«^»
11.2. Providing a JavaServer page that is a client of Amazon's Web Services

I then produced the following JavaServer page. You need to register with Amazon to use these facilities. For this reason, in the following code, my registration id has been replaced by XXXXXXXXXXXXXX. Setting the locale to uk is meant to get it to yield information from amazon.co.uk rather than amazon.com but this does not seem to be the case for some pieces of information. It seems it is part of the design of Amazon's Web Service to return null if a value is not available in time: it seems that their view is that it is better to be fast in providing some of the information rather than hanging around for all of it to become available.

0310: <html>
0311: <body>
0312: <%@page language="java" import="com.amazon.soap.*" %>
0313: <%
0314:    try 
0315:    {
0316:       String tIsbn = "0201711079";
0317:       AmazonSearchService tAmazonSearchService = new AmazonSearchServiceLocator();
0318:       AmazonSearchPort tAmazonSearchPort = tAmazonSearchService.getAmazonSearchPort();
0319:       AsinRequest tAsinRequest = new AsinRequest();
0320:       tAsinRequest.setTag("webservices-20");
0321:       tAsinRequest.setDevtag("XXXXXXXXXXXXXX");
0322:       tAsinRequest.setAsin(tIsbn);
0323:       tAsinRequest.setLocale("uk");
0324:       tAsinRequest.setType("heavy");
0325:       ProductInfo tProductInfo = tAmazonSearchPort.asinSearchRequest(tAsinRequest);
0326:       Details[] tDetailsArray = tProductInfo.getDetails();
0327:       String tProductName = tDetailsArray[0].getProductName();
0328:       String tReleaseDate = tDetailsArray[0].getReleaseDate();
0329:       String tOurPrice = tDetailsArray[0].getOurPrice();
0330:       String tListPrice = tDetailsArray[0].getListPrice();
0331:       String tUsedPrice = tDetailsArray[0].getUsedPrice();
0332:       String tSalesRank = tDetailsArray[0].getSalesRank();
0333:       String tAvailability = tDetailsArray[0].getAvailability();
0334:       String tImageUrlSmall = tDetailsArray[0].getImageUrlSmall();
0335:       String tImageUrlMedium = tDetailsArray[0].getImageUrlMedium();
0336:       String tImageUrlLarge = tDetailsArray[0].getImageUrlLarge();
0337: %>
0338:       <table><tr><td><img src="<%= tImageUrlMedium %>"></td><td>
0339:       My book <em><%= tProductName %></em> is on sale at 
0340:       <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0201711079/">www.amazon.co.uk</a>
0341:       for <%= tOurPrice %>.
0342: <%
0343:       if ( ! tOurPrice.equals(tListPrice) )
0344:       {
0345: %>
0346:          <br>Its list price is <%= tListPrice %>.
0347: <%
0348:       }
0349: %>
0350:       <br>Grimly, it's also available there with a used price of <%= tUsedPrice %>!
0351:       <br>Currently, its sales rank is <%= tSalesRank %>.
0352:       <br>It was published on <%= tReleaseDate %>.
0353:       </td></tr></table>
0354: <%
0355:    }
0356:    catch (Exception pException)
0357:    {
0358:       pException.printStackTrace();
0359:    }
0360: %>
0361: </body>
0362: </html>