Announcement Announcement Module
Collapse
No announcement yet.
FaultResolver not get called if Response schema validation fails in spring-ws-2.1.0 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FaultResolver not get called if Response schema validation fails in spring-ws-2.1.0

    Hi

    Recently We have migrated our spring web service libraries from 2.0 to 2.1. After migratation, Our application unable to generate soap fault if response schema validation fails. Here is how we have implemented this:

    1. We have PayloadValidatingInterceptorWithException class which extends PayloadValidatingInterceptor. Here we have overriden handleRequestValidationErrors and handleResponseValidationErrors methods and we are throwing our own runtime exception from both methods - Always.

    2. We have ServiceFaultExceptionResolver class which extends SimpleSoapExceptionResolver and have overriden customizeFault where we create fault through marshaller object

    Now in 2.0 Version, dispatch method of MessageDispatcher class has one single try block for all the code - i.e. both interceptor.handleRequst and interceptor.handleResponse are in same try and if any exception thrown from these methods then processEndpointException method will get called from catch block and this processEndpointException method is resposible for calling all the SimpleSoapExceptionResolver and generate the fault. - So all is well and our application is used to generate fault for both request and response schema validation.

    But in 2.1 Version, dispatch method of MessageDispatcher class has two try block - one for interceptor.handleRequst and another for interceptor.handleResponse. Now the catch block for request one calls processEndpointException but catch block for response one does not call - it only calls triggerAfterCompletion which is meant for resource cleanup. Now that is why presently our application generates soap fault if request schema fails but it does not generate soap fault if response schema validation fails - I mean control does not go to customizeFault method of ServiceFaultExceptionResolver.

    So I have following questions:

    1. May I know why do we have different try in v 2.1 for request and response or why the second catch does not call processEndpointException ?

    2. How can I resolve my problem with 2.1 ? That is I need to invoke customizeFault method of ServiceFaultExceptionResolver for response schema validation failure scenario also.

    Thanks
    Subhajit
    Last edited by Subhajit Raha; Jan 25th, 2013, 02:44 PM.

  • #2
    Hello!


    1. May I know why do we have different try in v 2.1 for request and response or why the second catch does not call processEndpointException ?

    2. How can I resolve my problem with 2.1 ? That is I need to invoke customizeFault method of ServiceFaultExceptionResolver for response schema validation failure scenario also.
    Sorry for the delay...

    ad1) I think Spring-Ws doesn't seem to think that response interceptors should produce fault... Look at "org.springframework.ws.server.endpoint.intercepto r.AbstractValidatingInterceptor.handleResponseVali dationErrors(MessageContext, SAXParseException[])" - it doesn't throw an exception - it just returns false.

    ad2) Please see https://github.com/grgrzybek/spring-...pring-ws-85762 - I've prepared an example for you. What I did:
    • PayloadValidatingInterceptorWithException has ServiceFaultExceptionResolver injected
    • PayloadValidatingInterceptorWithException.handleRe sponseValidationErrors() instead of throwing RuntimeException uses it to invoke resolveException(MessageContext, Object, Exception) on injected ServiceFaultExceptionResolver which fetches soapFault from MessageContext and customizes it

    the result XML, when response validation occurs is:
    Code:
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
       <SOAP-ENV:Header/>
       <SOAP-ENV:Body>
          <SOAP-ENV:Fault>
             <faultcode>SOAP-ENV:Server</faultcode>
             <faultstring xml:lang="en">Unable to process the request; please contact support using Reference Id: test-id</faultstring>
             <detail>
                <ns2:my-fault xmlns:ns2="urn:test">
                   <ns2:fault-info>Unable to process the request; please contact support using Reference Id: test-id</ns2:fault-info>
                   <ns2:code>1000</ns2:code>
                   <ns2:date>2013-02-08T13:07:54.596+01:00</ns2:date>
                   <ns2:faultId>test-id</ns2:faultId>
                </ns2:my-fault>
             </detail>
          </SOAP-ENV:Fault>
       </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    best regards
    Grzegorz Grzybek

    Comment


    • #3
      Hi Grzegorz

      Thanks a lot. It works fine.

      Regards
      Subhajit

      Comment


      • #4
        Isn't this a clear bug...?

        You can see from source code:
        https://src.springframework.org/svn/...terceptor.java
        https://src.springframework.org/svn/...terceptor.java

        that handleResponseValidationErrors() is not implemented whereas handleRequestValidationErrors() is, so even if you enable response validation, you get nothing but log messages indicating that something went wrong. If you add the method, things work like expected. All I had to do was to extend PayloadValidatingInterceptor and add this

        @Override
        protected boolean handleResponseValidationErrors(MessageContext messageContext, SAXParseException[] errors) {
        for (SAXParseException error : errors) {
        logger.warn("XML validation error on request: " + error.getMessage());
        }
        if (messageContext.getResponse() instanceof SoapMessage) {
        SoapMessage response = (SoapMessage) messageContext.getResponse();
        SoapBody body = response.getSoapBody();
        SoapFault fault = body.addClientOrSenderFault(getFaultStringOrReason (), getFaultStringOrReasonLocale());
        if (getAddValidationErrorDetail()) {
        SoapFaultDetail detail = fault.addFaultDetail();
        for (SAXParseException error : errors) {
        SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName( ));
        detailElement.addText(error.getMessage());
        }
        }
        }
        return false;
        }

        Comment


        • #5
          Ah, seems this is the bug about it: https://jira.springsource.org/browse/SWS-824

          Comment

          Working...
          X