Service-Oriented Computing:
Programming Assignment 1
Connecting to the Amazon Web Service
Write a client application that uses the Amazon Web Services. You can make
any kind of search from Amazon.com, such as retrieving product information from
the Amazon.com catalog. Amazon Web Services make use of either SOAP or XML over
HTTP. This assignment uses SOAP.
The assignment requires you to write a client program that performs the
following tasks:
- Search and list products. For
example, A Keyword Search for books on Turkish Cook Books. [KEYWORDREQUEST]
- Choose one of the products
listed and retrieve the detailed product information. [ASINREQUEST]
- Add this chosen product to
the Shopping Cart and display the cart. Modify the cart, by increasing the
Quantity and redisplay.
[ADDSHOPPINGCARTITEMSREQUEST
and MODIFYSHOPPINGCARTITEMSREQUEST]
The
quality of the user interface is not important for this assignment, although it
is of course important in general. Use the following steps to carry out this
assignment. A sample implementation
of this assignment can be seen at this link http://iris.csc.ncsu.edu:8080/amazon/amazonSearch.jsp.
- Download the Amazon Web
Services toolkit
and become familiar with the services Amazon.com provides. Specifically,
review the README file, the JavaCodeSample
directory, and an example implementation found in the kit.
- Use the WSDL
document describing Amazon.com offering. This document contains
information on where the service is located and what types of messages it
expects.
- Download Axis. Read the Installation and
User's Guide. This assignment requires only a limited use of Axis.
- Set your CLASSPATH
to individually include axis.jar, commons-discovery.jar, commons-logging.jar,
jaxrpc.jar, saaj.jar,
log4j-1.2.4.jar, and wsdl4j.jar. [Use the corresponding file names
from the latest distribution of axis]
- Use the Axis WSDL2Java
tool to generate Java classes from AmazonWebServices.wsdl.
- Compile these Java
files to confirm that WSDL2Java generated everything correctly.
- You might compare the WSDL
document with some Java files to better understand what is going on. In
particular, consider the following classes in the com.amazon.soap.axis
package that are needed for this assignment. Review examples given also.
- AmazonSearchServiceLocator
- AmazonSearchPort [Look at the different messages supported. For ex: keywordSearchRequest]
- KeywordRequest
- ProductInfo
- Details
- AsinRequest
- AddShoppingCartItemsRequest
- AddItem
- Item
- ModifyShoppingCartItemsRequest
- ItemQuantity
- Write a client program that
uses the generated class files to access the actual Web Services
implementations. Review the sample Java programs in the developer kit.
Your client program can be a servlet, a JSP
page, or a simple Java application. We recommend JSP for this purpose.
Because you won't deploy any Web Services, you don't need to install an
application server, other than to host your JSP page or servlet. Jakarta
Tomcat is a good application server.
- We are using the older
version of AWS. You need to
get a dev tag from Amazon by registering with them. Go here. If this link does not work, go to
amazon.com and find their link to Web services, and there create an
account. The dev tag is the same as the
Access Key Id that will be given to you. This dev tag is need to make any request to the amazon
web services. The tag
field can be assigned the value of “webservices-20” in the
requests. See example code snippet below.
- Submit your client code and
the output of running this client program by using the online submit
utility. Include a README file describing how to invoke your program. If you have a JSP-based client
program hosted on a personal application server, specify the URL in the
README file.
Code Snippets to
help you get a start
First Part: KeywordRequest
Your client application will have a call to the amazon web service in the following way. Solution given here to
simplify.
AmazonSearchServiceLocator
AmazonServiceLocator = new AmazonSearchServiceLocator();
AmazonSearchPort
searchSite = AmazonServiceLocator.getAmazonSearchPort();
KeywordRequest
theRequest = new KeywordRequest();
theRequest.setKeyword(keyword);
theRequest.setTag("webservices-20");
theRequest.setDevtag("<YOUR
DEV TAG>");
theRequest.setPage("1");
theRequest.setMode("books");
theRequest.setType("heavy");
ProductInfo
result = searchSite.keywordSearchRequest(theRequest);
Details[]
allDetails = result.getDetails();
Extract the details from this object and display all the
returned results, in our case, all the books relevant to the keyword. See the example implementation.
Second Part: AsinRequest
Complete
this part and the parts below in the similar fashion. For the list of the products displayed,
select one of them and perform a AsinRequest
call on it, and retrieve more information on it. See the example implementation for
reference.
Third Part: Adding to a cart.
Hint:
You need to call the request addShoppingCartItemsRequest
first with the AddItems array (in our case just 1
item in the array) along with your tag, and devtag, to
obtain the cartId, and the HMAC for the transaction. cartId
and HMAC are not known originally otherwise. The response of this request is ShoppingCart, from which you can retrieve all the necessary
information like cartId, and HMAC, and the items in
the cart.
Fourth Part :
Modifying the cart.
Hint:
Use the cartId and HMAC obtained from the previous
part, to call modifyShoppingCartItemsRequest along
with the ItemQuantity array (one item in the array in
this case with the modified quantity), your tag (in this case “webservices-20” ) , and dev tag (obtain one from Amazon by
registering with them).