Jersey Hello World Service WADL comsunwsrestwadlresource application wadl

  • Slides: 26
Download presentation

Jersey の自動処理 Hello. World. Service を記述するWADLが 自動生成 com/sun/ws/rest/wadl/resource の下に application. wadl 同じディレクトリに Wadl. Resouce

Jersey の自動処理 Hello. World. Service を記述するWADLが 自動生成 com/sun/ws/rest/wadl/resource の下に application. wadl 同じディレクトリに Wadl. Resouce のソースとバイトコード生成 =>application. wadlの情報を提供する

 WADLプロジェクト  http: //wadl. dev. java. net/  バイナリパッケージを展開 ~ -+- wadl -+- bin -+- wadl

 WADLプロジェクト  http: //wadl. dev. java. net/  バイナリパッケージを展開 ~ -+- wadl -+- bin -+- wadl 2 java <-- UNIX用のツール本体   | +- wadl 2 java. 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 -+- Yahoo. Search. wadl

Yahoo. Search の WADL(1) <application xmlns="http: //research. sun. com/wadl/2006/10 "> <grammars> <include href="News. Search.

Yahoo. Search の WADL(1) <application xmlns="http: //research. sun. com/wadl/2006/10 "> <grammars> <include href="News. Search. Response. xsd"/> <include href="News. Search. Error. xsd"/> </grammars> :

Yahoo. Search の WADL(2) <resources base="http: //api. search. yahoo. com/New s. Search. Service/V 1/">

Yahoo. Search の WADL(2) <resources base="http: //api. search. yahoo. com/New s. Search. Service/V 1/"> <resource path="news. Search"> : <method href="#search"/> </resources>

Yahoo. Search の WADL(3) <method name="GET" id="search"> <request> <param name="query" type="xsd: string" required="true" style="query">

Yahoo. Search の WADL(3) <method name="GET" id="search"> <request> <param name="query" type="xsd: string" required="true" style="query"> </param><param name="results" type="xsd: int" default="10" style="query"> </param>

対応する URLのパターン http: //api. search. yahoo. com/News Search. Service/V 1/news. Search? query=Ja pan&results=20&. .

対応する URLのパターン http: //api. search. yahoo. com/News Search. Service/V 1/news. Search? query=Ja pan&results=20&. . .

Yahoo. Search の WADL(4) <response> <representation media. Type="application/xml" element="yn: Result. Set"> </representation> </response> </method>

Yahoo. Search の WADL(4) <response> <representation media. Type="application/xml" element="yn: Result. Set"> </representation> </response> </method> </application>

返されるXML文書の例 <Result. Set xmlns=”urn: yahoo: yn”> <Result> <title>. . . </title> <url>. . .

返されるXML文書の例 <Result. Set xmlns=”urn: yahoo: yn”> <Result> <title>. . . </title> <url>. . . </url> : </Result> <Result>. . . </Result> </Result. Set>

import java. util. List; import com. yahoo. search. *; public class Client { public

import java. util. List; import com. yahoo. search. *; public class Client { public static void main( String[] args ) { Yahoo. Searchのクライアントの例 import java. util. List; import com. yahoo. search. *; public class Client { public static void main( String[] args ) { try { : :

import java. util. List; import com. yahoo. search. *; public class Client { public

import java. util. List; import com. yahoo. search. *; public class Client { public static void main( String[] args ) { Yahoo. Searchのクライアントの例 Endpoint. News. Search search = new Endpoint. News. Search(); Result. Set set = search. get. As. Result. Set( "jaxws_restful_sample", args[0] ); // 第1引数はID情報、第2引数は検索ワード // URI などの情報は表に現れない!

import java. util. List; import com. yahoo. search. *; public class Client { public

import java. util. List; import com. yahoo. search. *; public class Client { public static void main( String[] args ) { Yahoo. Searchのクライアントの例 // 結果の取り出し // ここでも POJO のみの記述 List<Result> list = set. get. Result. List(); for( Result result : list ) { System. out. println( result. get. Title() + ": " + result. get. Summary() ); }

Helloworld の WADL(全体) <application xmlns="http: //research. sun. com/wadl/2006/10"> <resources base="http: //localhost: 9998/"> <resource path="/helloworld">

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

Helloworld の WADL(前半部) <application xmlns="http: //research. sun. com/wadl/2006/10"> <resources base="http: //localhost: 9998/"> <resource path="/helloworld">

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

生成された Endpoint. java public class Endpoint { public static class Helloworld { public Helloworld()

生成された Endpoint. java public class Endpoint { public static class Helloworld { public Helloworld() { … } public Data. Source get. As. Text. Plain() {…} } }

クライアントプログラム import hello. Endpoint; import java. io. *; import javax. activation. Data. Source;   public

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

クライアントプログラム(2) Endpoint. Helloworld service = new Endpoint. Helloworld(); Data. Source source = service. get.

クライアントプログラム(2) Endpoint. Helloworld service = new Endpoint. Helloworld(); Data. Source source = service. get. As. Text. Plain(); Reader reader = new Input. Stream. Reader( source. get. Input. Stream() );