O'Reilly logo

Java SOA Cookbook by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Explicitly Enabling Addressing on the Client

Problem

You want to invoke a service that declares it uses addressing.

Solution

You don’t need to do anything, as the JAX-WS runtime can determine that the WSDL advertises that it uses addressing based on the presence of the <wsaw:UsingAddressing/> element in the binding section of the wsdl:definitions.

Create an instance of javax.xml.ws.AddressingFeature, using true as a constructor parameter. Then pass this feature instance to the port accessor method on the service stub you got from wsimport (or its equivalent). The code to do so looks like this:

new MyImplService().getMyImplPort(
  new javax.xml.ws.AddressingFeature(true)
);

Discussion

The JAX-WS 2.1 specification indicates that clients must explicitly enable addressing in order to use addressing in a web service that declares support for it. For each invocation, the client must also explicitly set BindingProvider.SOAPACTION_URI_PROPERTY.

Note

If you attempt to invoke a service that specifies that addressing is required and you have not enabled addressing on the client, you’ll get an error message such as this in the SOAP response’s Fault <faultstring> element: “A required header representing a Message Addressing Property is not present.” You may also get an error that you can read off of a response header that looks like this:

<S:Header> <FaultDetail xmlns="http://www.w3.org/2005/08/addressing"> <ProblemHeaderQName> {http://www.w3.org/2005/08/addressing}Action </ProblemHeaderQName> </FaultDetail> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required