ここでは,WSDL変換用に仮実装のWebサービス実装クラスと例外クラスを作成し,cjwsgenコマンドのWSDL生成機能を実行して,コンパイル済みのJavaソースからWSDLファイルを作成します。作成したクラスは,javax.jws.WebServiceアノテーションでアノテートします。SOAP 1.2を使用する場合,さらにSOAP 1.2を指定したjavax.xml.ws.BindingTypeアノテーションでアノテートしてください。メソッドを実装する必要はありません。
SOAP 1.1を使用する場合とSOAP 1.2を使用する場合では,仮実装のWebサービス実装クラスとTestJaxWsService.wsdlでソースコードが異なります。
SOAP 1.1の場合の仮実装のWebサービス実装クラスの例を次に示します。
package com.example.sample;
@javax.jws.WebService
public class TestJaxWsImpl {
public String jaxWsTest1(String information, int count)
throws UserDefinedException
{
// 実装不要
return null;
}
} |
SOAP 1.2の場合の仮実装のWebサービス実装クラスの例を次に示します。
package com.example.sample;
@javax.jws.WebService
@javax.xml.ws.BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class TestJaxWsImpl {
public String jaxWsTest1(String information, int count)
throws UserDefinedException
{
// 実装不要
return null;
}
} |
仮実装の例外クラスの例を次に示します。
package com.example.sample;
public class UserDefinedFault extends Exception{
// 実装不要
public int additionalInfo;
public String detail;
public String message;
} |
作成したTestJaxWsImpl.javaとUserDefinedFault.javaをUTF-8形式でc:¥temp¥jaxws¥works¥wsrm¥server¥temporary¥src¥com¥example¥sample¥ディレクトリに保存し,コンパイルします。コンパイルの例を次に示します。
> cd c:¥temp¥jaxws¥works¥wsrm¥server¥
> mkdir .¥temporary
> mkdir .¥temporary¥classes
> javac -encoding UTF-8 -cp "%COSMINEXUS_HOME%¥jaxws¥lib¥cjjaxws.jar;%COSMINEXUS_HOME%¥CC¥client¥lib¥j2ee-javax.jar" -d .¥temporary¥classes .¥temporary¥src¥com¥example¥sample¥TestJaxWsImpl.java .¥temporary¥src¥com¥example¥sample¥UserDefinedFault.java |
コンパイルが正常に終了すると,c:¥temp¥jaxws¥works¥wsrm¥server¥temporary¥classes¥com¥example¥sample¥ディレクトリにTestJaxWsImpl.classとUserDefinedFault.classが生成されます。これらのクラスファイルを利用して,cjwsgenコマンドのWSDL生成機能でWSDLファイルを作成します。
cjwsgenコマンドの実行例を次に示します。
> cd c:¥temp¥jaxws¥works¥wsrm¥server¥
> mkdir .¥WEB-INF¥wsdl¥
> "%COSMINEXUS_HOME%¥jaxws¥bin¥cjwsgen.bat" -r .¥WEB-INF¥wsdl -d .¥temporary¥classes -cp .¥temporary¥classes com.example.sample.TestJaxWsImpl |
cjwsgenコマンドが正常に終了すると,c:¥temp¥jaxws¥works¥wsrm¥WEB-INF¥wsdl¥ディレクトリにTestJaxWsService.wsdlとTestJaxWsService_schema1.xsdが生成されます。c:¥temp¥jaxws¥works¥wsrm¥temporary¥classes¥ディレクトリにあるクラスは削除してください。
生成されたTestJaxWsService.wsdlとTestJaxWsService_schema1.xsdは,一部修正する必要があります。
SOAP 1.1の場合のTestJaxWsService.wsdlの修正例を次に示します。イタリック体になっている個所が,修正した個所です。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions targetNamespace="http://example.com/sample" name="TestJaxWsImplService" xmlns:tns="http://example.com/sample" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema targetNamespace="http://example.com/sample">
<xsd:include schemaLocation="TestJaxWsImplService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="jaxWsTest1">
<part name="parameters" element="tns:jaxWsTest1"/>
</message>
<message name="jaxWsTest1Response">
<part name="parameters" element="tns:jaxWsTest1Response"/>
</message>
<message name="UserDefinedFault">
<part name="fault" element="tns:UserDefinedFault"/>
</message>
<portType name="TestJaxWs">
<operation name="jaxWsTest1">
<input message="tns:jaxWsTest1"/>
<output message="tns:jaxWsTest1Response"/>
<fault message="tns:UserDefinedFault" name="UserDefinedFault"/>
</operation>
</portType>
<binding name="testJaxWsBinding" type="tns:TestJaxWs">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="jaxWsTest1">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="UserDefinedFault">
<soap:fault name="UserDefinedFault" use="literal"/>
</fault>
</operation>
</binding>
<service name="TestJaxWsService">
<port name="testJaxWs" binding="tns:testJaxWsBinding">
<soap:address location="http://webhost:8085/wsrm/TestJaxWsService"/>
</port>
</service>
</definitions> |
SOAP 1.2の場合のTestJaxWsService.wsdlの修正例を次に示します。イタリック体になっている個所が,修正した個所です。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions targetNamespace="http://example.com/sample" name="TestJaxWsImplService" xmlns:tns="http://example.com/sample" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema targetNamespace="http://example.com/sample">
<xsd:include schemaLocation="TestJaxWsImplService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="jaxWsTest1">
<part name="parameters" element="tns:jaxWsTest1"/>
</message>
<message name="jaxWsTest1Response">
<part name="parameters" element="tns:jaxWsTest1Response"/>
</message>
<message name="UserDefinedFault">
<part name="fault" element="tns:UserDefinedFault"/>
</message>
<portType name="TestJaxWs">
<operation name="jaxWsTest1">
<input message="tns:jaxWsTest1"/>
<output message="tns:jaxWsTest1Response"/>
<fault message="tns:UserDefinedFault" name="UserDefinedFault"/>
</operation>
</portType>
<binding name="testJaxWsBinding" type="tns:TestJaxWs">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="jaxWsTest1">
<soap12:operation soapAction=""/>
<input>
<soap12:body use="literal"/>
</input>
<output>
<soap12:body use="literal"/>
</output>
<fault name="UserDefinedFault">
<soap12:fault name="UserDefinedFault" use="literal"/>
</fault>
</operation>
</binding>
<service name="TestJaxWsService">
<port name="testJaxWs" binding="tns:testJaxWsBinding">
<soap12:address location="http://webhost:8085/wsrm/TestJaxWsService"/>
</port>
</service>
</definitions> |
TestJaxWsService_schema1.xsdの修正例を次に示します。イタリック体になっている個所が,修正した個所です。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://example.com/sample" xmlns:tns="http://example.com/sample" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="UserDefinedFault" type="tns:UserDefinedFault"/>
<xs:element name="jaxWsTest1" type="tns:jaxWsTest1"/>
<xs:element name="jaxWsTest1Response" type="tns:jaxWsTest1Response"/>
<xs:complexType name="jaxWsTest1">
<xs:sequence>
<xs:element name="arg0" type="xs:string" minOccurs="0"/>
<xs:element name="arg1" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="jaxWsTest1Response">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="UserDefinedFault">
<xs:sequence>
<xs:element name="message" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema> |
修正したTestJaxWsService.wsdlは,名前をinput.wsdlに変更して,c:¥temp¥jaxws¥works¥wsrm¥server¥WEB-INF¥wsdl¥ディレクトリに保存してください。