Published on WSO2 Oxygen Tank (http://wso2.org)

Amazon ECommerce Client

By damitha
Created 2008-03-13 10:19

This article by Damitha Kumarage describes, a WSF/C solution based on wsclient Web services command line client tool.

 

Introduction..

The Amazon E-Commerce Service [1], "ECS", exposes Amazon's product data through an easy-to-use Web services interface. WSO2-WSF/C Solution Space [2] provides an excellent command line tool called amazoneclient to consume this Web service from your command line shell(Linux or Windows). You can use the tool to search products, lookup selected items and finally add items to a shopping cart session created. The tool is easy to use and could be integrated to your scripts easily. amazoneclient internally uses WSF/C platforms command line Web services client tool called wsclient [3] for doing Web service calls. For more information on wsclient, see my tutorial, Calling Web Services From The Shell [4]. amazoneclient supports SOAP and REST like invocations.

 

Applies To

WSF/C 1.2.0, 1.2.1
Axis2/C 1.3.0
Environment Linux - Debian Etch/Lenny, Ubuntu, Fedora, Windows

 

Table of Contents

 

WSF/C-Solutions [5]. You need to have wsclient installed in your system, in order to use amazoneclient. Click here [6] to download and install wsclient.

Now, I will explain, in a step by step fashion, how to use amazoneclient effectively to do your transactions with Amazon e-commerce service.

 

Synopsis for amazonclient

amazoneclient.sh --subscription-id=<your amazon key> --op=<operation> --op-args=<key1:value1 key2:value2 ....>

For more information on each option do:

amazoneclient.sh --help

To interact with Amazon ecommerce service, you need to provide your amazon key that you can obtained from here, [7] with the option --subscription-id. You need to provide the operation you want to invoke from ItemSearch, ItemLookup, CartCreate, CartAdd, CartModify or CartClear.

You also need to specify required arguments for the operation, under the option --op-args. After each amazoneclient invocation, you will see two files in the current directory from which you invoked the command. One is <op_name>.xml and the other is <op_name>Response.xml. The former contains your request message payload prepared by amazoneclient ready to be sent. The latter is the response file you received after invoking the Web service. For example, if you invoked the operation ItemSearch, your request file will be ItemSearch.xml and your response ItemSearchResponse.xml. There is also a options called dump, which you can use for testing purposes. What this does is to dump your request into the operation response file, in wire format (complete with headers etc), instead of actually sending the message through the wire.

The response from Amazon service is unformatted raw xml. The job of amazoneclient does not include displaying this response properly formatted. There are many tools out there better suited for that. May be you can use XSLT for that. Infact, comand line tools in the shell are designed to combine with other useful commands through pipes, redirection etc to provide powerful combinations. Each single tool excels at what it is designed to do. You can use a tool like xmlindent  to display the response in simple text format.

By default amazoneclient send requests in REST. In order to tell amazoneclient to use SOAP formatted messages, use --soap option.

 

Author

Damitha Kumarage, Senior Software Engineer at wso2, committer Apache Software Foundation, damitha at wso2 dot com


Source URL:
http://wso2.org/library/3363