Search code examples
javahandlerjax-rpc

How to get the WS operation name in Handler using JAX RPC?


I have written a handler to construct my SOAP headers, but i am going to use it for different operations. Now depending on operation, some of the header names change. So i need to know which operation is getting called, based on which i will change my header name.

There in lies my problem . I am using JAX RPC, which is the requirement of the current project that i am working on. How do i get to know the operation name in my handler ? Kindly help.


Solution

  • I did some research on this. There is not a lot of material available on the internet for this. However i got lucky. Those who are facing similar problems like me can use this method :

        protected String getMethodName(MessageContext mc)
        {
        String operationName = null;
    
        try
        {
        SOAPMessageContext messageContext = (SOAPMessageContext) mc;
    
        // assume the operation name is the first element
        // after SOAP:Body element
        Iterator i = messageContext.
        getMessage().getSOAPPart().getEnvelope().getBody().getChildElements();
        while ( i.hasNext() )
        {
        Object obj = i.next();
        if(obj instanceof SOAPElement)
        {
        SOAPElement e = (SOAPElement) obj;
        operationName = e.getElementName().getLocalName();
        break;
        }
        }
        }
        catch(Exception e)
        {
        e.printStackTrace();
        }
        return operationName;
        }
    

    This method takes the message context object and iterates through the whole soap envelope to get the operation name.

    Hope this helps some of the folks.