|
|
WebOTX Manual V10.4 (第4版) 目次を表示 |
public boolean handleMessage(LogicalMessageContext context); public boolean handleFault(LogicalMessageContext context); public void close(MessageContext ctx);なお、非同期通信でハンドラが呼び出される場合にはhandleMessageおよびhandleFaultの戻り値としてtrueを必ず返却するように実装してください。 Logical Handlerのサンプルは次のようになります。
package sample;
import javax.xml.ws.handler.*;
public class HelloLogicalHandler implements LogicalHandler<LogicalMessageContext> {
public boolean handleMessage(LogicalMessageContext context) {
//通常のメッセージの送受信ごとに呼び出されます。
return true;
}
public boolean handleFault(LogicalMessageContext context) {
//Faultメッセージの送受信ごとに呼び出されます。
return true;
}
public void close(MessageContext context) {
//メッセージ、Faultメッセージ、例外をディスパッチする直前に呼び出されます。
}
}
public Set<QName> getHeaders(); public boolean handleMessage(SOAPMessageContext context); public boolean handleFault(SOAPMessageContext context); public void close(MessageContext ctx);Protocol Handlerのサンプルは次のようになります。
package sample;
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
public class HelloSOAPHandler implements SOAPHandler<SOAPMessageContext> {
public Set<QName> getHeaders() {
return null;
}
public boolean handleMessage(SOAPMessageContext context) {
//通常のメッセージの送受信ごとに呼び出されます。
return true;
}
public boolean handleFault(SOAPMessageContext context) {
//Faultメッセージの送受信ごとに呼び出されます。
return true;
}
public void close(MessageContext context) {
//メッセージ、Faultメッセージ、例外をディスパッチする直前に呼び出されます。
}
}
Handler handler = new HelloLogicalHandler(); Handler handler2 = new HelloSOAPHandler(); List<Handler> handlerList = new ArrayList<Handler>(); handlerList.add(handler); handlerList.add(handler2); Binding binding =((BindingProvider)port).getBinding(); binding.setHandlerChain(handlerList);◇ バインディングファイルに記述して登録する場合の例
<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-name>HelloLogicalHandler</handler-name>
<handler-class>sample.HelloLogicalHandler</handler-class>
</handler>
<handler>
<handler-name>HelloSOAPHandler</handler-name>
<handler-class>sample.HelloSOAPHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>
<handler-class>には、登録するハンドラのクラス名を記述します。import javax.jws.HandlerChain; @HandlerChain(file="handlers.xml")バインディングファイルは、クラスパスの通った場所、たとえば、WARファイルのWEB_INF/classes/配下などに置いておく必要があります。
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns='http://www.nec.com/WebOTX/xml/ns/jax-ws/ri/runtime'version='2.0'>
<endpoint
name='hellows-soap12'
implementation='sample.Hello'
binding="http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/"
url-pattern='/hello'/>
</endpoints>
・Webサービスエンドポイント実装クラスに@BindingType(value="http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/") を記述する
import javax.jws.WebService;
import javax.xml.ws.BindingType;
@WebService
@BindingType(value="http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/")
public class Hello {
:
}
※ クライアント側については特に指定は不要です。<?xml version="1.0" encoding="UTF-8"?> <endpoints xmlns='http://www.nec.com/WebOTX/xml/ns/jax-ws/ri/runtime' version='2.0'> <endpoint name="Mtom" implementation="sample.HelloImpl" url-pattern="/hello" enable-mtom="true"/> </endpoints>(b) <endpoint> の属性 binding にMTOM Bindingの値を記述する
<endpoint ...
binding="http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true"
/>
SOAP1.2のMTOMメッセージを使用する場合は次のように指定してください。
<endpoint ...
binding="http://www.w3.org/2003/05/soap/bindings/HTTP/?mtom=true"
/>
◇ Webサービスエンドポイントにアノテーションを記述する方法 import javax.xml.ws.soap.MTOM;※ 前述のSOAP1.2の指定と組み合わせることができます。
@MTOM
import javax.xml.ws.BindingType; @BindingType(value="http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true")SOAP1.2のMTOMメッセージを使用する場合は次のように指定してください。
import javax.xml.ws.BindingType; @BindingType(value="http://www.w3.org/2003/05/soap/bindings/HTTP/?mtom=true")
<enableWrapperStyle>をWSDLファイルに定義します。
◇ <definitions>に指定する場合の例
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" ... xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" targetNamespace="http://sample" name="Hello">
<bindings>
<enableWrapperStyle>false</enableWrapperStyle>
:
</bindings>
</definitions>
◇ <portType>に指定する場合の例
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" ... xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" targetNamespace="http://sample" name="Hello">
:
<portType name="Hello">
<bindings>
<enableWrapperStyle>false</enableWrapperStyle>
</bindings>
:
</portType>
:
</definitions>
◇ <operation>に指定する場合の例
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" ... xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" targetNamespace="http://sample" name="Hello">
:
<portType name="Hello">
<operation name="sayHello">
<bindings>
<enableWrapperStyle>false</enableWrapperStyle>
</bindings>
:
</operation>
</portType>
:
</definitions>
<bindings>をルート要素とするバインディングファイル(bindings.xml)を用意し、それを、wsimportコマンドの-bオプションで指定します。
bindings.xml
<bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" wsdlLocation="http://example.org/foo.wsdl" xmlns="http://java.sun.com/xml/ns/jaxws">
<enableWrapperStyle>true</enableWrapperStyle>
</bindings>
HelloService service = new HelloService(); Hello port = service.getHelloPort(); ((javax.xml.ws.BindingProvider)port).getRequestContext().put(<キー>,<値>);
MtomSample port = new MtomService().getMtomPort(new MTOMFeature());(b) dispatchの作成時にMTOMFeatureを引数として渡す
javax.xml.ws.Service.createDispatch(....,newjavax.xml.ws.soap.MTOMFeature())(c) クライアントプロキシのSOAPBindingに対してSOAPBinding.setMTOMEnabled(true)を実行する
Hello port = new HelloService.getHelloPort(); SOAPBinding binding = (SOAPBinding)((BindingProvider)port).getBinding(); binding.setMTOMEnabled(true);
| キー | 値 | 既定値 |
|---|---|---|
| javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY | http://localhost:8080/hellows/hello など | なし |
| キー | 値 | 既定値 |
|---|---|---|
| com.nec.webotx.webservice.xml.ws.client.BindingProviderProperties. CONNECT_TIMEOUT | タイムアウト値(単位:ミリ秒) | 30000 |
| キー | 値 | 既定値 |
|---|---|---|
| com.nec.webotx.webservice.xml.ws.client.BindingProviderProperties. REQUEST_TIMEOUT | タイムアウト値(単位:ミリ秒) | 300000 |
| キー | 値 | 既定値 |
|---|---|---|
| com.nec.webotx.webservice.xml.ws.client.BindingProviderProperties. CONTENT_NEGOTIATION_PROPERTY | none | pessimistic | optimistic | なし |
[設定例]
-Dcom.nec.webotx.webservice.xml.ws.client.ContentNegotiation=[ none | pessimistic | optimistic ] クライアントクラス
| 値 | 意味 |
|---|---|
| none | Fast Infoset を使用しない |
| pessimistic | レスポンスメッセージのみFast Infoset を利用する |
| optimistic | リクエストメッセージ・レスポンスメッセージの両方でFast Infoset を利用する |
| キー | 値 | 既定値 |
|---|---|---|
|
com.nec.webotx.webservice.xml.ws.client.BindingProviderProperties. HTTP_CLIENT_STREAMING_CHUNK_SIZE |
各チャンク内に書き込むバイト数 | なし |
Memo
JAX-RPCは旧互換のための機能です。
import javax.xml.rpc.server.ServiceLifecycle;
import javax.xml.rpc.server.ServletEndpointContext;
public class TestSoapBindingImpl implements com.nec.webotx.webservice.director.hello.hello_PortType,ServiceLifecycle {
private ServletEndpointContext jaxrpcContext;
public void init(Object context) throws ServiceException {
jaxrpcContext =(ServletEndpointContext) context;
}
public void destroy() {
jaxrpcContext = null;
}
public void getMessageContext() {
jaxrpcContext.getMessageContext();
}
}
_setProperty(com.nec.webotx.webservice.xml.rpc.client.StubPropertyConstants.CONTENT_NEGOTIATION_PROPERTY, "***value***");※クライアントで作成したStubインスタンスに対してこのメソッドを実行する方法もあります。
[設定例]
[foo@webotx ~]$ java -Dcom.nec.webotx.webservice.xml.rpc.client.ContentNegotiation=***value*** クライアントクラスなお、「***value***」には次のうちいずれかの値を指定します。
| 値 | 意味 |
|---|---|
| none | Fast Infoset を使用しない |
| pessimistic | レスポンスメッセージのみFast Infoset を利用する |
| optimistic | リクエストメッセージ・レスポンスメッセージの両方でFast Infoset を利用する |
Caution
インタフェースが変更になる場合は、Webサービス作成ウィザードをやり直す必要があります。