Search in sources :

Example 11 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class StreamMessage method readEnvelope.

private static void readEnvelope(StreamMessage message) {
    if (message.envelopeReader == null)
        return;
    XMLStreamReader reader = message.envelopeReader;
    message.envelopeReader = null;
    SOAPVersion soapVersion = message.soapVersion;
    // Move to soap:Envelope and verify
    if (reader.getEventType() != XMLStreamConstants.START_ELEMENT)
        XMLStreamReaderUtil.nextElementContent(reader);
    XMLStreamReaderUtil.verifyReaderState(reader, XMLStreamConstants.START_ELEMENT);
    if (SOAP_ENVELOPE.equals(reader.getLocalName()) && !soapVersion.nsUri.equals(reader.getNamespaceURI())) {
        throw new VersionMismatchException(soapVersion, soapVersion.nsUri, reader.getNamespaceURI());
    }
    XMLStreamReaderUtil.verifyTag(reader, soapVersion.nsUri, SOAP_ENVELOPE);
    TagInfoset envelopeTag = new TagInfoset(reader);
    // Collect namespaces on soap:Envelope
    Map<String, String> namespaces = new HashMap<>();
    for (int i = 0; i < reader.getNamespaceCount(); i++) {
        namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
    }
    // Move to next element
    XMLStreamReaderUtil.nextElementContent(reader);
    XMLStreamReaderUtil.verifyReaderState(reader, javax.xml.stream.XMLStreamConstants.START_ELEMENT);
    HeaderList headers = null;
    TagInfoset headerTag = null;
    if (reader.getLocalName().equals(SOAP_HEADER) && reader.getNamespaceURI().equals(soapVersion.nsUri)) {
        headerTag = new TagInfoset(reader);
        // Collect namespaces on soap:Header
        for (int i = 0; i < reader.getNamespaceCount(); i++) {
            namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
        }
        // skip <soap:Header>
        XMLStreamReaderUtil.nextElementContent(reader);
        // If SOAP header blocks are present (i.e. not <soap:Header/>)
        if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
            headers = new HeaderList(soapVersion);
            try {
                // Cache SOAP header blocks
                StreamHeaderDecoder headerDecoder = SOAPVersion.SOAP_11.equals(soapVersion) ? SOAP11StreamHeaderDecoder : SOAP12StreamHeaderDecoder;
                cacheHeaders(reader, namespaces, headers, headerDecoder);
            } catch (XMLStreamException e) {
                // TODO need to throw more meaningful exception
                throw new WebServiceException(e);
            }
        }
        // Move to soap:Body
        XMLStreamReaderUtil.nextElementContent(reader);
    }
    // Verify that <soap:Body> is present
    XMLStreamReaderUtil.verifyTag(reader, soapVersion.nsUri, SOAP_BODY);
    TagInfoset bodyTag = new TagInfoset(reader);
    String bodyPrologue = XMLStreamReaderUtil.nextWhiteSpaceContent(reader);
    message.init(envelopeTag, headerTag, message.attachmentSet, headers, bodyPrologue, bodyTag, null, reader, soapVersion);
// when there's no payload,
// it's tempting to use EmptyMessageImpl, but it doesn't preserve the infoset
// of <envelope>,<header>, and <body>, so we need to stick to StreamMessage.
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) HashMap(java.util.HashMap) SOAPVersion(com.sun.xml.ws.api.SOAPVersion) TagInfoset(com.sun.xml.ws.encoding.TagInfoset) HeaderList(com.sun.xml.ws.api.message.HeaderList) VersionMismatchException(com.sun.xml.ws.protocol.soap.VersionMismatchException)

Example 12 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class AbstractSEIModelImpl method createJAXBContext.

