Search in sources :

Example 1 with Fault

use of org.xmlsoap.schemas.soap.envelope.Fault in project camel by apache.

the class Soap11DataFormatAdapter method createFaultFromException.

/**
     * Creates a SOAP fault from the exception and populates the message as well
     * as the detail. The detail object is read from the method getFaultInfo of
     * the throwable if present
     * 
     * @param exception the cause exception
     * @return SOAP fault from given Throwable
     */
@SuppressWarnings("unchecked")
private JAXBElement<Fault> createFaultFromException(final Throwable exception) {
    WebFault webFault = exception.getClass().getAnnotation(WebFault.class);
    if (webFault == null || webFault.targetNamespace() == null) {
        throw new RuntimeException("The exception " + exception.getClass().getName() + " needs to have an WebFault annotation with name and targetNamespace", exception);
    }
    QName name = new QName(webFault.targetNamespace(), webFault.name());
    Object faultObject;
    try {
        Method method = exception.getClass().getMethod("getFaultInfo");
        faultObject = method.invoke(exception);
    } catch (Exception e) {
        throw new RuntimeCamelException("Exception while trying to get fault details", e);
    }
    Fault fault = new Fault();
    fault.setFaultcode(FAULT_CODE_SERVER);
    fault.setFaultstring(exception.getMessage());
    Detail detailEl = new ObjectFactory().createDetail();
    @SuppressWarnings("rawtypes") JAXBElement<?> faultDetailContent = new JAXBElement(name, faultObject.getClass(), faultObject);
    detailEl.getAny().add(faultDetailContent);
    fault.setDetail(detailEl);
    return new ObjectFactory().createFault(fault);
}
Also used : QName(javax.xml.namespace.QName) WebFault(javax.xml.ws.WebFault) Fault(org.xmlsoap.schemas.soap.envelope.Fault) Method(java.lang.reflect.Method) JAXBElement(javax.xml.bind.JAXBElement) RuntimeCamelException(org.apache.camel.RuntimeCamelException) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) WebFault(javax.xml.ws.WebFault) ObjectFactory(org.xmlsoap.schemas.soap.envelope.ObjectFactory) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Detail(org.xmlsoap.schemas.soap.envelope.Detail)

Example 2 with Fault

use of org.xmlsoap.schemas.soap.envelope.Fault in project camel by apache.

the class Soap11DataFormatAdapter 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.xmlsoap.schemas.soap.envelope.Header) RuntimeCamelException(org.apache.camel.RuntimeCamelException) WebFault(javax.xml.ws.WebFault) Fault(org.xmlsoap.schemas.soap.envelope.Fault) Envelope(org.xmlsoap.schemas.soap.envelope.Envelope) RuntimeCamelException(org.apache.camel.RuntimeCamelException) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Aggregations

IOException (java.io.IOException)2 SOAPException (javax.xml.soap.SOAPException)2 WebFault (javax.xml.ws.WebFault)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2 Fault (org.xmlsoap.schemas.soap.envelope.Fault)2 Method (java.lang.reflect.Method)1 JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1 Detail (org.xmlsoap.schemas.soap.envelope.Detail)1 Envelope (org.xmlsoap.schemas.soap.envelope.Envelope)1 Header (org.xmlsoap.schemas.soap.envelope.Header)1 ObjectFactory (org.xmlsoap.schemas.soap.envelope.ObjectFactory)1