Apache Axis (Web サービスの簡単なデプロイ)

Axis には JWS (Java Web Service) ファイルという簡単な Web サービスのデプロイの機能があります。
(これはこちらでセットアップした Axis のサンプルに入っていた例を紹介しています)

かんたんな足し算と引き算の結果を返す Java Bean があります。

public class Calculator {

public int add(int i1, int i2)
{
return i1 + i2;
}

public int subtract(int i1, int i2)
{
return i1 - i2;
}

}

Axis-Examples.war ディレクトリの中に上の内容で Calculator.jws という名前のファイルを作成します。

ほんとはそれだけでいいらしいのですが、今回は追加で以下の作業が必要でした。

まず、WEB-INFjwsClasses というディレクトリを作成します。

その WEB-INFjwsClasses というディレクトリに上の Calculator.jws と同じ内容で、Calculator.java とそれをコンパイルした Calculator.class をおきます。

通常、この2つの作業 (ディレクトリの作成と .java ファイルのコピー/コンパイル)は自動的になされるようです。

こちらが Calculator Web サービスにアクセスするクライアントのプログラムです。

サーバーの URL にあわせて太字の部分を変えています。

/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/

package samples.userguide.example2 ;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;

import javax.xml.rpc.ParameterMode;

public class CalcClient
{
public static void main(String [] args) throws Exception {
Options options = new Options(args);

String endpoint = "http://asdomino:" + options.getPort() +
"/webapp/axis/Calculator.jws";


args = options.getRemainingArgs();

if (args == null || args.length != 3) {
System.err.println("Usage: CalcClient <add|subtract> arg1 arg2");
return;
}

String method = args[0];
if (!(method.equals("add") || method.equals("subtract"))) {
System.err.println("Usage: CalcClient <add|subtract> arg1 arg2");
return;
}

Integer i1 = new Integer(args[1]);
Integer i2 = new Integer(args[2]);

Service service = new Service();
Call call = (Call) service.createCall();

call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName( method );
call.addParameter( "op1", XMLType.XSD_INT, ParameterMode.IN );
call.addParameter( "op2", XMLType.XSD_INT, ParameterMode.IN );
call.setReturnType( XMLType.XSD_INT );

Integer ret = (Integer) call.invoke( new Object [] { i1, i2 });

System.out.println("Got result : " + ret);
}
}

処理自体の流れとしてはこんなかんじです。

// 宛先のセット
String endpoint = "http://asdomino:" + options.getPort() + "/webapp/axis/Calculator.jws";

// 呼び出すメソッドのセット (add か subtract か)
String method = args[0];

// パラメータのセット (add か subtract の引き数)
Integer i1 = new Integer(args[1]);
Integer i2 = new Integer(args[2]);

// サービス呼び出しのための手順
Service service = new Service();
Call call = (Call) service.createCall();

call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName( method );
call.addParameter( "op1", XMLType.XSD_INT, ParameterMode.IN );
call.addParameter( "op2", XMLType.XSD_INT, ParameterMode.IN );
call.setReturnType( XMLType.XSD_INT );

// 実際の呼び出し
Integer ret = (Integer) call.invoke( new Object [] { i1, i2 });

Axis の必要な jar ファイルをクラスパスに指定して、クライアントのクラスをコンパイルします。

実行結果です。

Web Service Deployment Descriptor (WSDD) というものを使用して Web サービスのデプロイも可能です。
org.apache.client.AdminClient というクラスを使用して行なうのですが、これはローカルでの作業になります。つまり、iSeries でやる場合は Qshell を使用して行ないます。
ダウンロードされてきたものについてきたものはインターネットへのアクセスがありますので、インターネット接続のできる iSeries で行なう必要がありますね。(こちらにはないので今回テストは断念しました ...)

[Top Pageに戻る]

[PR] | ハウスクリーニング葬儀 東京韓国食材転職サイトSEOアクセス解析ハウスメーカーレンタルオフィスSEO対策消費者金融不動産担保ローン時計車 買取ハワイ挙式アスクル転職生命保険テンプレート沖縄旅行動画免許合宿二輪引越し消費者金融税理士ゴルフ会員権留学レーシックマッサージFX投資信託くりっく365アフィリエイト育毛剤FXホームページ制作デイトレードFXホノルルマラソンベスト ハワイ ホテル レーツバリ島ハワイウエディングHawaii hotelsHawaii Activitiesbhhr
【運営会社「パラダイムシフト」サービス】 ハワイ現地オプショナルツアーリラックマ.ビジネスクラス ハワイ) - ビジネスクラス航空券 - 格安航空券(1) - 格安航空券(2) - 海外ホテル - 韓国旅行
無料ホームページ作成 - レンタルサーバー - 携帯ホームページ - ブログ - ホテル 予約 - タイムシェア - ヴィラ - ハワイ コンドミニアム - バリ島 ホテル - ハワイ 不動産 - プーケット ホテル
[PR] 美容整形外科を選ぶならこちらから。まずは比較してみましょう