| Oracle® Fusion Middleware Oracle WebLogic Server JAX-RPC Webサービスの高度な機能のプログラミング 11g リリース1 (10.3.6) B61634-05 |
|
![]() 前 |
![]() 次 |
この章では、WebLogic Java API for XML-based RPC (JAX-RPC) Webサービスと非同期機能を併用する方法について説明します。
この章では、以下のトピックについて説明します。
ここまでの各項では、WebLogic Webサービスの非同期機能(Webサービスの信頼性のあるメッセージング、会話、非同期リクエスト-レスポンス、およびバッファリング)を単独で使用する方法を説明します。ただし、通常、Webサービスではこれらの機能を併用しています。例については、「信頼性のある会話型Webサービスを実装するJWSファイルの例」および「信頼性のある会話型Webサービスを非同期で呼び出すクライアントWebサービスの例」を参照してください。
併用すると、個々の機能についての節で説明した制限事項の一部が適用されなくなったり、場合によっては追加の制限事項が適用されたりします。次の表に、様々な機能を組み合せる場合の考慮事項をまとめます。
表6-1 非同期機能を一緒に使用する場合の考慮事項
| 機能の組合せ | 考慮事項 |
|---|---|
|
非同期リクエスト-レスポンス機能とWebサービスの信頼性のあるメッセージング/バッファ機能 |
|
|
非同期リクエスト-レスポンス機能とWebサービスの信頼性のあるメッセージング機能 |
非同期コンテキストのいずれか1つ( |
|
非同期リクエスト-レスポンス機能とバッファ機能 |
バッファ付きWebサービス操作を呼び出すクライアントWebサービスで |
|
会話機能とWebサービスの信頼性のあるメッセージング機能 |
|
|
会話機能と非同期リクエスト-レスポンス機能 |
クライアントの会話型Webサービスとその他のWebサービスとの間における非同期のレスポンスもまた、会話に参加します。たとえば、WebServiceAが会話型で、非同期リクエスト-レスポンスを使用してWebServiceBを呼び出すとします。WebServiceAは会話型であるため、WebServiceBからの非同期レスポンスも同じ会話に参加します。 |
次のサンプルのJWSファイルでは、信頼性があり、かつ会話型でもあるWebサービスを実装しています。
package examples.webservices.async_mega;
import java.io.Serializable;
import weblogic.jws.WLHttpTransport;
import weblogic.jws.Conversation;
import weblogic.jws.Policy;
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService(name="AsyncMegaPortType",
serviceName="AsyncMegaService",
targetNamespace="http://examples.org/")
@Policy(uri="AsyncReliableConversationPolicy.xml",
attachToWsdl=true)
@WLHttpTransport(contextPath="asyncMega",
serviceUri="AsyncMegaService",
portName="AsyncMegaServicePort")
/**
* Web Service that is both reliable and conversational.
*/
public class AsyncMegaServiceImpl implements Serializable {
@WebMethod
@Conversation (Conversation.Phase.START)
public String start() {
return "Starting conversation";
}
@WebMethod
@Conversation (Conversation.Phase.CONTINUE)
public String middle(String message) {
return "Middle of conversation; the message is: " + message;
}
@WebMethod
@Conversation (Conversation.Phase.FINISH)
public String finish(String message ) {
return "End of conversation; the message is: " + message;
}
}
次のJWSファイルでは、「信頼性のある会話型Webサービスを実装するJWSファイルの例」に記載のWebサービスにおける様々な会話型のメソッドを確実に呼び出すクライアントWebサービスの実装方法を示します。クライアントJWSファイルでは、非同期リクエスト-レスポンス機能も使用しています。
package examples.webservices.async_mega;
import weblogic.jws.WLHttpTransport;
import weblogic.jws.ServiceClient;
import weblogic.jws.AsyncResponse;
import weblogic.jws.AsyncFailure;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.xml.rpc.Stub;
import weblogic.wsee.async.AsyncPreCallContext;
import weblogic.wsee.async.AsyncCallContextFactory;
import weblogic.wsee.async.AsyncPostCallContext;
import weblogic.wsee.reliability.WsrmUtils;
import examples.webservices.async_mega.AsyncMegaPortType;
import examples.webservices.async_mega.AsyncMegaService;
import examples.webservices.async_mega.AsyncMegaService_Impl;
import java.rmi.RemoteException;
@WebService(name="AsyncMegaClientPortType",
serviceName="AsyncMegaClientService",
targetNamespace="http://examples.org/")
@WLHttpTransport(contextPath="asyncMegaClient",
serviceUri="AsyncMegaClient",
portName="AsyncMegaClientServicePort")
/**
* Client Web Service that has a conversation with the AsyncMegaService
* reliably and asynchronously.
*/
public class AsyncMegaClientImpl {
@ServiceClient(
wsdlLocation="http://localhost:7001/asyncMega/AsyncMegaService?WSDL",
serviceName="AsyncMegaService",
portName="AsyncMegaServicePort")
private AsyncMegaPortType port;
@WebMethod
public void runAsyncReliableConversation(String message) {
AsyncPreCallContext apc = AsyncCallContextFactory.getAsyncPreCallContext();
apc.setProperty("message", message);
try {
port.startAsync(apc);
System.out.println("start method executed.");
port.middleAsync(apc, message );
System.out.println("middle method executed.");
// Since this service is not conversational, any state kept in the port
// field will be lost when this method returns. In the case of reliable
// messaging, this state includes the ID of the reliable sequence being
// used to send messages. The setFinalMessage method specifies
// that this is the final message to be sent on this sequence. This
// will allow the reliable messaging subsystem to proactively clean up
// the reliable sequence instead of timing out.
WsrmUtils.setFinalMessage((Stub)port);
port.finishAsync(apc, message );
System.out.println("finish method executed.");
}
catch (RemoteException e) {
e.printStackTrace();
}
}
@AsyncResponse(target="port", operation="start")
public void onStartAsyncResponse(AsyncPostCallContext apc, String message) {
System.out.println("-------------------");
System.out.println("Got message " + message );
System.out.println("-------------------");
}
@AsyncResponse(target="port", operation="middle")
public void onMiddleAsyncResponse(AsyncPostCallContext apc, String message) {
System.out.println("-------------------");
System.out.println("Got message " + message );
System.out.println("-------------------");
}
@AsyncResponse(target="port", operation="finish")
public void onFinishAsyncResponse(AsyncPostCallContext apc, String message) {
System.out.println("-------------------");
System.out.println("Got message " + message );
System.out.println("-------------------");
}
@AsyncFailure(target="port", operation="start")
public void onStartAsyncFailure(AsyncPostCallContext apc, Throwable e) {
System.out.println("-------------------");
e.printStackTrace();
System.out.println("-------------------");
}
@AsyncFailure(target="port", operation="middle")
public void onMiddleAsyncFailure(AsyncPostCallContext apc, Throwable e) {
System.out.println("-------------------");
e.printStackTrace();
System.out.println("-------------------");
}
@AsyncFailure(target="port", operation="finish")
public void onFinishAsyncFailure(AsyncPostCallContext apc, Throwable e) {
System.out.println("-------------------");
e.printStackTrace();
System.out.println("-------------------");
}
}