Search code examples
javasoapweblogic

How can I associate and inbound and outbound soaphandler with each-other


http://docs.oracle.com/javaee/5/api/javax/xml/ws/handler/soap/SOAPHandler.html

How can I associate an inbound handleMessage(SOAPMessageContext) call with and outbound handleMessage(SOAPMessageContext).

I've tried a few things, Weblogic doesn't reuse the context object so reference checking doesn't work. I can't find any property that indicates the request distinctly and therefor I can't seem to create a link between the request and response.

Alternatively is there a better way to get the request and response on web-logic problematically and associated together such that they can be dumped to the database for future debugging purposes.


Solution

  • Okay, so this may not work on all implementations of JAX-WS but for weblogic this certainly does.

    What I've done

    public final boolean handleMessage(SOAPMessageContext context) {
        // Using `Object` type as we don't have any need to import servlet libraries into a JAX-WS library
        Object o = context.get(MessageContext.SERVLET_REQUEST);
        // o will hold a reference to the request 
        // if inbound.o == outbound.o the request objects are identical and therefor we can associate them.
        return true;
    }
    

    I don't see why this wouldn't work in other containers but please double check before using this method.