1 / 24

Web サービス II ( 第 1 3 回 ) ‏

Web サービス II ( 第 1 3 回 ) ‏. 2008 年 1 月 9 日 植田龍男. 本日の目的. Web サービスの 歴史と将来の展望 (1) WSDL 2.0 の登場 ‏ Jersey プロジェクト Ver 0.5 による開発. この講義で やったこと. Java SE 6 と JAXB, JAX-WS 2.0 の API JAX-WS 2.0 の枠組みによる開発 サーバサイドは POJO + アノテーション アプリケーションサーバ Glassfish RESTful な Web サービスの存在

baka
Download Presentation

Web サービス II ( 第 1 3 回 ) ‏

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WebサービスII (第13回)‏ 2008年1月9日 植田龍男

  2. 本日の目的 • Webサービスの歴史と将来の展望(1) • WSDL 2.0 の登場‏ • JerseyプロジェクトVer 0.5 • による開発

  3. この講義でやったこと • Java SE 6 と JAXB, JAX-WS 2.0 のAPI • JAX-WS2.0の枠組みによる開発 • サーバサイドは POJO + アノテーション • アプリケーションサーバ Glassfish • RESTful なWebサービスの存在 • RESTful なWebサービスの新しい開発方法 • Jerseyプロジェクト、WADL

  4. 2種類のWebサービス • 「古典的」 Webサービス SOAPメッセージの交換 RPC型(メソッドの呼び出しをインタフェースで定義) • RESTful なWebサービス URIでアクセス可能、「裸の」XMLを送信

  5. それぞれの長所・短所(昔) • 古典的: WSDLによる厳格な定義 標準化・統合が保証 開発者の負担大、広い普及が遅れ • RESTful: 開発の自由度大、手軽、普及が速い 標準化、統合は視野外 開発者にある程度のスキルは必要

  6. それぞれの長所・短所(今) • 古典的: WSDLによる厳格な定義 標準化・統合が保証 EoDの普及で負担は減 • RESTful: 開発の自由度大、手軽、普及が速い 標準化・統合の可能性 EoDの導入も

  7. 復習:開発の手順の比較(1) • Java SE 6 の SOAP型の開発 @Webservice アノテーションが付加された POJO からスタート • Jersey の RESTful 型の開発 @UriTemplate, @HttpMethod が付加された POJO からスタート

  8. 復習:開発手順の比較(2) • SOAP型 ツール wsgen によるソースとWSDLの自動生成 => サーバが公開 http://sitename/servicename?wsdl • RESTful型 apt + 専用のプロセッサによるソースとWADLの自動生成=>RESTfulサービスで公開 http://sitename/applicaiton.wadl

  9. RESTful 型の課題 • アノテーションの記述方法や処理方法のより洗練されたスタイル (Jerseyはまだ開発途上) • すべてのサービスでWADLの存在の保証 • WSDLとの統合

  10. WSDL 2.0 まで • 現行のWSDLVer 1.1 (原理的にはSOAP、HTTPに非依存 実質的には HTTP上のSOAP) • その後に追加したい機能の登場 WS-I による標準化の試み • RESTful なWebサービスの普及 (「HTTP と SOAP」という表現)

  11. Jersey0.4の自動処理 • J2SE 5.0 の apt ツールでアノテーションを処理 • HelloWorldService を記述するWADLを 自動生成 com/sun/ws/rest/wadl/resource の下に application.wadl • WadlResouce のソースとバイトコード生成 =>application.wadlの情報を提供する

  12. Jersey0.4の不便だった点 • apt の処理は「古い」スタイル • 手動で apt の処理を呼び出す必要 • (アノテーション処理の理解が必要) • アノテーションの名称や形式の意味が直観的にわかりにくい

  13. Jersey 0.5 では • 処理は POJOのコンパイルのみ javac -cp $LIB/jsr311-api.jar Source.java • application.wadl を提供するクラスの存在は意識する必要がない(サーバ側で自動生成) • よりわかりやすいアノテーション @Path, @GET など

  14. Jersey 0.4 の POJO @UriTemplate("/helloworld") public class HelloWorldResource { @HttpMethod("GET") @ProduceMime("text/plain") public String getClichedMessage() { return "Hello World!"; } }

  15. Jersey 0.5 の POJO @Path("/helloworld") public class HelloWorldResource { @GET @ProduceMime("text/plain") public String getClichedMessage() { return "Hello World!"; } }

  16. Jersey 0.4 => 0.5 • WADLの利用はオプショナルではなくデフォルトとなった(常に利用可能) =WADLやそれを提供するクラスの存在は意識しなくてより(知識がなくてもよい) • apt やアノテーション処理の知識も不要 • JAX-WS 2.0 の枠組みによる SOAP型の開発スタイルのレベルにより近づいた • 開発スタイルの「統合」も近い?

  17. WADLプロジェクト • http://wadl.dev.java.net/ •  バイナリパッケージを展開 ~ -+- wadl -+- bin -+- wadl2java <-- UNIX用のツール本体 | +- wadl2java.bat <-- Windows用のツール本体 +- lib -+- wadl-cmdline-1.0-SNAPSHOT.jar +- samples -+- ant -+- build.xml <-- ant でビルド +- cmdline -+- run <-- UNIX用 | +- run.cmd <-- Windows用 +- maven -+- pom.xml <-- maven でビルド +- share -+- YahooSearch.wadl

  18. Helloworld の WADL(全体) <application xmlns="http://research.sun.com/wadl/2006/10"> <resources base="http://localhost:9998/"> <resource path="/helloworld"> <method name="GET"> <response> <representation mediaType="text/plain"/> </response> </method> </resource> </resources> </application>

  19. Helloworld の WADL(前半部) <application xmlns="http://research.sun.com/wadl/2006/10"> <resources base="http://localhost:9998/"> <resource path="/helloworld"> <method name="GET"> <response> <representation mediaType="text/plain"/>

  20. 生成された Endpoint.java public class Endpoint { public static class Helloworld { public Helloworld() { … } public DataSource getAsTextPlain()‏ { … } } }

  21. クライアントプログラム import hello.Endpoint; import java.io.*; import javax.activation.DataSource; public class HelloClient { public static void main( String[] args ) {

  22. クライアントプログラム(2) Endpoint.Helloworld service = new Endpoint.Helloworld(); DataSource source = service.getAsTextPlain(); Reader reader = new InputStreamReader( source.getInputStream() );

  23. 手順のまとめ • Jerseyによるサーバサイドと WADLの提供 POJOからの自動生成 第10回の課題を参照:ポイントは apt によるアノテーションの処理 • WADL の取得(クライアント側) • WADLからのJavaの自動生成 第11回の課題を参照: ポイントは wadl2java

  24. 1月の予定 • 1/9 第13回:「Webサービスの未来(1)」 • 1/16 第14回:「Webサービスの未来(2)」 • 1/23 第15回:試験 (2階実習室にて)

More Related