12.5. JAX-WS 開発に関する参考資料

12.5.1. Web Services Addressing (WS-Addressing) の有効化

前提条件

  • お使いのアプリケーションに既存の JAX-WS サービスとクライアント設定がなければなりません。

手順12.1 タスク

  1. サービスエンドポイントのアノテーション

    アプリケーションのエンドポイントコードに @Addressing アノテーションを追加します。

    例12.26 @Addressing アノテーション

    このサンプルでは、通常の JAX-WS エンドポイントに@Addressing アノテーションを追加する場合です。
    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. クライアントコードの更新

    アプリケーションでクライアントコードを更新し WS-Addressing を設定

    例12.27 WS-Addressing のクライアント設定

    このサンプルでは、通常の JAX-WS クライアントを更新し 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();
       }
    }
結果:

クライアントとエンドポイントは WS-Addressing を使い通信を行うようになりました。