Restletを使ってみた

HttpClientとXstreamでRESTしようとしたらダメだったので、Restletを使ってみた。

コードはこんな感じ。

public static void main(String[] args) throws IOException {
    String url = "http://auctions.yahooapis.jp/AuctionWebService/V1/SellingList?"
            + "appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            + "&sellerID=the_longbows";

    Client client = new Client(Protocol.HTTP);

    DomRepresentation entityAsDom = client.get(url).getEntityAsDom();
    NodeSet items = entityAsDom.getNodes("/AuctionSellingList/item/title");
    for (Node item : items) {
        System.out.println(item.getTextContent());
    }
}


初め、何故かyahoo.comのNot Foundが返ってきた。


com.noelios.restlet.ext.httpclient_3.1.jarがなかったのが原因らしい。
これはハマった。


なので、必要なモジュールは、

org.restlet.jar
com.noelios.restlet.jar
com.noelios.restlet.ext.httpclient_3.1.jar
commons-httpclient-3.1.jar
commons-codec-1.3.jar
commons-logging-1.1.1.jar

かな。


しかし、Restletって、結果をオブジェクトにマッピングまではしてくれないのね。。。
上のコードの用途だけなら、HttpClientだけでいいな・・。



HttpClient+digesterで行くか・・。