1

I'm writing a JAX-WS WebService but I am running into a little stumbling block when it comes to extracting information from the SOAP header. My WebService class is annotated with @WebService and I am inject the WebServiceContext into the class with:

@Resource
private WebServiceContext webServiceContext;

but I'm a little stuck at this point as to how to extract the SOAP header information.

I'm using Spring 3, but haven't seen any methods/util classes there either that would shed some light on the issue. From what I've seen online, I can use getMessageContext() and cast to a SOAPMessageContext, but I see significant numbers of people failing at that level complaining about casting problems with no offered solution.

I have not yet tried it, so before I did, I was wondering if this was the preferred method, or if there is a better technique to use.

Thanks,

Eric

Eric B.
  • 23,425
  • 50
  • 169
  • 316

2 Answers2

2

I guess that you can get the SoapMessageContext with a message handler. You can check the response here.

Implementing a SoapMessageHandler like this should work:

public class SoapHeadersHandler implements SOAPHandler<SOAPMessageContext>
{

  @Override
  public boolean handleMessage(SOAPMessageContext soapMessageContext)
  {
    try
    {
      Object[] headers = soapMessageContext.getHeaders(...);
    }
    catch (SOAPException e)
    {
      // Handle exception
    }

    return true;
  }

}
Community
  • 1
  • 1
Denian
  • 737
  • 2
  • 8
  • 17
1

Posting here what I did, as it doesnt requires creating an extra class

final HttpServletRequest req = (HttpServletRequest) wsCtxt.getMessageContext().get(MessageContext.SERVLET_REQUEST);
String headerValue = req.getHeader("myHeaderName");
TheBakker
  • 2,852
  • 2
  • 28
  • 49