Enable Web Services Addressing support for JAX-WS applications using WS-Policy
For JAX-WS applications, we can enable WS-Addressing support during the development of a client or service application by adding WS-Policy assertions into the WSDL document.
The JAX-WS 2.2 specification introduces functionality that enables WS-Policy assertions in the application WSDL document to be mapped to and from Java annotations in the code.
There are several ways of enabling WS-Addressing support for JAX-WS applications. The method of using WS-Policy will be effective unless it is overridden by another method with greater precedence, such as if you are using AddressingFeature classes or using Addressing annotations. See the parent topic: Enabling Web Services Addressing support for JAX-WS applications for full details about the order of precedence used by WebSphere Application Server.
WebSphere Application Server version 8 supports the JAX-WS 2.2 specification. One of the differences between the JAX-WS 2.1 and JAX-WS 2.2 specifications is that whereas the presence of WS-Policy in an application's WSDL was formerly ignored, if WS-Addressing support is defined within the WS-Policy, this will now be used by WebSphere Application Server in the configuration of the application. As the presence of WS-Policy in an application's WSDL is now checked for WS-Addressing configuration, you may notice a change in behavior in applications formerly run in previous versions of WAS.
If we add an Addressing annotation to the provider code and use the wsgen command-line tool to generate the WSDL document, it will contain WS-Policy assertions specifying the WS-Addressing support. However, if you are looking at the published WSDL document for the provider service, it is possible that policy defined in policy sets is showing, as this would overwrite any annotations defined in the code.
For an existing WSDL document to create Java code, when WebSphere Application Server reads the WSDL, if any WS-Policy assertions specifying WS-Addressing support are present, the generated Java code will contain Addressing annotations.
- To enable WS-Addressing support on clients, use WS-Policy assertions in the code, with optional attributes as required. The wsam:Addressing assertion indicates that WS-Addressing is required. To indicate that WS-Addressing is supported but not mandatory, add the wsp:Optional attribute. In the following example, WS-Addressing is supported, but is not mandatory and the messaging format to use has not been specified.
<wsp:Policy> <wsam:Addressing wsp:Optional="true"> <wsp:Policy/> </wsam:Addressing> </wsp:Policy>This example is equivalent to the policy set configuration of WS-Addressing being set to non-mandatory and the messaging style being set to synchronous and asynchronous.
- To specify the message exchange pattern to be employed, use the wsam:AnonymousResponses assertion for synchronous message exchanges and the wsam:NonAnonymousResponses assertion for asynchronous message exchanges. In the following example, WS-Addressing support is set as mandatory and a synchronous message exchange pattern has been specified.
<wsp:Policy> <wsam:Addressing> <wsp:Policy> <wsam:AnonymousResponses/> </wsp:Policy> </wsam:Addressing> </wsp:Policy>This example is equivalent to the policy set configuration of WS-Addressing being set to required and the messaging style being set to synchronous only.For more information, see the Web Services Addressing 1.0 - Metadata specification document.
Results
If we add WS-Addressing annotations to the application code specifying that WS-Addressing is enabled, when you generate the WSDL it will contain WS-Policy assertions.
When WS-Policy assertions specifying WS-Addressing support are included in the WSDL, WS-Addressing headers are included in the generated SOAP messages.
If we specify that WS-Addressing is required and an inbound SOAP message is received that does not include any WS-Addressing headers, an exception occurs.
Related tasks
Enable WS-Addressing for JAX-WS applications Enable Web Services Addressing support for JAX-WS applications using addressing features Develop a JAX-WS client from a WSDL file
wsgen command for JAX-WS applications wsimport command for JAX-WS applications
Related information:
Web Services Addressing 1.0 - Metadata specification