JAX-RPCでWebServiceを動かす HelloService
まあ
cd C:\jwsdp-1.3\docs\jwstutorial13\examples\jaxrpc\helloservice
ant build
ant deploy
で動いちゃうんですが...
それでは味気ないので、チュートリアルを見て手動でやってみようと思います。
以下は、チュートリアルを読んで必要そうだと思った手順で、やってみたわけではありません。
まずはサービスのエンドポイントインターフェイスをコーディング。
HelloIF.java
package helloservice; import java.rmi.Remote; import java.rmi.RemoteException; public interface HelloIF extends Remote { public String sayHello(String s) throws RemoteException; }
続いて実装クラスをコーディング。
HelloImpl.java
package helloservice; public class HelloImpl implements HelloIF { public String message ="Hello"; public String sayHello(String s) { return message + s; } }
そしたらコンパイル。javacでもeclipseでも。
クラスファイルは
C:\jwsdp-1.3\docs\jwstutorial13\examples\jaxrpc\helloservice\build以下におく。
つづいて、C:\jwsdp-1.3\docs\jwstutorial13\examples\jaxrpc\helloservice\config-interface.xml を編集。
<?xml version="1.0" encoding="UTF-8"?> <configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config"> <service name="MyHelloService" targetNamespace="urn:Foo" typeNamespace="urn:Foo" packageName="helloservice"> <interface name="helloservice.HelloIF"/> </service> </configuration>
wscompileを実行。コマンドプロンプトで
cd C:\jwsdp-1.3\docs\jwstutorial13\examples\jaxrpc\helloservice
C:\jwsdp-1.3\jaxrpc\bin\wscompile -define -d build -nd build -classpath build config-interface.xml -model build/model.gz
jaxrpc-ri.xmlファイルを編集。
<?xml version="1.0" encoding="UTF-8"?> <webServices xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/dd" version="1.0" targetNamespaceBase="urn:Foo" typeNamespaceBase="urn:Foo" urlPatternBase="/ws"> <endpoint name="MyHello" displayName="HelloWorld Service" description="A simple web service" interface="helloservice.HelloIF" model="/WEB-INF/model.gz" implementation="hello.HelloImpl"/> <endpointMapping endpointName="MyHello" urlPattern="/hello"/> </webServices>
web.xmlを編集。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"> <web-app> <display-name>Hello World Application <description>A web application containing a simple JAX-RPC endpoint <session-config> <session-timeout>60 </session-config> </web-app>
以下の構成でdist/hello-jaxrpc-portable.warファイルを作成。(zip圧縮して拡張子変えるなり、antを使用するなりして)
WEB-INF/classes/hello/HelloIF.class
WEB-INF/classes/hello/HelloImpl.class
WEB-INF/jaxrpc-ri.xml
WEB-INF/model.gz
WEB-INF/web.xml
デプロイ可能なwarファイルを作成
コマンドプロンプトで
C:\jwsdp-1.3\jaxrpc\bin\wsdeploy -o dist/hello-jaxrpc.war dist/hello-jaxrpc-portable.war
これで、MyHelloService.wsdlを含んだ dist/hello-jaxrpc.war が作成される。
このwarファイルを C:\jwsdp-1.3\webapps に配置すればOK。
ブラウザで http://localhost:8080/hello-jaxrpc/hello にアクセスすれば、WebServiceの情報が表示される。