Search in sources :

Example 1 with Envelope

use of org.w3._2003._05.soap_envelope.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._2003._05.soap_envelope.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)

Aggregations

Envelope (org.w3._2003._05.soap_envelope.Envelope)2 Header (org.w3._2003._05.soap_envelope.Header)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SOAPException (javax.xml.soap.SOAPException)1 WebFault (javax.xml.ws.WebFault)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 Body (org.w3._2003._05.soap_envelope.Body)1 Fault (org.w3._2003._05.soap_envelope.Fault)1