Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with AWS client needed  RSS feed

 
Yogs Kumar
Greenhorn
Posts: 23
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,
I am working on examples from Web Services up and running .I am currently trying to execute the following client against amazon web service.The class runs fine without any issues but no books are returned in the resultset,any idea what might be the problem

Here are the steps i followed:
1.I used the wsimport command to get the client classes:
wsimport -keep -p awsClient \ http://ecs.amazonaws.com/AWSECommerceService/AWSECommerceService.wsdl

2.Following is my client class:

import awsClient.AWSECommerceService;
import awsClient.AWSECommerceServicePortType;
import awsClient.ItemSearchRequest;
import awsClient.ItemSearch;
import awsClient.Items;
import awsClient.Item;
import awsClient.OperationRequest;
import awsClient.SearchResultsMap;
import awsClient.AwsHandlerResolver;
import javax.xml.ws.Holder;
import javax.xml.ws.handler.HandlerResolver;

import java.util.List;
import java.util.ArrayList;

class AmazonClientW {
public static void main(String[ ] args) {
if (args.length < 1) {
System.err.println("Usage: java AmazonClientW <access key>");
return;
}
final String access_key = args[0];
// Construct a service object to get the port object.
AWSECommerceService service = new AWSECommerceService();
service.setHandlerResolver(new AwsHandlerResolver("**********************"));
AWSECommerceServicePortType port = service.getAWSECommerceServicePort();
// Construct an empty request object and then add details.
ItemSearchRequest request = new ItemSearchRequest();
request.setSearchIndex("Books");
request.setKeywords("physics");
ItemSearch search = new ItemSearch();
search.getRequest().add(request);
search.setAWSAccessKeyId(access_key);
Holder<OperationRequest> operation_request = null;
Holder<List<Items>> items = new Holder<List<Items>>();
port.itemSearch(search.getMarketplaceDomain(), search.getAWSAccessKeyId(),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> item_list = retval.getItem();
// list of Item subelements
for (Item item : item_list)
{
System.out.println("Inside for!!!");
System.out.println(item.getItemAttributes().getTitle());
}
}
}

Can someone please help me as to what might be the reason for not getting any books in the result.
 
Luan Cestari
Ranch Hand
Posts: 172
C++ Redhat Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is this line:
Holder<OperationRequest> operation_request = null;

You must define the operation, which in this case would be the ItemSearch I think.
 
Yogs Kumar
Greenhorn
Posts: 23
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luan Cestari wrote:I think the problem is this line:
Holder<OperationRequest> operation_request = null;

You must define the operation, which in this case would be the ItemSearch I think.


Hello Luan Cestari,

That parameter is defined as an output parameter in the web service.The last two parameters are output parameters.So do you think i should assigning the value ItemSearch to that operation_request parameter.

Thanks
 
Luan Cestari
Ranch Hand
Posts: 172
C++ Redhat Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any error message? I was thinking a little bit more about this problem, i think i was wrong (after looking more the WSDL/XML schema and amazon docs), maybe what it is really missing the Signature parameter.

http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemSearch.html
http://docs.aws.amazon.com/AWSECommerceService/latest/DG/TheXMLMessageforanItemSearchSOAPRequest.html
 
Yogs Kumar
Greenhorn
Posts: 23
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luan Cestari wrote:Is there any error message? I was thinking a little bit more about this problem, i think i was wrong (after looking more the WSDL/XML schema and amazon docs), maybe what it is really missing the Signature parameter.

http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemSearch.html
http://docs.aws.amazon.com/AWSECommerceService/latest/DG/TheXMLMessageforanItemSearchSOAPRequest.html


Hello Luan thanks for looking into this

I have two points to add:

1.Yes these services needs signature and i am passing the required access key and secret key as run time arguments to the class.On the links you mentioned they had also told about the X.509 certificates.I created and installed those certificates in the mac keystore but no luck with the results.

2.I configured tcpmon to see what is the response xml i was getting the strange thing i noticed was that tcpmon is recording only the first request to get WSDL but i do NOT see a request going for this Item search operation.I am not sure why a request is not being sent or if there is some problem with my tcpmon in capturing the request.

Again thanks for your time!!!
 
Luan Cestari
Ranch Hand
Posts: 172
C++ Redhat Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome =). I would suggest to try to use tcpdump to capture the packets and analyze them later (just a single request will provide enough information). I also found a good example of Amazon WS in this book http://books.google.com.br/books?id=694fvh2hdVEC&lpg=PA51&ots=86bEc4GODv&dq=aws%20ecommerce%20%20web%20services%20java&pg=PA46#v=onepage&q&f=false
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!