WebSphere Application Server, Version 6.1   
             オペレーティング・システム: AIX , HP-UX, Linux, Solaris, Windows, Windows Vista

             目次と検索結果のパーソナライズ化

例: クライアント・サイド・アダプターの実装

CommandTarget インターフェースは、クライアントが実装する 1 つのメソッド executeCommand を 宣言します。executeCommand メソッドは、TargetableCommand オブジェクトを入力として 取り、また TargetableCommand を戻します。

executeCommand メソッドのクライアント・サイド実装

この例は、 クライアント・サイド・アダプターで使用されるメソッドの実装を示します。 この実装は以下のことを行います。
  • 受け取るコマンドをシリアライズします。
  • サーブレットに対する HTTP 接続を作成します。
  • 入力および出力ストリームを作成し、コマンドがサーバーに送信され、 戻されるときに、コマンドを処理します。
  • 出力ストリーム上にコマンドを配置します。
  • コマンドをサーバーに送信します。
  • 入力ストリームから戻されたコマンドを検索します。
  • 戻されたコマンドを executeCommand メソッドの呼び出し元に戻します。
public TargetableCommand executeCommand(TargetableCommand command)
throws CommandException
{
try {
// Serialize the command
byte[] array = serialize(command);
// Create a connection to the servlet
URL url = new URL
("http://" + hostName +
"/servlet/com.ibm.websphere.command.servlet.CommandServlet");
HttpURLConnection httpURLConnection =
(HttpURLConnection) url.openConnection();
// Set the properties of the connection
...
// Put the serialized command on the output stream
OutputStream outputStream = httpURLConnection.getOutputStream();
outputStream.write(array);
// Create a return stream
InputStream inputStream = httpURLConnection.getInputStream();
// Send the command to the servlet
httpURLConnection.connect();
ObjectInputStream objectInputStream =
new ObjectInputStream(inputStream);
// Retrieve the command returned from the servlet
Object object = objectInputStream.readObject();
if (object instanceof CommandException) {
throw ((CommandException) object);
}
// Pass the returned command back to the calling method
return (TargetableCommand) object;
}
// Handle exceptions
....
}



関連タスク
コマンドの使用
関連資料
例: サーブレット内でのコマンドの実行
例: コマンド・ターゲットの書き込み (クライアント・サイド・アダプター)
参照トピック    

ご利用条件 | フィードバック

最終更新: Jan 21, 2008 5:05:53 PM EST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.base.doc/info/aes/ae/rcmd_implclsideadapter.html