Class SOAPFaultMessage


  • public class SOAPFaultMessage
    extends java.lang.Object

    Utility class to create a SOAPFault

    Due to security concerns the server should never reveal exception internals to the client, rather respond with a general message. Generally, the RequestLifeCycleFilter does so in case a request failed to process due to a thrown exception.

    However, sometimes you want to respond with a business-exception to the client (yet yielding a positive http response status) so it knows what went wrong and why. In such a case you can handle a business exception in your servlet implementation and respond with a SOAPFault using this class.

    • Constructor Summary

      Constructors 
      Constructor Description
      SOAPFaultMessage​(org.w3c.dom.Document requestDocument, java.lang.String requestURL, java.lang.Throwable faultException, java.lang.String message)
      SOAPFaultMessage
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.xml.soap.SOAPMessage getMessage()  
      static boolean writeSOAPFaultToHTTPResponse​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Exception faultException, java.lang.String faultMessage)
      Convenience method to write a SOAP message response.
      static boolean writeSOAPFaultToHTTPResponse​(javax.servlet.http.HttpServletResponse resp, org.w3c.dom.Document requestDocument, java.lang.String requestURL, java.lang.Throwable faultException, java.lang.String faultMessage)
      Convenience method to write a SOAP massage response.
      void writeTo​(java.io.OutputStream out)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SOAPFaultMessage

        public SOAPFaultMessage​(org.w3c.dom.Document requestDocument,
                                java.lang.String requestURL,
                                java.lang.Throwable faultException,
                                java.lang.String message)
                         throws javax.xml.soap.SOAPException
        SOAPFaultMessage
        Parameters:
        requestDocument - - optional request document to serialize into SOAPFault
        requestURL - - optional URL to appear in SOAPFault
        faultException - - optional exception caused this fault
        message - - optional literal message provided as FaultReason in SOAPFault
        Throws:
        javax.xml.soap.SOAPException
    • Method Detail

      • writeSOAPFaultToHTTPResponse

        public static boolean writeSOAPFaultToHTTPResponse​(javax.servlet.http.HttpServletResponse resp,
                                                           org.w3c.dom.Document requestDocument,
                                                           java.lang.String requestURL,
                                                           java.lang.Throwable faultException,
                                                           java.lang.String faultMessage)
        Convenience method to write a SOAP massage response. The responseOutputStream must not be opened yet. It captures all Exceptions happening during that and writes them to log. The http response status is NOT set by this method. The response content-type is set to 'text/xml'.
        Parameters:
        resp -
        requestDocument - - optional request document to serialize into SOAPFault
        requestURL - - optional URL to appear in SOAPFault
        faultException - - optional exception caused this fault, must not reveal security relevant facts
        faultMessage - - optional literal message provided as FaultReason in SOAPFault must not reveal security relevant facts
        Returns:
        true if exception was thrown, false if a SOAPFault could not be produced an an error log was created instead
      • writeSOAPFaultToHTTPResponse

        public static boolean writeSOAPFaultToHTTPResponse​(javax.servlet.http.HttpServletRequest request,
                                                           javax.servlet.http.HttpServletResponse response,
                                                           java.lang.Exception faultException,
                                                           java.lang.String faultMessage)
        Convenience method to write a SOAP message response. The responseOutputStream must not be opened yet. It captures all Exceptions happening during that and writes them to log. The http response status is NOT set by this method. The response content-type is set to 'text/xml'.
        Parameters:
        request -
        response -
        faultException - - optional exception caused this fault, must not reveal security relevant facts
        faultMessage - - must not reveal security relevant facts
        Returns:
        true if exception was thrown, false if a SOAPFault could not be produced an an error log was created instead
      • getMessage

        public javax.xml.soap.SOAPMessage getMessage()
        Returns:
        the message
      • writeTo

        public void writeTo​(java.io.OutputStream out)
                     throws javax.xml.soap.SOAPException,
                            java.io.IOException
        Parameters:
        out -
        Throws:
        javax.xml.soap.SOAPException
        java.io.IOException
        See Also:
        SOAPMessage.writeTo(java.io.OutputStream)