private void createJAXBContext() {
    final List<TypeInfo> types = getAllTypeInfos();
    final List<Class> cls = new ArrayList<>(types.size() + additionalClasses.size());
    cls.addAll(additionalClasses);
    for (TypeInfo type : types) {
        cls.add((Class) type.type);
    }
    try {
        // jaxbContext = JAXBRIContext.newInstance(cls, types, targetNamespace, false);
        // Need to avoid doPriv block once JAXB is fixed. Afterwards, use the above
        bindingContext = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {

            @Override
            public BindingContext run() throws Exception {
                if (LOGGER.isLoggable(Level.FINEST)) {
                    LOGGER.log(Level.FINEST, "Creating JAXBContext with classes={0} and types={1}", new Object[] { cls, types });
                }
                UsesJAXBContextFeature f = features.get(UsesJAXBContextFeature.class);
                com.oracle.webservices.api.databinding.DatabindingModeFeature dmf = features.get(com.oracle.webservices.api.databinding.DatabindingModeFeature.class);
                JAXBContextFactory factory = f != null ? f.getFactory() : null;
                if (factory == null)
                    factory = JAXBContextFactory.DEFAULT;
                // return factory.createJAXBContext(AbstractSEIModelImpl.this,cls,types);
                databindingInfo.properties().put(JAXBContextFactory.class.getName(), factory);
                if (dmf != null) {
                    if (LOGGER.isLoggable(Level.FINE))
                        LOGGER.log(Level.FINE, "DatabindingModeFeature in SEI specifies mode: {0}", dmf.getMode());
                    databindingInfo.setDatabindingMode(dmf.getMode());
                }
                if (f != null)
                    databindingInfo.setDatabindingMode(BindingContextFactory.DefaultDatabindingMode);
                databindingInfo.setClassLoader(classLoader);
                databindingInfo.contentClasses().addAll(cls);
                databindingInfo.typeInfos().addAll(types);
                databindingInfo.properties().put("c14nSupport", Boolean.FALSE);
                databindingInfo.setDefaultNamespace(AbstractSEIModelImpl.this.getDefaultSchemaNamespace());
                BindingContext bc = BindingContextFactory.create(databindingInfo);
                if (LOGGER.isLoggable(Level.FINE))
                    LOGGER.log(Level.FINE, "Created binding context: {0}", bc.getClass().getName());
                // System.out.println("---------------------- databinding " + bc);
                return bc;
            }
        });
        // createBridgeMap(types);
        createBondMap(types);
    } catch (PrivilegedActionException e) {
        throw new WebServiceException(ModelerMessages.UNABLE_TO_CREATE_JAXB_CONTEXT(), e);
    }
    knownNamespaceURIs = new ArrayList<>();
    for (String namespace : bindingContext.getKnownNamespaceURIs()) {
        if (namespace.length() > 0) {
            if (!namespace.equals(SOAPNamespaceConstants.XSD) && !namespace.equals(SOAPNamespaceConstants.XMLNS))
                knownNamespaceURIs.add(namespace);
        }
    }
    marshallers = new Pool.Marshaller(jaxbContext);
// return getJAXBContext();
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) PrivilegedActionException(java.security.PrivilegedActionException) ArrayList(java.util.ArrayList) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) BindingContext(com.sun.xml.ws.spi.db.BindingContext) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) UsesJAXBContextFeature(com.sun.xml.ws.developer.UsesJAXBContextFeature) JAXBContextFactory(com.sun.xml.ws.developer.JAXBContextFactory) Pool(com.sun.xml.ws.util.Pool)

Example 13 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class PolicyUtil method getPortScopedFeatures.

/**
 * Returns the list of features that correspond to the policies in the policy
 * map for a give port
 *
 * @param policyMap The service policies
 * @param serviceName The service name
 * @param portName The service port name
 * @return List of features for the given port corresponding to the policies in the map
 */
public static Collection<WebServiceFeature> getPortScopedFeatures(PolicyMap policyMap, QName serviceName, QName portName) {
    LOGGER.entering(policyMap, serviceName, portName);
    Collection<WebServiceFeature> features = new ArrayList<>();
    try {
        final PolicyMapKey key = PolicyMap.createWsdlEndpointScopeKey(serviceName, portName);
        for (PolicyFeatureConfigurator configurator : CONFIGURATORS) {
            Collection<WebServiceFeature> additionalFeatures = configurator.getFeatures(key, policyMap);
            if (additionalFeatures != null) {
                features.addAll(additionalFeatures);
            }
        }
    } catch (PolicyException e) {
        throw new WebServiceException(e);
    }
    LOGGER.exiting(features);
    return features;
}
Also used : PolicyFeatureConfigurator(com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfigurator) WebServiceException(jakarta.xml.ws.WebServiceException) PolicyMapKey(com.sun.xml.ws.policy.PolicyMapKey) PolicyException(com.sun.xml.ws.policy.PolicyException) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) ArrayList(java.util.ArrayList)

Example 14 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class PolicyWSDLGeneratorExtension method writePolicyOrReferenceIt.

/**
 * Adds a PolicyReference element that points to the policy of the element,
 * if the policy does not have any id or name. Writes policy inside the element otherwise.
 *
 * @param subject
 *      PolicySubject to be referenced or marshalled
 * @param writer
 *      A TXW on to which we shall add the PolicyReference
 */
