3

I have a SOAP handle class and I added a statement to throw a custom runtime exception (first throwing throw new IntrusionException, then catching it, then throwing MyRuntimeException).

According to http://docs.oracle.com/cd/E13222_01/wls/docs103/webserv_adv/handlers.html in the "Implementing the Handler.handleMessage() Method" section, if I throw a runtime exception in the handler, handleFault() should be called.

I put in breakpoints in my application, and that method isn't being called. Instead of a Soap Fault, the client gets the usual response from the WS Also, for some reason, the logging stopped working and in the debugging doesn't stop at the WS class breakpoints, but as soon as i take that throw exception statement out again, the logging works again.

public class GatewayRequestHandler implements javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> {

        // private static final Log LOG =
        // LogFactory.getLog(GatewayRequestHandler.class);
        private static final Logger LOG = ESAPI.getLogger(GatewayRequestHandler.class.getName());

        private static myEsapiValidator esapiValidator = (myEsapiValidator) ESAPI.validator();

        @Override
        public boolean handleMessage(SOAPMessageContext mc) {

                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                String outString = null;

                SOAPMessage soapMsg = mc.getMessage();
                try {
                        LOG.info(Logger.EVENT_UNSPECIFIED, "WSDL Operation: " + mc.get(MessageContext.WSDL_OPERATION));

                        soapMsg.writeTo(outStream);
                        outString = new String(outStream.toByteArray(), "UTF-8");

                        // validate inbound message

                        try {
                                outString = esapiValidator.getValidInput("ResponseDocument", outString, "my.XMLString",
                                        Integer.MAX_VALUE, true, true);
                                LOG.info(Logger.SECURITY_SUCCESS, "Successfully validated inbound message.");
                                throw new IntrusionException("Test canonicalization failure","test");
                        } catch (IntrusionException | ValidationException e) {
                                String errStr = "Error validating the inbound response message.";
                                LOG.error(Logger.SECURITY_FAILURE, errStr, e);
                                // throw new ComponentException(errStr, e);
                                throw new MyRuntimeException(errStr, e);
                        }

... @Override public boolean handleFault(SOAPMessageContext mc) {

user994165
  • 9,146
  • 30
  • 98
  • 165
  • Any chance you found a solution? I got the same issue. – olek Jan 06 '16 at 12:40
  • @Olek, I did not. You could try just catching the exception in the handleMessage and directly calling handleFault. I think what I did instead was to do a put() on the SOAPMessage with a key/value, look for it in the web service class, and handle it there. – user994165 Jan 07 '16 at 18:30

0 Answers0