import import import import import import import import import import import import
awsClient.AWSECommerceService; awsClient.AWSECommerceServicePortType; awsClient.ItemSearchRequest; awsClient.ItemSearch; awsClient.Items; awsClient.Item; awsClient.OperationRequest; awsClient.SearchResultsMap; awsClient.AwsHandlerResolver; javax.xml.ws.Holder; java.util.List; java.util.ArrayList;
class AmazonClientW { // W is for Wrapped style public static void main(String[] args) { if (args.length < 2) { System.err.println("Usage: java -cp . wrapped.TheClient
<secretkey>"); return; } final String access_key = args[0]; final String secret_key = args[1]; // Construct a service object to get the port object. AWSECommerceService service = new AWSECommerceService(); service.setHandlerResolver(new AwsHandlerResolver(secret_key)); AWSECommerceServicePortType port = service.getAWSECommerceServicePort(); // Construct an empty request object and then add details. ItemSearchRequest request = new ItemSearchRequest(); request.setSearchIndex("Books"); request.setKeywords("quantum gravity"); ItemSearch search = new ItemSearch(); search.getRequest().add(request); search.setAWSAccessKeyId(access_key); Holder operation_request = null; Holder> items = new Holder>(); port.itemSearch(search.getMarketplaceDomain(), search .getAWSAccessKeyId(), search.getSubscriptionId(), search .getAssociateTag(), search.getXMLEscaping(), search .getValidate(), search.getShared(), search.getRequest(), operation_request, items); // Unpack the response to print the book titles. Items retval = items.value.get(0); // first and only Items element List- item_list = retval.getItem(); // list of Item subelements for (Item item : item_list) // each Item in the list System.out.println(item.getItemAttributes().getTitle()); }
}