Metroは、WSDLまたはwsit-client.xml構成ファイルのいずれかから実行時にポリシーを適用します。そのため、ポリシーに関連するコードは生成されません。この投稿によると、現時点ではプログラムで行うことはできません。
このチュートリアルでは、WSSで実行できることのいくつかをかなりよく説明しています。この場合、すべてが当てはまるとは限りませんが、それでも十分に読むことができます。
WSSをサポートするクライアントを生成する最も簡単な方法はwsimport
、Metroのスクリプトを使用することです。
cd metro/bin/
mkdir src target
./wsimport.sh -s src -d target -extension -Xendorsed -verbose YourService.wsdl
次に、Metroをアプリケーションサーバーにインストールします(ライブラリを正しい場所にコピーするか、antスクリプトを実行します)。
ant -f metro-on-glassfish.xml
次に、ローカルのWSDLファイルをクラスパス(リソースフォルダーなど)に配置します。これにより、Metroは実行時にファイルを取得して、生成されたYourService
クラスからポリシーを適用できます。
private final static URL YOURSERVICE_WSDL_LOCATION;
// This is enough, you don't need the wsdlLocation attribute
// on the @WebServiceClient annotation if you have this.
static {
YOURSERVICE_WSDL_LOCATION =
CustomerService.class.getClassLoader().getResource("YourService.wsdl");
}
public YourService() {
super(YOURSERVICE_WSDL_LOCATION,
new QName("http://tempuri.org/", "YourService"));
}
また、WS-Addressingが必要な場合は、バインディングメソッドに手動で機能を追加する必要があります(Metroが生成したことはないので、常に自分で追加する必要があります)。
@WebEndpoint(name = "WSHttpBinding_IYourService")
public IYourService getWSHttpBindingIYourService() {
WebServiceFeature wsAddressing = new AddressingFeature(true);
IYourService service =
super.getPort(new QName("http://xmlns.example.com/services/Your",
"WSHttpBinding_IYourService"), IYourService.class,
wsAddressing);
return service;
}