Search |
||
Adding SOAP headers in the JAX-WS RI is easier in 2.1 EA3Posted by kohsuke on November 20, 2006 at 3:07 PM PST
One of the additions in the JAX-WS RI 2.1 EA3 is a simple way to add SOAP headers for your request. The official "portable" way of doing this is that you creaate a SOAPHandler and mess with SAAJ. This works, but Vivek though it's just too much work for such a simple thing one day, and we all agreed. So we quickly put together a better way to do this. Here's how to do this: When you create a proxy or dispatch object, they implement BindingProvider interface. When you use the JAX-WS RI, you can downcast to WSBindingProvider which defines a few more methods provided only by the JAX-WS RI. This interface lets you set an arbitrary number of Header object, each representing a SOAP header. You can implement it on your own if you want, but most likely you'd use one of the factory methods defined on Headers class to create one.
import com.sun.xml.ws.developer.WSBindingProvider;
HelloPort port = helloService.getHelloPort(); // or something like that...
WSBindingProvider bp = (WSBindingProvider)port;
bp.setOutboundHeader(
// simple string value as a header, like <simpleHeader>stringValue</simpleHeader>
Headers.create(new QName("simpleHeader"),"stringValue"),
// create a header from JAXB object
Headers.create(jaxbContext,myJaxbObject)
);
Once set, it will take effect on all the successive methods. If you'd like to see more factory methods on Headers, please let us know! We are also talking about adding a switch to wsimport so that you won't have to downcast. »
Related Topics >>
Java Web Services and XML Comments
Comments are listed in date ascending order (oldest first)
How are SOAP headers accessed in a Web service operation?
Submitted by pshrosbree on Thu, 2009-10-08 01:46.
I have a client application that sets up some SOAP headers to specify a message ID and a callback URL, calls the Web service operation, and the Web service operation is supposed to callback asynchronously on the SOAP header provided URL.
I can cheat, by creating a singleton map that maps MessageIDs to URLs, which is populated by the handler chain, and the operation can access this map, but this is not scalable, and it is nasty. The best would be if there were a way to access the SOAP headers inside the operation.
In the operation I have access to the WebServiceContext, and so the MessageContext, and so the HTTP Request headers, but I can’t see how to access the SOAP headers. Is there a portable to do this in Metro 1.4?
To answer my own
Submitted by pshrosbree on Thu, 2009-10-08 05:27.
To answer my own question:
Use
HeaderList headers = (HeaderList) messageContext.get(JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY);
|
||
|
|
How to set header in Web service response?