I try to create a Web Service using the Provider interface.I need to
know in the invoke(...) method which WSDL Operation has been invoked but
I don't know the good way to do that.
I try to get the MessageContext.WSDL_OPERATION on the message context
but it is always null so I tried to get the "SoapAction" in the HTTP
headers but it is no more a mandatory header for the caller...
Somebody how I can get this information the right way?
Here is my provider class.
@ServiceMode(value = Service.Mode.PAYLOAD)
@WebServiceProvider()
public class MyProvider implements Provider<Source>
{
@Resource
WebServiceContext wsContext;
public Source invoke(Source source)
{
try
{
MessageContext msgContext = wsContext.getMessageContext();
String methodName = null;
QName operation =
(QName)msgContext.get(MessageContext.WSDL_OPERATION);
if (operation != null)
{
methodName = operation.getLocalPart();
}
else
{
Map headers =
(Map)msgContext.get(MessageContext.HTTP_REQUEST_HEADERS);
if (headers != null)
{
List soapActionList = (List)headers.get("Soapaction");
if (soapActionList != null && soapActionList.size()
!= 0)
{
methodName = (String)soapActionList.get(0);
}
}
}
if (methodName==null)
{
throw new RuntimeException("Can't retrieve operation name");
}
System.out.println("Method : " + methodName);
Source result = // create the result using methodName
return result;
}
catch (Throwable e)
{
e.printStackTrace();
throw new RuntimeException("Error in provider endpoint", e);
}
}
}
Regards
Sebastien