Search in sources :

Example 1 with Envelope

use of org.w3.x2003.x05.soapEnvelope.Envelope in project camel by apache.

the class Soap12DataFormatAdapter method doUnmarshal.

@Override
public Object doUnmarshal(Exchange exchange, InputStream stream, Object rootObject) throws IOException {
    if (rootObject.getClass() != Envelope.class) {
        throw new RuntimeCamelException("Expected Soap Envelope but got " + rootObject.getClass());
    }
    Envelope envelope = (Envelope) rootObject;
    Header header = envelope.getHeader();
    if (header != null) {
        List<Object> returnHeaders;
        List<Object> anyHeaderElements = envelope.getHeader().getAny();
        if (null != anyHeaderElements && !(getDataFormat().isIgnoreUnmarshalledHeaders())) {
            if (getDataFormat().isIgnoreJAXBElement()) {
                returnHeaders = new ArrayList<Object>();
                for (Object headerEl : anyHeaderElements) {
                    returnHeaders.add(JAXBIntrospector.getValue(headerEl));
                }
            } else {
                returnHeaders = anyHeaderElements;
            }
            exchange.getOut().setHeader(SoapJaxbDataFormat.SOAP_UNMARSHALLED_HEADER_LIST, returnHeaders);
        }
    }
    List<Object> anyElement = envelope.getBody().getAny();
    if (anyElement.size() == 0) {
        // No parameter so return null
        return null;
    }
    Object payloadEl = anyElement.get(0);
    Object payload = JAXBIntrospector.getValue(payloadEl);
    if (payload instanceof Fault) {
        Exception exception = createExceptionFromFault((Fault) payload);
        exchange.setException(exception);
        return null;
    } else {
        return getDataFormat().isIgnoreJAXBElement() ? payload : payloadEl;
    }
}
Also used : Header(org.w3._2003._05.soap_envelope.Header) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Fault(org.w3._2003._05.soap_envelope.Fault) WebFault(javax.xml.ws.WebFault) Envelope(org.w3._2003._05.soap_envelope.Envelope) SOAPException(javax.xml.soap.SOAPException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Example 2 with Envelope

use of org.w3.x2003.x05.soapEnvelope.Envelope in project camel by apache.

the class Soap12DataFormatAdapter method doMarshal.

@Override
public Object doMarshal(Exchange exchange, Object inputObject, OutputStream stream, String soapAction) throws IOException {
    Body body = objectFactory.createBody();
    Header header = objectFactory.createHeader();
    Throwable exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
    if (exception == null) {
        exception = exchange.getIn().getHeader(Exchange.EXCEPTION_CAUGHT, Throwable.class);
    }
    final List<Object> bodyContent;
    List<Object> headerContent = new ArrayList<Object>();
    if (exception != null) {
        bodyContent = new ArrayList<Object>();
        bodyContent.add(createFaultFromException(exception));
    } else {
        if (!dataFormat.isIgnoreUnmarshalledHeaders()) {
            List<Object> inboundSoapHeaders = (List<Object>) exchange.getIn().getHeader(SoapJaxbDataFormat.SOAP_UNMARSHALLED_HEADER_LIST);
            if (null != inboundSoapHeaders) {
                headerContent.addAll(inboundSoapHeaders);
            }
        }
        bodyContent = getDataFormat().createContentFromObject(inputObject, soapAction, headerContent);
    }
    for (Object elem : bodyContent) {
        body.getAny().add(elem);
    }
    for (Object elem : headerContent) {
        header.getAny().add(elem);
    }
    Envelope envelope = new Envelope();
    if (headerContent.size() > 0) {
        envelope.setHeader(header);
    }
    envelope.setBody(body);
    JAXBElement<Envelope> envelopeEl = objectFactory.createEnvelope(envelope);
    return envelopeEl;
}
Also used : Header(org.w3._2003._05.soap_envelope.Header) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Envelope(org.w3._2003._05.soap_envelope.Envelope) Body(org.w3._2003._05.soap_envelope.Body)

Example 3 with Envelope

use of org.w3.x2003.x05.soapEnvelope.Envelope in project arctic-sea by 52North.

the class Soap12Decoder method createEnvelope.

/**
 * Parses SOAP 1.2 Envelope to a SOS internal SOAP request.
 *
 * @param doc
 *            request as xml representation
 *
 * @return SOS internal SOAP request
 *
 * @throws DecodingException
 *             if an error occurs.
 */
@Override
protected SoapRequest createEnvelope(XmlObject doc) throws DecodingException {
    SoapRequest soapRequest = new SoapRequest(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, SOAPConstants.SOAP_1_2_PROTOCOL);
    String soapAction = "";
    try {
        SOAPMessage message;
        try {
            message = SoapHelper.getSoapMessageForProtocol(SOAPConstants.SOAP_1_2_PROTOCOL, doc.newInputStream());
        } catch (IOException | SOAPException ioe) {
            throw new NoApplicableCodeException().causedBy(ioe).withMessage("Error while parsing SOAPMessage from request string!");
        }
        try {
            if (message.getSOAPHeader() != null) {
                soapRequest.setSoapHeader(getSoapHeader(message.getSOAPHeader()));
            }
            soapRequest.setAction(checkSoapAction(soapAction, soapRequest.getSoapHeader()));
            soapRequest.setSoapBodyContent(getBodyContent((EnvelopeDocument) doc));
        } catch (SOAPException soape) {
            throw new NoApplicableCodeException().causedBy(soape).withMessage("Error while parsing SOAPMessage!");
        }
    } catch (OwsExceptionReport owse) {
        throw new DecodingException(owse);
    }
    return soapRequest;
}
Also used : SoapRequest(org.n52.shetland.w3c.soap.SoapRequest) EnvelopeDocument(org.w3.x2003.x05.soapEnvelope.EnvelopeDocument) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) SOAPException(javax.xml.soap.SOAPException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) IOException(java.io.IOException) SOAPMessage(javax.xml.soap.SOAPMessage) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 4 with Envelope

