Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-3442

Fault should not swallow the cause exception message

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 2.4, 2.3.4
    • Soap Binding
    • None

    Description

      When sending an invalid SOAP message specifically with an incorrect end tag:

      snip...
        <soapenv:Body>
            <cus:lookupCustomer>
               <customerId>1</customerId>
               <customerId2>1</customerId2>
            <cus:lookupCustomer>   <------- no slash.
         </soapenv:Body>
      end snip..
      

      The wrong SOAP fault is thrown when using the WSS4JInInterceptor:

      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
         <soap:Body>
            <soap:Fault>
               <faultcode>soap:Client</faultcode>
               <faultstring>Problems creating SAAJ object model</faultstring>
            </soap:Fault>
         </soap:Body>
      </soap:Envelope>
      

      When the WSS4JInInterceptor is removed the following exception is thrown:

      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
         <soap:Body>
            <soap:Fault>
               <faultcode>soap:Client</faultcode>
               <faultstring>Unmarshalling Error: cvc-complex-type.2.4.d: Invalid content was found starting with element 'cus:lookupCustomer'. No child element is expected at this point.</faultstring>
            </soap:Fault>
         </soap:Body>
      </soap:Envelope>
      

      If you enable the WSS4JInInterceptor, CXF will use SAAJInInterceptor to create a SOAP message for using.
      That could explain that you got the "Problems creating SAAJ object model" message.
      I just checked the code of SAAJInInterceptor, it just wrap the real cause of exception message like this

      } catch (SOAPException soape) {
                  throw new SoapFault(new org.apache.cxf.common.i18n.Message(
                          "SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), soape,
                          message.getVersion().getSender());
              } catch (XMLStreamException e) {
                  throw new SoapFault(new org.apache.cxf.common.i18n.Message(
                          "SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), e, message
                          .getVersion().getSender());
              }
      

      After digging the code more, I found the SoapFault and it's parent Fault doesn't take the cause exception into consideration.
      When the Fault reason send to the client, it just a Fault message without the cause. It's difficult for the user to trace the real cause of the exception. My suggestion is change the Fault class to add the cause exception message into the Fault message like this

          public Fault(Message message, Throwable throwable) {
              super(message, throwable);
              this.message = message.toString;
              if (throwable != null) {
                 this.message += "Caused by: " + throwable.getMessage();
              }
              code = FAULT_CODE_SERVER;
          }
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            njiang Willem Jiang
            njiang Willem Jiang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment