![]() ![]() ![]() ![]() |
以下の節では、最も一般的な Web サービスの使用例について説明します。
これらの使用例では、簡単な WebLogic Web サービスを作成する手順や、デプロイ済みの Web サービスからオペレーションを呼び出す手順を示します。各使用例には、基本的な Java コードと Ant build.xml
ファイルが含まれており、それを使用して、ユーザの開発環境でサンプルを再現したり、設定済みの開発環境の外で指示に従ってサンプルを作成して実行したりできます。
使用例ではサンプルで使用されるツールや技術については詳しく説明していません。特定の機能の詳細については、このガイドの関連するトピックを参照してください。
この節では、1 つのオペレーションを含む非常に簡単な Web サービスの作成方法について説明します。Web サービスを実装する JWS ファイルでは必須の JWS アノテーション @WebService
を 1 つだけ使用しています。JWS ファイルは、JWS メタデータ アノテーションを使用して Web サービスの形式を指定した標準の Java ファイルです。メタデータ アノテーションは JDK 5.0 の新機能であり、Web サービス ファイルにアノテーションを付けるために使用される一連のアノテーションを JWS アノテーションと呼びます。WebLogic Web サービスでは、JSR-181 で定義された標準の JWS アノテーションと、付加価値機能用の WebLogic 固有のアノテーションを使用します。
以下の例では、1 つのオペレーション sayHelloWorld
を含む HelloWorldService
という Web サービスを作成する方法を示します。簡単にするために、オペレーションは入力された文字列値を返す以外には何も行いません。
bin
サブディレクトリにある setDomainEnv.cmd
(Windows) または setDomainEnv.sh
(UNIX) スクリプトを実行して、WebLogic Server 環境を設定します。WebLogic Server ドメインのデフォルトの場所は、BEA_HOME
/user_projects/domains/
domainName
です。BEA_HOME
は BEA Products の最上位のインストール ディレクトリ、domainName
はドメインの名前です。prompt> mkdir /myExamples/hello_world
src
ディレクトリと、JWS ファイル (この手順で後述) のパッケージ名に相当するサブディレクトリを作成します。prompt> cd /myExamples/hello_world
prompt> mkdir src/examples/webservices/hello_world
HelloWorldImpl.java
という Java ファイルを作成します。
サンプル JWS ファイルでは、1 つのパブリック メソッド sayHelloWorld(String)
を含む HelloWorldImpl
という Java クラスが示されています。@WebService
アノテーションは、Java クラスが HelloWorldService
という Web サービスを実装することを指定しています。デフォルトでは、すべてのパブリック メソッドがオペレーションとして公開されます。
src/examples/webservices/hello_world
ディレクトリに HelloWorldImpl.java
ファイルを保存します。build.xml
ファイルを作成し、taskdef
Ant タスクを追加して、jwsc
タスクの完全修飾クラス名を指定します。<project name="webservices-hello_world" default="all">
<taskdef name="jwsc"
classname="weblogic.wsee.tools.anttasks.JwscTask" />
</project>
この手順で説明される追加のターゲット (clean
、undeploy
、client
、run
など) が含まれている、完全なサンプル build.xml
ファイルについては、「HelloWorldImpl.java のサンプル Ant ビルド ファイル」を参照してください。完全な build.xml
ファイルでは、EAR ディレクトリの名前を常にハードコード化して使用するのではなく、${ear-dir}
などのプロパティも使用しています。
jwsc
Ant タスクの呼び出しを、build-service
ターゲット内にラップして、build.xml
ファイルに追加します。<target name="build-service">
<jwsc
srcdir="src"
destdir="output/helloWorldEar">
<jws file="examples/webservices/hello_world/HelloWorldImpl.java" />
</jwsc>
</target>
jwsc
WebLogic Web サービス Ant タスクは、補助的なアーティファクト (デプロイメント記述子、ユーザ定義のデータ型のシリアライゼーション クラス、WSDL ファイルなど) を生成し、ユーザが作成および生成した Java コードをコンパイルして、すべてのアーティファクトを、後で WebLogic Server にデプロイされるエンタープライズ アプリケーション EAR にアーカイブ化します。
build-service
ターゲットを指定して、jwsc
Ant タスクを実行します。prompt> ant build-service
output/helloWorldEar
ディレクトリを見て、jwsc
Ant タスクによって生成されたファイルとアーティファクトを確認します。
wldeploy
Ant タスクを使用して、エンタープライズ アプリケーションにパッケージ化された Web サービスを WebLogic Server にデプロイします。いずれの場合でも、output
ディレクトリにある helloWorldEar
エンタープライズ アプリケーションをデプロイします。
wldeploy
Ant タスクを使用するには、以下のターゲットを build.xml
ファイルに追加します。
<taskdef name="wldeploy"
classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<target name="deploy">
<wldeploy action="deploy"
name="helloWorldEar" source="output/helloWorldEar"
user="${wls.username}" password="${wls.password}"
verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}" />
</target>
wls.username
、wls.password
、wls.hostname
、wls.port
、およびwls.server.name
の値は、ご使用の WebLogic Server インスタンスの対応する値で置き換えます。
deploy
ターゲットを実行して、WAR ファイルをデプロイします。
prompt> ant deploy
http://host
:port
/HelloWorldImpl/HelloWorldImpl?WSDL
この URL は、WLHttpTransport
JWS アノテーションの contextPath
および serviceUri
属性の値を指定して構成しますが、この使用例の JWS ファイルには WLHttpTransport
アノテーションが含まれていないので、2 つの属性のデフォルト値 (JWS クラス内の Java クラスの名前) を指定します。WebLogic Server インスタンスのホスト名とポートを使用します。
Web サービスを呼び出す JAX-RPC Java クライアント アプリケーションの作成例については、「スタンドアロンの JAX-RPC Java クライアントからの Web サービスの呼び出し」を参照してください。
build.xml
ファイルで clean
、build-service
、undeploy
、および deploy
ターゲットを使用すると、開発プロセスの一環として Web サービスを繰り返し更新、再ビルド、アンデプロイ、および再デプロイできます。
package examples.webservices.hello_world;
// @WebService アノテーションをインポートする
import javax.jws.WebService;
@WebService(name="HelloWorldPortType", serviceName="HelloWorldService")
/**
* この JWS ファイルは、1 つのオペレーション sayHelloWorld を含む簡単な
* Java クラス実装の WebLogic Web サービスの基本となる
*
* @author Copyright (c) 2005 by BEA Systems.All rights reserved.
*/
public class HelloWorldImpl {
// デフォルトでは、すべてのパブリック メソッドが Web サービス オペレーションとして公開される
public String sayHelloWorld(String message) {
System.out.println("sayHelloWorld:" + message);
return "Here is the message: '" + message + "'";
}
}
以下の build.xml
ファイルでは、プロパティを使用してファイルを簡素化しています。
<project name="webservices-hello_world" default="all">
<!-- このビルドのグローバルなプロパティを設定 -->
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="weblogic" />
<property name="wls.hostname" value="localhost" />
<property name="wls.port" value="7001" />
<property name="wls.server.name" value="myserver" />
<property name="ear.deployed.name" value="helloWorldEar" />
<property name="example-output" value="output" />
<property name="ear-dir" value="${example-output}/helloWorldEar" />
<property name="clientclass-dir" value="${example-output}/clientclasses" />
<path id="client.class.path">
<pathelement path="${clientclass-dir}"/>
<pathelement path="${java.class.path}"/>
</path>
<taskdef name="jwsc"
classname="weblogic.wsee.tools.anttasks.JwscTask" />
<taskdef name="clientgen"
classname="weblogic.wsee.tools.anttasks.ClientGenTask" />
<taskdef name="wldeploy"
classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<target name="all" depends="clean,build-service,deploy,client" />
<target name="clean" depends="undeploy">
<delete dir="${example-output}"/>
</target>
<target name="build-service">
<jwsc
srcdir="src"
destdir="${ear-dir}">
<jws file="examples/webservices/hello_world/HelloWorldImpl.java" />
</jwsc>
</target>
<target name="deploy">
<wldeploy action="deploy" name="${ear.deployed.name}"
source="${ear-dir}" user="${wls.username}"
password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}" />
</target>
<target name="undeploy">
<wldeploy action="undeploy" name="${ear.deployed.name}"
failonerror="false"
user="${wls.username}" password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}" />
</target>
<target name="client">
<clientgen
wsdl="http://${wls.hostname}:${wls.port}/HelloWorldImpl/HelloWorldImpl?WSDL"
destDir="${clientclass-dir}"
packageName="examples.webservices.hello_world.client"/>
<javac
srcdir="${clientclass-dir}" destdir="${clientclass-dir}"
includes="**/*.java"/>
<javac
srcdir="src" destdir="${clientclass-dir}"
includes="examples/webservices/hello_world/client/**/*.java"/>
</target>
<target name="run">
<java classname="examples.webservices.hello_world.client.Main"
fork="true" failonerror="true" >
<classpath refid="client.class.path"/>
<arg
line="http://${wls.hostname}:${wls.port}/HelloWorldImpl/HelloWorldImpl" />
</java> </target>
</project>
前の使用例では、Web サービス オペレーションのパラメータと戻り値として、単純データ型 String
のみを使用していました。次の例では、ユーザ定義のデータ型 (特に BasicStruct
という JavaBean) をオペレーションのパラメータおよび戻り値として使用する Web サービスの作成方法を示します。
Web サービスでユーザ定義のデータ型を使用する場合、データ型の Java ソースを作成して、それを JWS ファイル内で適切に使用する以外に、プログラマが実際にすべきことはほとんどありません。jwsc
Ant タスクは、JWS ファイルにユーザ定義のデータ型がある場合、XML 表現 (SOAP メッセージで使用) と Java 表現 (WebLogic Server で使用) との間でデータを変換するのに必要な、すべてのデータ バインディング アーティファクトを自動的に生成します。データ バインディング アーティファクトには、Java ユーザ定義データ型に相当する XML スキーマ、JAX-RPC の型マッピング ファイルなどがあります。
以下の手順は、「簡単な HelloWorld Web サービスの作成」の手順とよく似ています。そのため、説明では必要な手順をすべて示してはいますが、簡単な HelloWorld サンプルと異なる手順についてのみ、詳細を述べています。
prompt> mkdir /myExamples/complex
src
ディレクトリと、JWS ファイル (この手順で後述) のパッケージ名に相当するサブディレクトリを作成します。prompt> cd /myExamples/complex
prompt> mkdir src/examples/webservices/complex
BasicStruct
JavaBean のソースを作成します。それには、任意の Java IDE またはテキスト エディタを開き、「サンプル BasicStruct JavaBean」で指定された Java コードを使用して、プロジェクト ディレクトリ内に BasicStruct.java
という Java ファイルを作成します。BasicStruct.java
ファイルをプロジェクト ディレクトリの src/examples/webservices/complex
サブディレクトリに保存します。
このサンプル JWS ファイルでは、前のサンプルよりも多くの JWS アノテーションを使用しています。@WebMethod
では、メソッドが Web サービス オペレーションとして公開されることを明示的に指定し、オペレーション名をデフォルトのメソッド名 echoStruct
から echoComplexType
に変更します。@WebParam
と @WebResult
では、パラメータと戻り値をコンフィグレーションします。@SOAPBinding
では、Web サービスのタイプを指定します。@WLHttpTransport
では、Web サービスの呼び出しに使用される URI を指定します。また、ComplexImpl.java
JWS ファイルでは examples.webservice.complex.BasicStruct
クラスをインポートして、echoStruct()
メソッドのパラメータと戻り値としてユーザ定義データ型の BasicStruct
を使用します。
JWS ファイルの作成に関するより詳細な情報については、「JWS ファイルのプログラミング」を参照してください。
ComplexImpl.java
ファイルをプロジェクト ディレクトリの src/examples/webservices/complex
サブディレクトリに保存します。build.xml
ファイルを作成し、taskdef
Ant タスクを追加して、jwsc
タスクの完全修飾クラス名を指定します。<project name="webservices-complex" default="all">
<taskdef name="jwsc"
classname="weblogic.wsee.tools.anttasks.JwscTask" />
</project>
完全なサンプル build.xml
ファイルについては、「ComplexImpl.java JWS ファイルのサンプル Ant ビルド ファイル」を参照してください。
jwsc
Ant タスクの呼び出しを、build-service
ターゲット内にラップして、build.xml
ファイルに追加します。<target name="build-service">
<jwsc
srcdir="src"
destdir="output/ComplexServiceEar" >
<jws file="examples/webservices/complex/ComplexImpl.java" />
</jwsc>
</target>
jwsc
Ant タスクを使用します。prompt> ant build-service
output/ComplexServiceEar
ディレクトリを見て、jwsc
Ant タスクによって生成されたファイルとアーティファクトを確認します。
wldeploy
Ant タスクを使用して、ComplexServiceEar
エンタープライズ アプリケーションにパッケージ化された Web サービスを WebLogic Server にデプロイします。 http://host
:port
/complex/ComplexService?WSDL
Web サービスを呼び出す JAX-RPC Java クライアント アプリケーションの作成例については、「スタンドアロンの JAX-RPC Java クライアントからの Web サービスの呼び出し」を参照してください。
package examples.webservices.complex;
/**
* integer、String、および String[] 型のプロパティを持つ、
* BasicStruct という簡単な JavaBean を定義する
*/
public class BasicStruct {
// プロパティ
private int intValue;
private String stringValue;
private String[] stringArray;
// ゲッターおよびセッター メソッド
public int getIntValue() {
return intValue;
}
public void setIntValue(int intValue) {
this.intValue = intValue;
}
public String getStringValue() {
return stringValue;
}
public void setStringValue(String stringValue) {
this.stringValue = stringValue;
}
public String[] getStringArray() {
return stringArray;
}
public void setStringArray(String[] stringArray) {
this.stringArray = stringArray;
}
public String toString() {
return "IntValue="+intValue+", StringValue="+stringValue;
}
}
package examples.webservices.complex;
// 標準の JWS アノテーション インタフェースをインポートする
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
// WebLogic 固有の JWS アノテーション インタフェースをインポートする
import weblogic.jws.WLHttpTransport;
// BasicStruct JavaBean をインポートする
import examples.webservices.complex.BasicStruct;
// Web サービスの portType 名を「ComplexPortType」、パブリック サービス名を「ComplexService」、
// 生成される WSDL で使用される targetNamespace を「http://example.org」と指定する、
// 標準の JWS アノテーション
@WebService(serviceName="ComplexService", name="ComplexPortType",
targetNamespace="http://example.org")
// document-literal-wrapped 型の Web サービスであることを指定する
// 標準の JWS アノテーション
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,
use=SOAPBinding.Use.LITERAL,
parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
// Web サービスの URI を構成するのに使用されるコンテキスト パスとサービス URI が
// 「complex/ComplexService」であることを指定する、WebLogic 固有の JWS アノテーション
@WLHttpTransport(contextPath="complex", serviceUri="ComplexService",
portName="ComplexServicePort")
/**
* WebLogic Web サービスの基本となる JWS ファイル。この Web サービスには、
* 以下の 2 つのパブリック オペレーションがある
*
* - echoInt(int)
* - echoComplexType(BasicStruct)
*
* この Web サービスは「document-literal」サービスとして定義される。
* つまり、SOAP メッセージには、本文全体を定義する XML スキーマ要素
* を参照している 1 つの部分がある
*
* @author Copyright (c) 2005 by BEA Systems. All Rights Reserved.
*/
public class ComplexImpl {
// メソッドがパブリック オペレーションとして公開されることを指定する、
// 標準の JWS アノテーション。アノテーションにはメンバー値の
// 「operationName」が含まれていないので、オペレーションの名前は
// メソッド名 echoInt と同じになる
//
// WebResult アノテーションは、生成される WSDL 内のオペレーションの
// 結果の名前が、デフォルト名の「return」ではなく「IntegerOutput」
// であることを指定する。 WebParam アノテーションは、WSDL ファイル内の
// 入力パラメータ名が、パラメータの Java 名「input」ではなく、
// 「IntegerInput」であることを指定する
@WebMethod()
@WebResult(name="IntegerOutput",
targetNamespace="http://example.org/complex")
public int echoInt(
@WebParam(name="IntegerInput",
targetNamespace="http://example.org/complex")
int input)
{
System.out.println("echoInt '" + input + "' to you too!");
return input;
}
// メソッド「echoStruct」を「echoComplexType」というパブリック オペレーション
// として公開するための、標準の JWS アノテーション。
// WebResult アノテーションは、生成される WSDL 内のオペレーションの結果の名前が、
// デフォルト名の「return」ではなく、「EchoStructReturnMessage」であることを
// 指定する
@WebMethod(operationName="echoComplexType")
@WebResult(name="EchoStructReturnMessage",
targetNamespace="http://example.org/complex")
public BasicStruct echoStruct(BasicStruct struct)
{
System.out.println("echoComplexType called");
return struct;
}
}
以下の build.xml
ファイルでは、プロパティを使用してファイルを簡素化しています。
<project name="webservices-complex" default="all">
<!-- このビルドのグローバルなプロパティを設定 -->
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="weblogic" />
<property name="wls.hostname" value="localhost" />
<property name="wls.port" value="7001" />
<property name="wls.server.name" value="myserver" />
<property name="ear.deployed.name" value="complexServiceEAR" />
<property name="example-output" value="output" />
<property name="ear-dir" value="${example-output}/complexServiceEar" />
<property name="clientclass-dir" value="${example-output}/clientclass" />
<path id="client.class.path">
<pathelement path="${clientclass-dir}"/>
<pathelement path="${java.class.path}"/>
</path>
<taskdef name="jwsc"
classname="weblogic.wsee.tools.anttasks.JwscTask" />
<taskdef name="clientgen"
classname="weblogic.wsee.tools.anttasks.ClientGenTask" />
<taskdef name="wldeploy"
classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<target name="all" depends="clean,build-service,deploy,client"/>
<target name="clean" depends="undeploy">
<delete dir="${example-output}"/>
</target>
<target name="build-service">
<jwsc
srcdir="src"
destdir="${ear-dir}"
keepGenerated="true"
>
<jws file="examples/webservices/complex/ComplexImpl.java" />
</jwsc>
</target>
<target name="deploy">
<wldeploy action="deploy"
name="${ear.deployed.name}"
source="${ear-dir}" user="${wls.username}"
password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}"/>
</target>
<target name="undeploy">
<wldeploy action="undeploy" failonerror="false"
name="${ear.deployed.name}"
user="${wls.username}" password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}"/>
</target>
<target name="client">
<clientgen
wsdl="http://${wls.hostname}:${wls.port}/complex/ComplexService?WSDL"
destDir="${clientclass-dir}"
packageName="examples.webservices.complex.client"/>
<javac
srcdir="${clientclass-dir}" destdir="${clientclass-dir}"
includes="**/*.java"/>
<javac
srcdir="src" destdir="${clientclass-dir}"
includes="examples/webservices/complex/client/**/*.java"/>
</target>
<target name="run" >
<java fork="true"
classname="examples.webservices.complex.client.Main"
failonerror="true" >
<classpath refid="client.class.path"/>
<arg line="http://${wls.hostname}:${wls.port}/complex/ComplexService"
/>
</java>
</target>
</project>
Web サービスの作成に関するもう 1 つの一般的な使用例は、既存の WSDL ファイル (黄金の WSDL とも呼ばれる) から開始することです。WSDL ファイルは Web サービスがどのようなものかを指定するパブリック規約であり、サポートされるオペレーションのリスト、各オペレーションのシグネチャと形式、オペレーションを呼び出すときに使用されるプロトコルと転送、ネットワーク上でデータを転送するときに使用される XML スキーマ データ型などを指定します。WSDL ファイルに基づいて、WebLogic Server にデプロイできるように、Web サービスを実装するアーティファクトを生成します。以下のようなアーティファクトがあります。
wsdlc
Ant タスクを使用してこれらのアーティファクトを生成します。一般に、この Ant タスクを 1 回実行して、生成される JWS インタフェース ファイルとデータ バインディング アーティファクトを含む JAR ファイルを生成し、その後で、インタフェースを実装している生成された JWS ファイルをコーディングして、Web サービスのビジネス ロジックを追加します。特に、Web サービス オペレーションを実装するメソッドに、オペレーションの動作に必要な Java コードを追加し、JWS アノテーションを追加します。
警告 : | wsdlc Ant タスクによって生成されるファイルのうち、ユーザが更新するのは JWS 実装ファイルのみです。JWS インタフェースやデータ バインディング アーティファクトを含む JAR ファイルを更新する必要はありません。 |
JWS 実装ファイルをコーディングしたら、前述の節で示された同じ手順に従って、jwsc
Ant タスクを実行してデプロイ可能な Web サービスを生成します。相違点は、compiledWsdl
属性を使用して、wsdlc
Ant タスクによって生成される JAR ファイル (JWS インタフェース ファイルとデータ バインディング アーティファクトを含む) を指定することだけです。
以下の簡単な例では、「サンプル WSDL ファイル」に示す WSDL ファイルから Web サービスを作成する方法を示しています。この Web サービスには、郵便番号を渡されると気温を返す getTemp
オペレーションが 1 つあります。
bin
サブディレクトリにある setDomainEnv.cmd
(Windows) または setDomainEnv.sh
(UNIX) スクリプトを実行して、WebLogic Server 環境を設定します。WebLogic Server ドメインのデフォルトの場所は、BEA_HOME
/user_projects/domains/
domainName
です。BEA_HOME
は BEA Products の最上位のインストール ディレクトリ、domainName
はドメインの名前です。prompt> mkdir /myExamples/wsdlc
TemperatureService.wsdl
という名前で /myExamples/wsdlc/wsdl_files
ディレクトリにあると仮定しています。ファイルの完全なリストについては、「サンプル WSDL ファイル」を参照してください。build.xml
ファイルを作成し、taskdef
Ant タスクを追加して、wsdlc
タスクの完全修飾クラス名を指定します。<project name="webservices-wsdlc" default="all">
<taskdef name="wsdlc"
classname="weblogic.wsee.tools.anttasks.WsdlcTask"/>
</project>
この手順で説明される追加のターゲット (clean
、undeploy
、client
、run
など) が含まれている、完全なサンプル build.xml
ファイルについては、「TemperatureService のサンプル Ant ビルド ファイル」を参照してください。完全な build.xml
ファイルでは、EAR ディレクトリの名前を常にハードコード化して使用するのではなく、${ear-dir}
などのプロパティも使用しています。
wsdlc
Ant タスクの呼び出しを、generate-from-wsdl
ターゲット内にラップして、build.xml
ファイルに追加します。<target name="generate-from-wsdl">
<wsdlc
srcWsdl="wsdl_files/TemperatureService.wsdl"
destJwsDir="output/compiledWsdl"
destImplDir="output/impl"
packageName="examples.webservices.wsdlc" />
</target>
このサンプルの wsdlc
タスクでは、JWS インタフェースとデータ バインディング アーティファクトを含む JAR ファイルを、現在のディレクトリの下の output/compiledWsdl
ディレクトリに生成します。また、JWS インタフェースの部分的な実装ファイル (TemperaturePortTypeImpl.java
) を output/impl/examples/webservices/wsdlc
ディレクトリに生成します (このディレクトリは、destImplDir
で指定された output ディレクトリと、パッケージ名で指定されたディレクトリ階層を組み合わせたものです)。生成されたすべての JWS ファイルは examples.webservices.wsdlc
パッケージにパッケージ化されます。
generate-from-wsdl
ターゲットを指定して、wsdlc
Ant タスクを実行します。prompt> ant generate-from-wsdl
wsdlc
Ant タスクによってアーティファクトとファイルが生成されたことを調べるには、output
ディレクトリを確認します。
output/impl/examples/webservices/wsdlc/TemperaturePortTypeImpl.java
JWS 実装ファイルを更新し、必要な処理を行うようにメソッドに Java コードを追加します。例については「サンプル TemperaturePortType Java 実装ファイル」を参照してください。追加された Java コードが太字になっています。生成された JWS 実装ファイルには @WebService
および @WLHttpTransport
アノテーションの値が自動的に含まれており、その値は元の WSDL ファイルの値に対応しています。 警告 : | 「WSDL から開始する」使用例の JWS 実装ファイルに追加できる JWS アノテーションには制限があります。詳細については、「wsdlc」を参照してください。 |
簡単にするために、サンプルの TemperaturePortTypeImpl.java
にある getTemp()
メソッドは、ハードコード化された数字を返します。実際のファイルの場合、このメソッドの実装では、特定の郵便番号で現在の気温を検索します。
TemperaturePortTypeImpl.java
ファイルを永続的なディレクトリ (プロジェクト ディレクトリの下の src
ディレクトリなど。パッケージ名に対応する子ディレクトリも作成します) にコピーします。prompt> cd /examples/wsdlc
prompt> mkdir src/examples/webservices/wsdlc
prompt> cpoutput/impl/examples/webservices/wsdlc/TemperaturePortTypeImpl.java
\
src/examples/webservices/wsdlc/TemperaturePortTypeImpl.java
jwsc
Ant タスクを実行する build-service
ターゲットを、build.xml
ファイルに追加します。jwsc
の compiledWsdl
属性を使用して、wsdlc
Ant タスクによって生成される JAR ファイルの名前を指定します。<taskdef name="jwsc"
classname="weblogic.wsee.tools.anttasks.JwscTask" />
<target name="build-service">
<jwsc
srcdir="src"
destdir="${ear-dir}">
<jws
file="examples/webservices/wsdlc/TemperaturePortTypeImpl.java"
compiledWsdl="output/compiledWsdl/TemperatureService_wsdl.jar"
/>
</jwsc>
</target>
build-service
ターゲットを実行してデプロイ可能な Web サービスを生成します。prompt> ant build-service
JWS ファイルを少しずつ更新する場合は、このターゲットを繰り返し実行できます。
wldeploy
Ant タスクを使用して、エンタープライズ アプリケーションにパッケージ化された Web サービスを WebLogic Server にデプロイします。いずれの場合でも、output
ディレクトリにある wsdlcEar
エンタープライズ アプリケーションをデプロイします。
wldeploy
Ant タスクを使用するには、以下のターゲットを build.xml
ファイルに追加します。
<taskdef name="wldeploy"
classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<target name="deploy">
<wldeploy action="deploy" name="wsdlcEar"
source="output/wsdlcEar" user="${wls.username}"
password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}" />
</target>
wls.username
、wls.password
、wls.hostname
、wls.port
、および wls.server.name
の値は、ご使用の WebLogic Server インスタンスの対応する値で置き換えます。
deploy
ターゲットを実行して、WAR ファイルをデプロイします。
prompt> ant deploy
http://host
:port
/temp/TemperatureService?WSDL
上記の URL のコンテキスト パスとサービス URI の部分は元の黄金の WSDL で指定されています。WebLogic Server インスタンスのホスト名とポートを使用します。デプロイされた WSDL ファイルと元の WSDL ファイルは、エンドポイント アドレスのホストとポート以外は同じであることに注目してください。
Web サービスを呼び出す JAX-RPC Java クライアント アプリケーションの作成例については、「スタンドアロンの JAX-RPC Java クライアントからの Web サービスの呼び出し」を参照してください。
build.xml
ファイルで clean
、build-service
、undeploy
、および deploy
ターゲットを使用すると、開発プロセスの一環として Web サービスを繰り返し更新、再ビルド、アンデプロイ、および再デプロイできます。
<?xml version="1.0"?>
<definitions
name="TemperatureService"
targetNamespace="http://www.bea.com/wls90"
xmlns:tns="http://www.bea.com/wls90"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/" >
<message name="getTempRequest">
<part name="zip" type="xsd:string"/>
</message>
<message name="getTempResponse">
<part name="return" type="xsd:float"/>
</message>
<portType name="TemperaturePortType">
<operation name="getTemp">
<input message="tns:getTempRequest"/>
<output message="tns:getTempResponse"/>
</operation>
</portType>
<binding name="TemperatureBinding" type="tns:TemperaturePortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getTemp">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"
namespace="http://www.bea.com/wls90" />
</input>
<output>
<soap:body use="literal"
namespace="http://www.bea.com/wls90" />
</output>
</operation>
</binding>
<service name="TemperatureService">
<documentation>
Returns current temperature in a given U.S. zipcode
</documentation>
<port name="TemperaturePort" binding="tns:TemperatureBinding">
<soap:address
location="http://localhost:7001/temp/TemperatureService"/>
</port>
</service>
</definitions>
package examples.webservices.wsdlc;
import javax.jws.WebService;
import weblogic.jws.*;
/**
* TemperaturePortTypeImpl クラスは、Web サービスのエンドポイント インタフェース TemperaturePortType を実装する */
@WebService(
serviceName="TemperatureService",
endpointInterface="examples.webservices.wsdlc.TemperaturePortType")
@WLHttpTransport(
contextPath="temp",
serviceUri="TemperatureService",
portName="TemperaturePort")
public class TemperaturePortTypeImpl implements TemperaturePortType {
public TemperaturePortTypeImpl() {
}
public float getTemp(java.lang.String zip)
{
return 1.234f;
}
}
以下の build.xml
ファイルでは、プロパティを使用してファイルを簡素化しています。
<project default="all">
<!-- このビルドのグローバルなプロパティを設定 -->
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="weblogic" />
<property name="wls.hostname" value="localhost" />
<property name="wls.port" value="7001" />
<property name="wls.server.name" value="myserver" />
<property name="ear.deployed.name" value="wsdlcEar" />
<property name="example-output" value="output" />
<property name="compiledWsdl-dir" value="${example-output}/compiledWsdl" />
<property name="impl-dir" value="${example-output}/impl" />
<property name="ear-dir" value="${example-output}/wsdlcEar" />
<property name="clientclass-dir" value="${example-output}/clientclasses" />
<path id="client.class.path">
<pathelement path="${clientclass-dir}"/>
<pathelement path="${java.class.path}"/>
</path>
<taskdef name="wsdlc"
classname="weblogic.wsee.tools.anttasks.WsdlcTask"/>
<taskdef name="jwsc"
classname="weblogic.wsee.tools.anttasks.JwscTask" />
<taskdef name="clientgen"
classname="weblogic.wsee.tools.anttasks.ClientGenTask" />
<taskdef name="wldeploy"
classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<target name="all"
depends="clean,generate-from-wsdl,build-service,deploy,client" />
<target name="clean" depends="undeploy">
<delete dir="${example-output}"/>
</target>
<target name="generate-from-wsdl">
<wsdlc
srcWsdl="wsdl_files/TemperatureService.wsdl"
destJwsDir="${compiledWsdl-dir}"
destImplDir="${impl-dir}"
packageName="examples.webservices.wsdlc" />
</target>
<target name="build-service">
<jwsc
srcdir="src"
destdir="${ear-dir}">
<jws file="examples/webservices/wsdlc/TemperaturePortTypeImpl.java"
compiledWsdl="${compiledWsdl-dir}/TemperatureService_wsdl.jar" />
</jwsc>
</target>
<target name="deploy">
<wldeploy action="deploy" name="${ear.deployed.name}"
source="${ear-dir}" user="${wls.username}"
password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}" />
</target>
<target name="undeploy">
<wldeploy action="undeploy" name="${ear.deployed.name}"
failonerror="false"
user="${wls.username}" password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}" />
</target>
<target name="client">
<clientgen
wsdl="http://${wls.hostname}:${wls.port}/temp/TemperatureService?WSDL"
destDir="${clientclass-dir}"
packageName="examples.webservices.wsdlc.client"/>
<javac
srcdir="${clientclass-dir}" destdir="${clientclass-dir}"
includes="**/*.java"/>
<javac
srcdir="src" destdir="${clientclass-dir}"
includes="examples/webservices/wsdlc/client/**/*.java"/>
</target>
<target name="run">
<java classname="examples.webservices.wsdlc.client.TemperatureClient"
fork="true" failonerror="true" >
<classpath refid="client.class.path"/>
<arg
line="http://${wls.hostname}:${wls.port}/temp/TemperatureService" />
</java>
</target>
</project>
クライアント アプリケーションからデプロイ済みの Web サービスのオペレーションを呼び出す場合、Web サービスは WebLogic Server にデプロイされている場合と、.NET などの他のアプリケーション サーバにデプロイされている場合があります。知る必要があるのは、パブリック規約ファイル、つまり WSDL の URL のみです。
Java クライアント アプリケーションを記述するほかに、clientgen
WebLogic Web サービス Ant タスクを実行して、クライアント アプリケーションが Web サービス オペレーションを呼び出すために必要なアーティファクトも生成する必要があります。以下のようなアーティファクトがあります。
以下の例では、「ユーザ定義のデータ型を使用する Web サービスの作成」で説明された ComplexService
WebLogic Web サービスの echoComplexType
オペレーションを呼び出す Java クライアント アプリケーションを作成する方法について説明します。echoComplexType
オペレーションは、パラメータおよび戻り値の型として BasicStruct
ユーザ定義データ型を取ります。この手順では、ComplexService
Web サービスをすでに作成してデプロイ済みであると仮定しています。
bin
サブディレクトリにある setDomainEnv.cmd
(Windows) または setDomainEnv.sh
(UNIX) スクリプトを実行して、WebLogic Server 環境を設定します。WebLogic Server ドメインのデフォルトの場所は、BEA_HOME
/user_projects/domains/
domainName
です。BEA_HOME
は BEA Products の最上位のインストール ディレクトリ、domainName
はドメインの名前です。prompt> mkdir /myExamples/simple_client
src
ディレクトリと、Java クライアント アプリケーション ファイル (この手順で後述) のパッケージ名に相当するサブディレクトリを作成します。prompt> cd /myExamples/simple_client
prompt> mkdir src/examples/webservices/simple_client
build.xml
ファイルを作成し、taskdef
Ant タスクを追加して、clientgen
タスクの完全修飾クラス名を指定します。<project name="webservices-simple_client" default="all">
<taskdef name="clientgen"
classname="weblogic.wsee.tools.anttasks.ClientGenTask" />
</project>
完全なサンプル build.xml
ファイルについては、「スタンドアロンのクライアント アプリケーションをビルドするためのサンプル Ant ビルド ファイル」を参照してください。完全な build.xml
ファイルでは、クライアント クラスの出力ディレクトリの名前を常にハードコード化して使用するのではなく、${clientclass-dir}
などのプロパティを使用しています。
clientgen
および javac
Ant タスクの呼び出しを、build-client
ターゲット内にラップして、build.xml
ファイルに追加します。<target name="build-client">
<clientgen
wsdl="http://${wls.hostname}:${wls.port}/complex/ComplexService?WSDL"
destDir="output/clientclass"
packageName="examples.webservices.simple_client"/>
<javac
srcdir="output/clientclass" destdir="output/clientclass"
includes="**/*.java"/>
<javac
srcdir="src" destdir="output/clientclass"
includes="examples/webservices/simple_client/*.java"/>
</target>
clientgen
Ant タスクでは、デプロイされた ComplexService
Web サービスの WSDL を使用して必要なアーティファクトを生成し、指定されたパッケージ名を使用してそれらを output/clientclass
ディレクトリに格納します。Web サービスをホストしている WebLogic Server インスタンスの実際のホスト名とポートで、変数を置き換えてください。
clientgen
Ant タスクは examples.webservices.complex.BasicStruct
JavaBean クラスも自動的に生成します。このクラスは、WSDL で指定されたユーザ定義のデータ型の Java 表現です。
build-client
ターゲットでは、clientgen
の他に標準の javac
Ant タスクも指定して、次の手順で説明するスタンドアロンの Java プログラムを含む、すべての Java コードをクラス ファイルにコンパイルします。
clientgen
Ant タスクの destFile
属性を使用すると、生成された Java ファイルを自動的にコンパイルして、すべてのアーティファクトを JAR ファイルにパッケージ化できます。コンパイルの詳細については、「clientgen」を参照してください。
echoComplexType
オペレーションを呼び出す Java クライアント アプリケーション ファイルを作成します。それには、任意の Java IDE またはテキスト エディタを開いて、「サンプル Java クライアント アプリケーション」で指定されたコードを使用して Main.java
という Java ファイルを作成します。
Main
クライアント アプリケーションは、1 つの引数 (Web サービスの WSDL URL) を取ります。アプリケーションは標準 JAX-RPC のガイドラインに従って、clientgen
によって生成された Service
インタフェースの WebLogic Server 固有の実装を使用して Web サービスのオペレーションを呼び出します。また、アプリケーションは、clientgen
Ant タスクで生成された BasicStruct
ユーザ定義データ型をインポートして使用します。このデータ型は echoStruct
オペレーションのパラメータおよび戻り値として使用されます。詳細については、「Web サービスの呼び出し」を参照してください。
Main.java
ファイルをメイン プロジェクト ディレクトリの src/examples/webservices/simple_client
サブディレクトリに保存します。build-client
ターゲットを指定して、clientgen
および javac
Ant タスクを実行します。prompt> ant build-client
output/clientclass
ディレクトリを見て、clientgen
Ant タスクによって生成されたファイルとアーティファクトを確認します。
Main
アプリケーションの実行に使用される以下のターゲットを build.xml
ファイルに追加します。<path id="client.class.path">
<pathelement path="output/clientclass"/>
<pathelement path="${java.class.path}"/>
</path>
<target name="run" >
<java fork="true"
classname="examples.webservices.simple_client.Main"
failonerror="true" >
<classpath refid="client.class.path"/>
<arg
line="http://${wls.hostname}:${wls.port}/complex/ComplexService"
/>
</java>
</target>
run
ターゲットは Main
アプリケーションを呼び出し、デプロイされた Web サービスの WSDL URL を 1 つの引数として渡します。classpath
要素では、<path>
タスクで作成される参照を使用して、CLASSPATH に clientclass
ディレクトリが追加されます。
run
ターゲットを実行して echoComplexType
オペレーションを呼び出します。prompt> ant run
run:
[java] echoComplexType called. Result: 999, Hello Struct
build.xml
ファイルの build-client
および run
ターゲットを使用して、開発プロセスの一環として Java クライアント アプリケーションを繰り返し更新、再ビルド、および実行できます。
package examples.webservices.simple_client;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
// echoComplexType オペレーションのパラメータおよび戻り値として使用される
// BasicStruct クラスをインポートする。// このクラスは clientgen Ant タスクによって自動的に生成される
import examples.webservices.complex.BasicStruct;
/**
* ComplexService Web サービスの echoComplexType オペレーションを呼び出す
* 簡単なスタンドアロンのクライアント アプリケーション
*
* @author Copyright (c) 2005 by BEA Systems. All Rights Reserved.
*/
public class Main {
public static void main(String[] args)
throws ServiceException, RemoteException{
ComplexService service = new ComplexService_Impl (args[0] + "?WSDL" );
ComplexPortType port = service.getComplexServicePort();
BasicStruct in = new BasicStruct();
in.setIntValue(999);
in.setStringValue("Hello Struct");
BasicStruct result = port.echoComplexType(in);
System.out.println("echoComplexType called. Result: " + result.getIntValue() + ", " + result.getStringValue());
}
}
以下の build.xml
ファイルでは、プロパティを使用してファイルを簡素化しています。
<project name="webservices-simple_client" default="all">
<!-- このビルドのグローバルなプロパティを設定 -->
<property name="wls.hostname" value="localhost" />
<property name="wls.port" value="7001" />
<property name="example-output" value="output" />
<property name="clientclass-dir" value="${example-output}/clientclass" />
<path id="client.class.path">
<pathelement path="${clientclass-dir}"/>
<pathelement path="${java.class.path}"/>
</path>
<taskdef name="clientgen"
classname="weblogic.wsee.tools.anttasks.ClientGenTask" />
<target name="clean" >
<delete dir="${clientclass-dir}"/>
</target>
<target name="all" depends="clean,build-client,run" />
<target name="build-client">
<clientgen
wsdl="http://${wls.hostname}:${wls.port}/complex/ComplexService?WSDL"
destDir="${clientclass-dir}"
packageName="examples.webservices.simple_client"/>
<javac
srcdir="${clientclass-dir}" destdir="${clientclass-dir}"
includes="**/*.java"/>
<javac
srcdir="src" destdir="${clientclass-dir}"
includes="examples/webservices/simple_client/*.java"/>
</target>
<target name="run" >
<java fork="true"
classname="examples.webservices.simple_client.Main"
failonerror="true" >
<classpath refid="client.class.path"/>
<arg line="http://${wls.hostname}:${wls.port}/complex/ComplexService"
/>
</java>
</target>
</project>
スタンドアロン クライアントからではなく、デプロイ済みの WebLogic Web サービス内から Web サービス (WebLogic、.NET など) を呼び出すこともできます。
その手順は、「スタンドアロンの JAX-RPC Java クライアントからの Web サービスの呼び出し」で説明した手順と似ています。ただしこの場合は、clientgen
Ant タスクを実行してクライアント スタブを生成するのではなく、jwsc
Ant タスク内で <jws>
の子要素 <clientgen>
を使用します。jwsc
Ant タスクでは、生成されたクライアント スタブが自動的に呼び出し側の Web サービスの WAR ファイルにパッケージ化されるため、即座に Web サービスからアクセスできるようになります。その後で、標準 JAX-RPC のプログラミング ガイドラインに従って、他の Web サービスを呼び出す Web サービスを実装する JWS ファイルを作成します。
以下の例では、「ユーザ定義のデータ型を使用する Web サービスの作成」で説明した ComplexService
Web サービスの echoComplexType
オペレーションを呼び出す JWS ファイルを記述する方法を示します。ComplexService
Web サービスを正常にデプロイ済みであると仮定しています。
bin
サブディレクトリにある setDomainEnv.cmd
(Windows) または setDomainEnv.sh
(UNIX) スクリプトを実行して、WebLogic Server 環境を設定します。WebLogic Server ドメインのデフォルトの場所は、BEA_HOME
/user_projects/domains/
domainName
です。BEA_HOME
は BEA Products の最上位のインストール ディレクトリ、domainName
はドメインの名前です。prompt> mkdir /myExamples/service_to_service
src
ディレクトリと、JWS およびクライアントアプリケーション ファイル (この手順で後述) のパッケージ名に相当するサブディレクトリを作成します。prompt> cd /myExamples/service_to_service
prompt> mkdir src/examples/webservices/service_to_service
ComplexService
Web サービスを呼び出す Web サービスを実装する JWS ファイルを作成します。任意の Java IDE またはテキスト エディタを開いて、「サンプル ClientServiceImpl.java JWS ファイル」で指定された Java コードを使用して ClientServiceImpl.java
という Java ファイルを作成します。
サンプル JWS ファイルでは、1 つのパブリック メソッド callComplexService()
を含む ClientServiceImpl
という Java クラスが示されています。この Java クラスでは、後で jwsc
Ant タスクで生成される JAX-RPC スタブと、BasicStruct
JavaBean (同じく clientgen
で生成される) をインポートします。この JavaBean は、ComplexService
Web サービスの echoComplexType
オペレーションのパラメータと戻り値のデータ型です。
ClientServiceImpl
Java クラスでは 1 つのメソッド callComplexService()
を定義しています。このメソッドは、ComplexService
Web サービスの echoComplexType
オペレーションに渡される BasicStruct
と、ComplexService
Web サービスの URL という 2 つのパラメータを取ります。メソッドは標準の JAX-RPC API を使用し、jwsc
によって生成されたスタブを使用して、ComplexService
の Service
と PortType
を取得します。その後で、echoComplexType
オペレーションを呼び出します。
ClientServiceImpl.java
ファイルを src/examples/webservices/service_to_service
ディレクトリに保存します。build.xml
ファイルを作成して、次のタスクを追加します。<project name="webservices-service_to_service" default="all">
<taskdef name="jwsc"
classname="weblogic.wsee.tools.anttasks.JwscTask" />
</project>
taskdef
タスクでは、jwsc
Ant タスクの完全なクラス名を定義しています。
この手順で説明される追加のターゲット (clean
、deploy
、undeploy
、client
、run
など) が含まれている、完全なサンプル build.xml
ファイルについては、「ClientService をビルドするためのサンプル Ant ビルド ファイル」を参照してください。完全な build.xml
ファイルでは、EAR ディレクトリの名前を常にハードコード化して使用するのではなく、${ear-dir}
などのプロパティも使用しています。
jwsc
Ant タスクの呼び出しを、build-service
ターゲット内にラップして、build.xml
ファイルに追加します。<target name="build-service">
<jwsc
srcdir="src"
destdir="output/ClientServiceEar" >
<jws
file="examples/webservices/service_to_service/ClientServiceImpl.java">
<clientgen
wsdl="http://${wls.hostname}:${wls.port}/complex/ComplexService?WSDL"
packageName="examples.webservices.service_to_service" />
</jws>
</jwsc>
</target>
この例では、jwsc
Ant タスクの <jws>
要素の <clientgen>
子要素で、jwsc
が JWS ファイルをコンパイルするだけでなく、WSDL ファイルに記述されている Web サービスを呼び出すために必要なクライアント アーティファクトも生成およびコンパイルすることを指定しています。
build-service
ターゲットを指定して、jwsc
Ant タスクを実行します。prompt> ant build-service
wldeploy
Ant タスクを使用して、エンタープライズ アプリケーションにパッケージ化された Web サービスを WebLogic Server にデプロイします。いずれの場合でも、output
ディレクトリにある ClientServiceEar
エンタープライズ アプリケーションをデプロイします。
wldeploy
Ant タスクを使用するには、以下のターゲットを build.xml
ファイルに追加します。
<taskdef name="wldeploy"
classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<target name="deploy">
<wldeploy action="deploy" name="ClientServiceEar"
source="ClientServiceEar" user="${wls.username}"
password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}" />
</target>
wls.username
、wls.password
、wls.hostname
、wls.port
、および wls.server.name
の値は、ご使用の WebLogic Server インスタンスの対応する値で置き換えます。
deploy
ターゲットを実行して、WAR ファイルをデプロイします。
prompt> ant deploy
http://host
:port
/ClientService/ClientService?WSDL
Web サービスを呼び出す JAX-RPC Java クライアント アプリケーションの作成例については、「スタンドアロンの JAX-RPC Java クライアントからの Web サービスの呼び出し」を参照してください。
package examples.webservices.service_to_service;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import javax.jws.WebService;
import javax.jws.WebMethod;
import weblogic.jws.WLHttpTransport;
// clientgen によって生成され、ComplexService Web サービスによって使用される
// BasicStruct データ型をインポートする
import examples.webservices.complex.BasicStruct;
// ComplexService Web サービスを呼び出すための JAX-RPC スタブをインポートする。
// clientgen によって生成されるスタブ
import examples.webservices.service_to_service.ComplexPortType;
import examples.webservices.service_to_service.ComplexService_Impl;
import examples.webservices.service_to_service.ComplexService;
@WebService(name="ClientPortType", serviceName="ClientService",
targetNamespace="http://examples.org")
@WLHttpTransport(contextPath="ClientService", serviceUri="ClientService",
portName="ClientServicePort")
public class ClientServiceImpl {
@WebMethod()
public String callComplexService(BasicStruct input, String serviceUrl)
throws ServiceException, RemoteException
{
// ComplexService を呼び出すために service および port スタブを作成する
ComplexService service = new ComplexService_Impl(serviceUrl + "?WSDL");
ComplexPortType port = service.getComplexServicePort();
// ComplexService の echoComplexType オペレーションを呼び出す
BasicStruct result = port.echoComplexType(input);
System.out.println("Invoked ComplexPortType.echoComplexType." );
return "Invoke went okay! Here's the result: '" + result.getIntValue() + ", " + result.getStringValue() + "'";
}
}
以下の build.xml
ファイルでは、プロパティを使用してファイルを簡素化しています。
<project name="webservices-service_to_service" default="all">
<!-- このビルドのグローバルなプロパティを設定 -->
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="weblogic" />
<property name="wls.hostname" value="localhost" />
<property name="wls.port" value="7001" />
<property name="wls.server.name" value="myserver" />
<property name="ear.deployed.name" value="ClientServiceEar" />
<property name="example-output" value="output" />
<property name="ear-dir" value="${example-output}/ClientServiceEar" />
<property name="clientclass-dir" value="${example-output}/clientclasses" />
<path id="client.class.path">
<pathelement path="${clientclass-dir}"/>
<pathelement path="${java.class.path}"/>
</path>
<taskdef name="jwsc"
classname="weblogic.wsee.tools.anttasks.JwscTask" />
<taskdef name="clientgen"
classname="weblogic.wsee.tools.anttasks.ClientGenTask" />
<taskdef name="wldeploy"
classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<target name="all" depends="clean,build-service,deploy,client"/>
<target name="clean" depends="undeploy">
<delete dir="${example-output}"/>
</target>
<target name="build-service">
<jwsc
srcdir="src"
destdir="${ear-dir}">
<jws
file="examples/webservices/service_to_service/ClientServiceImpl.java">
<clientgen
wsdl="http://${wls.hostname}:${wls.port}/complex/ComplexService?WSDL"
packageName="examples.webservices.service_to_service" />
</jws>
</jwsc>
</target>
<target name="deploy">
<wldeploy action="deploy" name="${ear.deployed.name}"
source="${ear-dir}" user="${wls.username}"
password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}" />
</target>
<target name="undeploy">
<wldeploy action="undeploy" name="${ear.deployed.name}"
failonerror="false"
user="${wls.username}"
password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}" />
</target>
<target name="client">
<clientgen
wsdl="http://${wls.hostname}:${wls.port}/ClientService/ClientService?WSDL"
destDir="${clientclass-dir}"
packageName="examples.webservices.service_to_service.client"/>
<javac
srcdir="${clientclass-dir}" destdir="${clientclass-dir}"
includes="**/*.java"/>
<javac
srcdir="src" destdir="${clientclass-dir}"
includes="examples/webservices/service_to_service/client/**/*.java"/>
</target>
<target name="run">
<java classname="examples.webservices.service_to_service.client.Main"
fork="true"
failonerror="true" >
<classpath refid="client.class.path"/>
<arg
line="http://${wls.hostname}:${wls.port}/ClientService/ClientService"/>
</java>
</target>
</project>
![]() ![]() ![]() |