use of org.w3.x2003.x05.soapEnvelope.Envelope in project arctic-sea by 52North.

the class Soap12Encoder method createSOAP12Envelope.

private XmlObject createSOAP12Envelope(SoapResponse response, EncodingContext additionalValues) throws EncodingException {
    String action = null;
    final EnvelopeDocument envelopeDoc = EnvelopeDocument.Factory.newInstance();
    final Envelope envelope = envelopeDoc.addNewEnvelope();
    final Body body = envelope.addNewBody();
    if (response.getSoapFault() != null) {
        body.set(createSOAP12Fault(response.getSoapFault()));
    } else {
        if (response.getException() != null) {
            if (!response.getException().getExceptions().isEmpty()) {
                final CodedException firstException = response.getException().getExceptions().get(0);
                action = getExceptionActionURI(firstException.getCode());
            }
            body.set(createSOAP12FaultFromExceptionResponse(response.getException()));
            N52XmlHelper.setSchemaLocationsToDocument(envelopeDoc, Sets.newHashSet(N52XmlHelper.getSchemaLocationForSOAP12(), N52XmlHelper.getSchemaLocationForOWS110Exception()));
        } else {
            action = response.getSoapAction();
            final XmlObject bodyContent = getBodyContent(response);
            String value = null;
            Node nodeToRemove = null;
            final NamedNodeMap attributeMap = bodyContent.getDomNode().getFirstChild().getAttributes();
            for (int i = 0; i < attributeMap.getLength(); i++) {
                final Node node = attributeMap.item(i);
                if (node.getLocalName().equals(W3CConstants.AN_SCHEMA_LOCATION)) {
                    value = node.getNodeValue();
                    nodeToRemove = node;
                }
            }
            if (nodeToRemove != null) {
                attributeMap.removeNamedItem(nodeToRemove.getNodeName());
            }
            final Set<SchemaLocation> schemaLocations = Sets.newHashSet();
            schemaLocations.add(N52XmlHelper.getSchemaLocationForSOAP12());
            if (value != null && !value.isEmpty()) {
                String[] split = value.split(" ");
                for (int i = 0; i < split.length; i += 2) {
                    schemaLocations.add(new SchemaLocation(split[i], split[i + 1]));
                }
            }
            N52XmlHelper.setSchemaLocationsToDocument(envelopeDoc, schemaLocations);
            body.set(bodyContent);
        }
    }
    if (response.getHeader() != null) {
        createSOAP12Header(envelope, response.getHeader(), action);
    } else {
        envelope.addNewHeader();
    }
    // checkAndValidateSoapMessage(envelopeDoc);
    return envelopeDoc;
}
Also used : SchemaLocation(org.n52.shetland.w3c.SchemaLocation) EnvelopeDocument(org.w3.x2003.x05.soapEnvelope.EnvelopeDocument) NamedNodeMap(org.w3c.dom.NamedNodeMap) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) Node(org.w3c.dom.Node) XmlObject(org.apache.xmlbeans.XmlObject) XmlString(org.apache.xmlbeans.XmlString) Envelope(org.w3.x2003.x05.soapEnvelope.Envelope) Body(org.w3.x2003.x05.soapEnvelope.Body)

Aggregations

IOException (java.io.IOException)2 SOAPException (javax.xml.soap.SOAPException)2 Envelope (org.w3._2003._05.soap_envelope.Envelope)2 Header (org.w3._2003._05.soap_envelope.Header)2 EnvelopeDocument (org.w3.x2003.x05.soapEnvelope.EnvelopeDocument)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 WebFault (javax.xml.ws.WebFault)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 XmlObject (org.apache.xmlbeans.XmlObject)1 XmlString (org.apache.xmlbeans.XmlString)1 CodedException (org.n52.shetland.ogc.ows.exception.CodedException)1 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)1 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)1 SchemaLocation (org.n52.shetland.w3c.SchemaLocation)1 SoapRequest (org.n52.shetland.w3c.soap.SoapRequest)1 DecodingException (org.n52.svalbard.decode.exception.DecodingException)1 Body (org.w3._2003._05.soap_envelope.Body)1