private void writePolicyOrReferenceIt(final PolicySubject subject, final TypedXmlWriter writer) {
    final Policy policy;
    try {
        policy = subject.getEffectivePolicy(merger);
    } catch (PolicyException e) {
        throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1011_FAILED_TO_RETRIEVE_EFFECTIVE_POLICY_FOR_SUBJECT(subject.toString()), e));
    }
    if (policy != null) {
        if (null == policy.getIdOrName()) {
            final PolicyModelGenerator generator = ModelGenerator.getGenerator();
            try {
                final PolicySourceModel policyInfoset = generator.translate(policy);
                marshaller.marshal(policyInfoset, writer);
            } catch (PolicyException pe) {
                throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1002_UNABLE_TO_MARSHALL_POLICY_OR_POLICY_REFERENCE(), pe));
            }
        } else {
            final TypedXmlWriter policyReference = writer._element(policy.getNamespaceVersion().asQName(XmlToken.PolicyReference), TypedXmlWriter.class);
            policyReference._attribute(XmlToken.Uri.toString(), '#' + policy.getIdOrName());
        }
    }
}
Also used : Policy(com.sun.xml.ws.policy.Policy) PolicySourceModel(com.sun.xml.ws.policy.sourcemodel.PolicySourceModel) WebServiceException(jakarta.xml.ws.WebServiceException) PolicyException(com.sun.xml.ws.policy.PolicyException) PolicyModelGenerator(com.sun.xml.ws.policy.sourcemodel.PolicyModelGenerator) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter)

Example 15 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class PolicyWSDLGeneratorExtension method start.

@Override
public void start(final WSDLGenExtnContext context) {
    LOGGER.entering();
    try {
        this.seiModel = context.getModel();
        final PolicyMapConfigurator[] policyMapConfigurators = loadConfigurators();
        final PolicyMapExtender[] extenders = new PolicyMapExtender[policyMapConfigurators.length];
        for (int i = 0; i < policyMapConfigurators.length; i++) {
            extenders[i] = PolicyMapExtender.createPolicyMapExtender();
        }
        // Read policy config file
        policyMap = PolicyResolverFactory.create().resolve(new PolicyResolver.ServerContext(policyMap, context.getContainer(), context.getEndpointClass(), false, extenders));
        if (policyMap == null) {
            LOGGER.fine(PolicyMessages.WSP_1019_CREATE_EMPTY_POLICY_MAP());
            policyMap = PolicyMap.createPolicyMap(Arrays.asList(extenders));
        }
        final WSBinding binding = context.getBinding();
        try {
            final Collection<PolicySubject> policySubjects = new LinkedList<>();
            for (int i = 0; i < policyMapConfigurators.length; i++) {
                policySubjects.addAll(policyMapConfigurators[i].update(policyMap, seiModel, binding));
                extenders[i].disconnect();
            }
            PolicyMapUtil.insertPolicies(policyMap, policySubjects, this.seiModel.getServiceQName(), this.seiModel.getPortName());
        } catch (PolicyException e) {
            throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1017_MAP_UPDATE_FAILED(), e));
        }
        final TypedXmlWriter root = context.getRoot();
        root._namespace(NamespaceVersion.v1_2.toString(), NamespaceVersion.v1_2.getDefaultNamespacePrefix());
        root._namespace(NamespaceVersion.v1_5.toString(), NamespaceVersion.v1_5.getDefaultNamespacePrefix());
        root._namespace(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_NAMESPACE_PREFIX);
    } finally {
        LOGGER.exiting();
    }
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) PolicySubject(com.sun.xml.ws.policy.PolicySubject) WebServiceException(jakarta.xml.ws.WebServiceException) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter) PolicyMapExtender(com.sun.xml.ws.policy.PolicyMapExtender) LinkedList(java.util.LinkedList) PolicyException(com.sun.xml.ws.policy.PolicyException) PolicyMapConfigurator(com.sun.xml.ws.policy.jaxws.spi.PolicyMapConfigurator) MtomPolicyMapConfigurator(com.sun.xml.ws.encoding.policy.MtomPolicyMapConfigurator) AddressingPolicyMapConfigurator(com.sun.xml.ws.addressing.policy.AddressingPolicyMapConfigurator)

Aggregations

WebServiceException (jakarta.xml.ws.WebServiceException)386 QName (javax.xml.namespace.QName)49 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)36 SOAPException (jakarta.xml.soap.SOAPException)33 JAXBException (jakarta.xml.bind.JAXBException)30 Node (org.w3c.dom.Node)28 JAXBContext (jakarta.xml.bind.JAXBContext)27 IOException (java.io.IOException)26 SOAPMessage (jakarta.xml.soap.SOAPMessage)25 XMLStreamException (javax.xml.stream.XMLStreamException)25 Source (javax.xml.transform.Source)23 ProtocolException (jakarta.xml.ws.ProtocolException)20 Dispatch (jakarta.xml.ws.Dispatch)19 MalformedURLException (java.net.MalformedURLException)19 MessageContext (jakarta.xml.ws.handler.MessageContext)17 Map (java.util.Map)17 URL (java.net.URL)16 StreamSource (javax.xml.transform.stream.StreamSource)16 HandlerTracker (fromwsdl.handler.common.HandlerTracker)14 HandlerTracker (handler.handler_processing.common.HandlerTracker)14