0

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.

The Dark Knight
  • 5,455
  • 11
  • 54
  • 95

2 Answers2

0

This gives you the service name:

@Override
public boolean handleMessage(SOAPMessageContext pContext) {
    QName servicio = (QName) pContext.get(MessageContext.WSDL_SERVICE);
    return servicio.getLocalPart();
}

And this gives you the operation name:

@Override
public boolean handleMessage(SOAPMessageContext pContext) {
    QName servicio = (QName) pContext.get(MessageContext.WSDL_OPERATION);
    return servicio.getLocalPart();
}
Sergio Gabari
  • 663
  • 6
  • 12
-1

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.

The Dark Knight
  • 5,455
  • 11
  • 54
  • 95
  • I got this info from this url : http://docs.oracle.com/cd/E13226_01/workshop/docs81/doc/en/core/index.html . There are a lot of other things also there. Interested RPC aspirants can learn a lot of things from here . – The Dark Knight Jan 02 '13 at 12:53