简体   繁体   中英

Get SOAP message from Wildfly WebServiceContext

I have a Wildfly 8.1.0 WebService with 4 WebMethods.

I need to log SOAP message (business requirement)

I injected the WebServiceContext which works

@Resource
private WebServiceContext wsContext;

I can get the org.apache.cxf.jaxws.context.WrappedMessageContext :

WrappedMessageContext wrappedMessageContext = (WrappedMessageContext) wsContext.getMessageContext();

and also the org.apache.cxf.message.Message :

Message message = wrappedMessageContext.getWrappedMessage();

But not the SOAP message.

Anyone has some ideas?

You're retrieving the wrong/unnecessary message context. What you should have is the SOAPMessageContext , from which you can easily get the SOAPMessage . You should have instead:

SOAPMessageContext msgCtxt = (SOAPMessageContext) wsContext.getMessageContext();
       SOAPMessage soapMsg = msgCtxt.getMessage(); //gotten your SOAP message
       //log your message

EDIT:

Based on your comment, it appears you're injecting a CXF-specific MessageContext (probably shouldn't do that, for the sake of obvious portability problems).

org.apache.cxf.binding.soap.SoapMessage soapMessage =  (org.apache.cxf.binding.soap.SoapMessage)wrappedMessage.getWrappedMessage();     //continuing from your current code

Unfortunately injecting the WebServiceContext and trying to get the SoapMessage did not work, so I went the SOAPHandler way.

Added a handler chain to my web service:

@HandlerChain(file = "my-handler.xml", name = "MyWebServiceHandler")

Created my own handler class and implemented javax.xml.ws.handler.soap.SOAPHandler.

From my SOAPHandler implemented method "handleMessage(SOAPMessageContext context)" I could get hold of the SOAP message like this:

SOAPMessage soapMessage = context.getMessage();
soapMessage.writeTo(outputStream);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM