Q: How do I set a header when using { { { WSDL2Java } } } stubs?

A: There are two styles of headers, explicit and implicit. Explicit headers are defined in the WSDL of the service. The { { { WSDL2Java } } } generation tool will recognize these headers in most cases and emit stub class methods that include the headers as arguments to the methods.

In other cases, you may want to set headers that are not explicitly called out in the WSDL. For instance, you want to do some custom processing in a handler or add security. In this case you can add headers to request before you invoke the stub method.

There are are two setHeader APIs on the org.apache.axis.client.Stub class. The first takes the namespace, name and value of the header.

 { { { setHeader(String namespace, String partName, Object headerValue) } } } 

{ { { The second takes a SoapHeaderElement: } } }

 { { { setHeader(SOAPHeaderElement header) } } } 

Here is an example of using the first API

{{{ { { { FooServiceLocator loc = new FooServiceLocator(); } } }

Question: { { { Can someone explain why the variable "binding" (in the above code) needs to be cast to a Stub if the FooService class (as typically generated by WSDL2Java) already extends the org.apache.axis.client.Stub class? } } }

Answer: { { { Because getFooService() will return the stub as a FooService object, which is an Interface that contains only the service operations. Casting this to a Stub object allows access to the JAX-RPC and Axis Stub APIs. } } }

Q: How do I get response headers when using { { { WSDL2Java } } } stubs?

A: You use the { { { getResponseHeader() } } } API in the Axis Stub object.

 { { { ["SOAPHeaderElement"] getResponseHeader(String namespace, String partName) } } } 

Or to get the entire list of headers

 { { { ["SOAPHeaderElement"][] getResponseHeaders() } } } 

Here is a code snippet that gets a header returned from myOperation().

{{{ { { {

Q: What do the getHeader() APIs do in the Stub object? Why don't they return the response headers?

Answer: These APIs return the headers in the Stub/Call that will be/have been sent in an operation request. This changed in Axis 1.1 so there was no way to get headers from the Stub (you could still get them from the Call object) and the { { { getResponseHeader } } } APIs were added post 1.1 to address this.

Q: If I am using Axis 1.1, how do I get the response headers?

Answer: { { { Use the Call object, which is available from the Service object, to get the SOAPEnvelope. This object has a slew of header functions in it. Or you can get the JAX-RPC javax.xml.soap.SOAPHeader object by calling getHeader() on the SOAPEnvelope. You will have to do your own enumeration on the headers, as the SOAPEnvelope class generally returns Iterators. } } }

Here is an example of how to use the Axis APIs on the SOAPEnvelope

{{{ { { {

AxisProjectPages/WSDLJavaHeader (last edited 2009-09-20 23:32:07 by localhost)