Search in sources :

Example 1 with Faultcode

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

the class Soap12Encoder method createSOAP12FaultFromExceptionResponse.

// see
// http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ300
// for more details
private XmlObject createSOAP12FaultFromExceptionResponse(final OwsExceptionReport owsExceptionReport) throws EncodingException {
    final FaultDocument faultDoc = FaultDocument.Factory.newInstance();
    final Fault fault = faultDoc.addNewFault();
    final Faultcode code = fault.addNewCode();
    code.setValue(SOAPConstants.SOAP_SENDER_FAULT);
    // 19.2.3 SOAP 1.2 Fault Binding
    if (!owsExceptionReport.getExceptions().isEmpty()) {
        final CodedException firstException = owsExceptionReport.getExceptions().get(0);
        final Subcode subcode = code.addNewSubcode();
        QName qName;
        if (firstException.getCode() != null) {
            qName = OwsHelper.getQNameForLocalName(firstException.getCode().toString());
        } else {
            qName = OwsHelper.getQNameForLocalName(OwsExceptionCode.NoApplicableCode.name());
        }
        subcode.setValue(qName);
        final Reasontext addNewText = fault.addNewReason().addNewText();
        addNewText.setLang(Locale.ENGLISH.getLanguage());
        addNewText.setStringValue(SoapHelper.getSoapFaultReasonText(firstException.getCode()));
        fault.addNewDetail().set(encodeObjectToXml(OWSConstants.NS_OWS, firstException, EncodingContext.of(XmlBeansEncodingFlags.ENCODE_OWS_EXCEPTION_ONLY)));
    }
    return faultDoc;
}
Also used : Faultcode(org.w3.x2003.x05.soapEnvelope.Faultcode) Subcode(org.w3.x2003.x05.soapEnvelope.Subcode) FaultDocument(org.w3.x2003.x05.soapEnvelope.FaultDocument) Reasontext(org.w3.x2003.x05.soapEnvelope.Reasontext) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) QName(javax.xml.namespace.QName) SoapFault(org.n52.shetland.w3c.soap.SoapFault) Fault(org.w3.x2003.x05.soapEnvelope.Fault)

Example 2 with Faultcode

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

the class Soap12DataFormatAdapter 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();
    Faultcode code = new Faultcode();
    code.setValue(FAULT_CODE_SERVER);
    fault.setCode(code);
    Reasontext text = new Reasontext();
    text.setValue(exception.getMessage());
    text.setLang("en");
    fault.setReason(new Faultreason().withText(text));
    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 : Reasontext(org.w3._2003._05.soap_envelope.Reasontext) QName(javax.xml.namespace.QName) Fault(org.w3._2003._05.soap_envelope.Fault) WebFault(javax.xml.ws.WebFault) Method(java.lang.reflect.Method) JAXBElement(javax.xml.bind.JAXBElement) SOAPException(javax.xml.soap.SOAPException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) WebFault(javax.xml.ws.WebFault) Faultcode(org.w3._2003._05.soap_envelope.Faultcode) ObjectFactory(org.w3._2003._05.soap_envelope.ObjectFactory) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Faultreason(org.w3._2003._05.soap_envelope.Faultreason) Detail(org.w3._2003._05.soap_envelope.Detail)

Aggregations

QName (javax.xml.namespace.QName)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 JAXBElement (javax.xml.bind.JAXBElement)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 CodedException (org.n52.shetland.ogc.ows.exception.CodedException)1 SoapFault (org.n52.shetland.w3c.soap.SoapFault)1 Detail (org.w3._2003._05.soap_envelope.Detail)1 Fault (org.w3._2003._05.soap_envelope.Fault)1 Faultcode (org.w3._2003._05.soap_envelope.Faultcode)1 Faultreason (org.w3._2003._05.soap_envelope.Faultreason)1 ObjectFactory (org.w3._2003._05.soap_envelope.ObjectFactory)1 Reasontext (org.w3._2003._05.soap_envelope.Reasontext)1 Fault (org.w3.x2003.x05.soapEnvelope.Fault)1 FaultDocument (org.w3.x2003.x05.soapEnvelope.FaultDocument)1 Faultcode (org.w3.x2003.x05.soapEnvelope.Faultcode)1 Reasontext (org.w3.x2003.x05.soapEnvelope.Reasontext)1