The net is vast
プログラミングや、コンピュータなどの備忘録です。 主にRuby, Java, Linux, 等を扱います。アルゴリズムも扱いたいな。
16:54

AmazonのWSDLからJavaのクライアントの生成

Category: By jx
いつも思うのだけれど、WSDLで生成されたソースコードは激しくわかりづらい。生成してもなかなか使い方がわかりにくいから嫌い。Amazonももちろん使いづらくてどうしたら良いのかよくわからなかった。試行錯誤の上やっとできるように。 まず、WSDLの場所なんだけれども、英語ページを見ていると、上のURLにたどり着くが、これだと日本の商品にアクセス出来ない。ちゃんと調べると、下のURLが正しいことがわかった。 http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl http://webservices.amazon.com/AWSECommerceService/JP/AWSECommerceService.wsdl そしたら、以下のコマンドを実行して、スタブを生成
wsimport http://webservices.amazon.com/AWSECommerceService/JP/AWSECommerceService.wsdl
で、まぁここまでは、簡単なんだけど、その使い方が難しい。自由区/Webサービス紹介/Amazon E-Commerce Service - DoboWikiで、.Net用みたいだけど、説明してくれているのが役に立つ。で、できたのが下のソースコードでItemLookupのサンプルになってる。 ん〜自分で作ったRESTクライアントの方が早いし、わかりやすいからそのままにしようか。。。。
String marketplaceDomain = null;
String awsAccessKeyId = "19A48A3RYVJ128FSEN82";
String subscriptionId = null;
String associateTag = "jx-22";
String validate = null;
String xmlEscaping = null;
ItemLookupRequest shared = null;
List<ItemLookupRequest> request = new ArrayList<ItemLookupRequest>();
ItemLookupRequest req1 = new ItemLookupRequest();
req1.getItemId().add("4990412621");
req1.getItemId().add("4835612582");
request.add(req1);
Holder<OperationRequest> operationRequest = null;
Holder<List<Items>> items = new Holder<List<Items>>();

AWSECommerceService client = new AWSECommerceService();
AWSECommerceServicePortType service = client
        .getAWSECommerceServicePort();
service.itemLookup(marketplaceDomain, awsAccessKeyId, subscriptionId,
        associateTag, validate, xmlEscaping, shared, request,
        operationRequest, items);
List<Item> itemList = items.value.get(0).getItem();
for (Item item : itemList) {
    System.out.println(item.getItemAttributes().getTitle());
}
 

0 comments so far.

Something to say?