Announcement Announcement Module
Collapse
No announcement yet.
How to unmarshal a SOAP Fault in a FaultMessageResolver? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to unmarshal a SOAP Fault in a FaultMessageResolver?

    Hi,

    I'm new to Spring-WS, and slowly getting my head wrapped around it. Right now, I'm writing a simple client to communicate with an existing WS. I'm using the WebServiceTemplate and the marshalSendAndReceive method. Everything works fine.

    However, when a SOAP fault occurs, the WST throws a SoapFaultClientException. I noticed that I can create my own FaultMessageResolver to check what is contained within the SOAP fault. However, when I try to unmarshal the WebServiceMessage in my FaultMessageResolver, I get the following error message:

    Code:
    JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are ....
    Obviously, my unmarshaller is not properly configured. Do I have to generate the JAXB fault model myself using xjc to then be able to unmarshal the error? I am somewhat amazed that this does not already exist.

    Is there a better way to extra my custom error information from within my soap:fault response? My error looks something like the following:

    Code:
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
       <soap:Body>
          <soap:Fault>
             <faultcode>soap:Server</faultcode>
             <faultstring>Blaze Data Error</faultstring>
             <detail>
                <ns14:serviceErrors xmlns="http://www.nb.com/ClientServices/LendingSimulation/CalculateProfitabilityRequest" xmlns:ns13="http://www.nb.com/fw/errorMgmt" xmlns:ns14="http://www.nb.com/ClientServices/LendingSimulation/V1" >
                   <ns13:faultstring>ServiceExecutionError</ns13:faultstring>
                   <ns13:serviceError>
                      <ns13:errorCode>C10F1013</ns13:errorCode>
                      <ns13:errorType>B</ns13:errorType>
                      <ns13:errorMessage>Unable to retreive additional data</ns13:errorMessage>
                      <ns13:fieldName>Message error received from PHClient :  [An unexpected error code was received : system=PH context=[empty]]</ns13:fieldName>
                      <ns13:systemId>Calculator</ns13:systemId>
                      <ns13:time>2012-06-19 14:45:10.151-0400</ns13:time>
                   </ns13:serviceError>
                </ns14:serviceErrors>
             </detail>
          </soap:Fault>
       </soap:Body>
    </soap:Envelope>
    Thanks!

    Eric

  • #2
    Same unmarshalling Exception

    Eric,

    I am also having the same issue, did you find a solution for this?

    Originally posted by benze View Post
    Hi,

    I'm new to Spring-WS, and slowly getting my head wrapped around it. Right now, I'm writing a simple client to communicate with an existing WS. I'm using the WebServiceTemplate and the marshalSendAndReceive method. Everything works fine.

    However, when a SOAP fault occurs, the WST throws a SoapFaultClientException. I noticed that I can create my own FaultMessageResolver to check what is contained within the SOAP fault. However, when I try to unmarshal the WebServiceMessage in my FaultMessageResolver, I get the following error message:

    Code:
    JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are ....
    Obviously, my unmarshaller is not properly configured. Do I have to generate the JAXB fault model myself using xjc to then be able to unmarshal the error? I am somewhat amazed that this does not already exist.

    Is there a better way to extra my custom error information from within my soap:fault response? My error looks something like the following:

    Code:
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
       <soap:Body>
          <soap:Fault>
             <faultcode>soap:Server</faultcode>
             <faultstring>Blaze Data Error</faultstring>
             <detail>
                <ns14:serviceErrors xmlns="http://www.nb.com/ClientServices/LendingSimulation/CalculateProfitabilityRequest" xmlns:ns13="http://www.nb.com/fw/errorMgmt" xmlns:ns14="http://www.nb.com/ClientServices/LendingSimulation/V1" >
                   <ns13:faultstring>ServiceExecutionError</ns13:faultstring>
                   <ns13:serviceError>
                      <ns13:errorCode>C10F1013</ns13:errorCode>
                      <ns13:errorType>B</ns13:errorType>
                      <ns13:errorMessage>Unable to retreive additional data</ns13:errorMessage>
                      <ns13:fieldName>Message error received from PHClient :  [An unexpected error code was received : system=PH context=[empty]]</ns13:fieldName>
                      <ns13:systemId>Calculator</ns13:systemId>
                      <ns13:time>2012-06-19 14:45:10.151-0400</ns13:time>
                   </ns13:serviceError>
                </ns14:serviceErrors>
             </detail>
          </soap:Fault>
       </soap:Body>
    </soap:Envelope>
    Thanks!

    Eric

    Comment


    • #3
      Did anyone solve this problem?
      Please help. I am having the same issue.
      Thanks

      Comment


      • #4
        There are two steps to resolve this issue.
        Step #1:

        webServiceTemplate.setCheckConnectionForFault(fals e);
        Indicates whether the connection should be checked for fault indicators (true), or whether we should rely on the message only (false). Most of the times SOAP API response will send fault as HTTP 200, so marshaller cannot recognize the Fault in the response so set it false explicitly.
        webServiceTemplate.setCheckConnectionForError(fals e);
        Indicates whether the connection should be checked for error indicators (true), or whether these should be ignored (false). The default is true. Set this also false to handle errors.

        The above step will resolve your issue but step #2 allows to handle the errors properly.

        Step 2:

        Use interceptor to handle request, response and errors.


        public class xyzInterceptor implements ClientInterceptor {

        @Override
        public boolean handleFault(MessageContext arg0)
        throws WebServiceClientException {
        return true;
        }
        //Override the other methods too but control comes to handle fault when there are faults from API.
        }

        Need to place the below code in the call where you are calling webserviceTemplate.marshallSendAndReceive(XXX,XXX) method.

        ClientInterceptor[] interceptors = new ClientInterceptor[1];
        interceptors[0] = xyzServiceInterceptor;
        webServiceTemplate.setInterceptors(interceptors);

        responseObject = (WO)webServiceTemplate.marshalSendAndReceive(endPo int,input);

        Let me know if you find any difficulty to implement this.

        Comment

        Working...
        X