13.5. JAX-WS Development Reference

13.5.1. Enable Web Services Addressing (WS-Addressing)

Prerequisites

  • Your application must have an existing JAX-WS service and client configuration.

Procedure 13.1. Annotate and Update client code

  1. Annotate the service endpoint

    Add the @Addressing annotation to the application's endpoint code.

    Example 13.28. @Addressing annotation

    This example demonstrates a regular JAX-WS endpoint with the @Addressing annotation added.
    package org.jboss.test.ws.jaxws.samples.wsa;
     
    import javax.jws.WebService;
    import javax.xml.ws.soap.Addressing;
     
    @WebService
    (
       portName = "AddressingServicePort",
       serviceName = "AddressingService",
       wsdlLocation = "WEB-INF/wsdl/AddressingService.wsdl",
       targetNamespace = "http://www.jboss.org/jbossws/ws-extensions/wsaddressing",
       endpointInterface = "org.jboss.test.ws.jaxws.samples.wsa.ServiceIface"
    )
    @Addressing(enabled=true, required=true)
    public class ServiceImpl implements ServiceIface
    {
       public String sayHello()
       {
          return "Hello World!";
       }
    }
    
  2. Update client code

    Update the client code in the application so that it configures WS-Addressing.

    Example 13.29. Client configuration for WS-Addressing

    This example demonstrates a regular JAX-WS client updated to configure WS-Addressing.
    package org.jboss.test.ws.jaxws.samples.wsa;
     
    import java.net.URL;
    import javax.xml.namespace.QName;
    import javax.xml.ws.Service;
    import javax.xml.ws.soap.AddressingFeature;
     
    public final class AddressingTestCase
    {
       private final String serviceURL = 
           "http://localhost:8080/jaxws-samples-wsa/AddressingService";
       
       public static void main(String[] args) throws Exception
       {
          // construct proxy
          QName serviceName = 
              new QName("http://www.jboss.org/jbossws/ws-extensions/wsaddressing",
                        "AddressingService");
          URL wsdlURL = new URL(serviceURL + "?wsdl");
          Service service = Service.create(wsdlURL, serviceName);
          ServiceIface proxy = 
              (ServiceIface)service.getPort(ServiceIface.class,  
                                            new AddressingFeature());
          // invoke method
          proxy.sayHello();
       }
    }
    
Result

The client and endpoint are now communicating using WS-Addressing.