Magazine
 
Quick Review:Ajax
 
Deploy Web services in Apache Geronimo
 

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());
}

May 2008 | Java Jazz Up | 24
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37 Download PDF