For simplicity, I created a class called AmazonClient in the same package structure that was generated
using WSDL2Java (com.amazon.xml.AWSECommerceServer). The code for this class is shown in
Listing 2. This class exposes a single method called lookupISBN. As the name suggests, this
method calls AWS and returns information about the book represented by the ISBN number
passed in.
Listing 2. AmazonClient.java
package com.amazon.xml.AWSECommerceServer;
import java.lang.*;
import java.util.*;
public class AmazonClient {
public AmazonClient() { }
public Items[] lookupISBN(String isbn) throws Exception {
try {
System.out.println("Given ISBN is " + isbn);
AWSECommerceServiceLocator locator =
new AWSECommerceServiceLocator();
AWSECommerceServicePortType type =
locator.getAWSECommerceServicePort();
String itemId[] = {isbn.trim()};
ItemLookup lookup = new ItemLookup();
lookup.setAssociateTag("MY ID"); // fill in your own
lookup.setSubscriptionId("MY ID"); // fill in your own
ItemLookupRequest lookupReq = new ItemLookupRequest();
lookupReq.setMerchantId("All");
lookupReq.setItemId(itemId);
lookupReq.setResponseGroup(new String[]
{"Medium", "OfferFull", "Variations", "Images"});
ItemLookupRequest[] requests = lookup.getRequest();
requests = new ItemLookupRequest[1];
requests[0] = lookupReq;
lookup.setRequest(requests);
ItemLookupResponse response =
type.itemLookup(lookup);
Items[] items = response.getItems();
if (items != null && items.length > 0) {
System.out.println("Number of results "+ items.length);
return items;
}
} catch (javax.xml.rpc.ServiceException se) {
throw new Exception(se.getMessage());
} |