Tuesday, July 23, 2013

JAX-WS Retrieving HTTP Headers


Here's a quick blog on how to retrieve HTTP Headers from a JAX-WS service.  In this example, I'm exposing a web service(I'm providing the service).  I created a JAX-WS handler following these directions


In the handleMessage() method, use the SOAPMessageContext to get the http headers by using the "get" method and passing the  javax.xml.ws.handler.MessageContext's HTTP_REQUEST_HEADERS property.


This will return a Map<String, List<String>>.  Where the key is the http header name and the List<String> is the value... I'm not sure why it's a list, but I just retrieved the first value and got what I expected.

Here's the code:



For the following message(raw view from SOAP UI):

I got the following output in my console:


Hope this helps!  Let me know if you have questions or suggestions!