| 7473 |
vikram.rag |
1 |
/*******************************************************************************
|
|
|
2 |
* Copyright 2008-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
3 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
4 |
*
|
|
|
5 |
* You may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
|
|
|
7 |
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
8 |
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
|
9 |
* specific language governing permissions and limitations under the License.
|
|
|
10 |
* *****************************************************************************
|
|
|
11 |
*
|
|
|
12 |
* Marketplace Web Service Orders Java Library
|
|
|
13 |
* API Version: 2011-01-01
|
|
|
14 |
*
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
package com.amazonservices.mws.orders.samples;
|
|
|
20 |
|
|
|
21 |
import java.util.List;
|
|
|
22 |
import java.util.ArrayList;
|
|
|
23 |
import com.amazonservices.mws.orders.*;
|
|
|
24 |
import com.amazonservices.mws.orders.model.*;
|
|
|
25 |
import java.util.concurrent.Future;
|
|
|
26 |
import java.util.concurrent.Executors;
|
|
|
27 |
import java.util.concurrent.ExecutorService;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
*
|
|
|
31 |
* Get Order Samples
|
|
|
32 |
*
|
|
|
33 |
*
|
|
|
34 |
*/
|
|
|
35 |
public class GetOrderAsyncSample {
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Just add few required parameters, and try the service
|
|
|
39 |
* Get Order functionality
|
|
|
40 |
*
|
|
|
41 |
* @param args unused
|
|
|
42 |
*/
|
|
|
43 |
public static void main(String... args) {
|
|
|
44 |
|
|
|
45 |
ExecutorService executor = Executors.newFixedThreadPool(100);
|
|
|
46 |
MarketplaceWebServiceOrdersAsync service = new MarketplaceWebServiceOrdersAsyncClient(
|
|
|
47 |
OrdersConfig.accessKeyId,
|
|
|
48 |
OrdersConfig.secretAccessKey,
|
|
|
49 |
OrdersConfig.applicationName,
|
|
|
50 |
OrdersConfig.applicationVersion,
|
|
|
51 |
OrdersConfig.config,
|
|
|
52 |
executor);
|
|
|
53 |
|
|
|
54 |
/************************************************************************
|
|
|
55 |
* Setup requests parameters and invoke parallel processing. Of course
|
|
|
56 |
* in real world application, there will be much more than a couple of
|
|
|
57 |
* requests to process.
|
|
|
58 |
***********************************************************************/
|
|
|
59 |
GetOrderRequest requestOne = new GetOrderRequest();
|
|
|
60 |
// @TODO: set request parameters here
|
|
|
61 |
|
|
|
62 |
GetOrderRequest requestTwo = new GetOrderRequest();
|
|
|
63 |
// @TODO: set second request parameters here
|
|
|
64 |
|
|
|
65 |
List<GetOrderRequest> requests = new ArrayList<GetOrderRequest>();
|
|
|
66 |
requests.add(requestOne);
|
|
|
67 |
requests.add(requestTwo);
|
|
|
68 |
|
|
|
69 |
invokeGetOrder(service, requests);
|
|
|
70 |
|
|
|
71 |
executor.shutdown();
|
|
|
72 |
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Get Order request sample
|
|
|
79 |
* This operation takes up to 50 order ids and returns the corresponding orders.
|
|
|
80 |
*
|
|
|
81 |
* @param service instance of MarketplaceWebServiceOrders service
|
|
|
82 |
* @param requests list of requests to process
|
|
|
83 |
*/
|
|
|
84 |
public static void invokeGetOrder(MarketplaceWebServiceOrdersAsync service, List<GetOrderRequest> requests) {
|
|
|
85 |
List<Future<GetOrderResponse>> responses = new ArrayList<Future<GetOrderResponse>>();
|
|
|
86 |
for (GetOrderRequest request : requests) {
|
|
|
87 |
responses.add(service.getOrderAsync(request));
|
|
|
88 |
}
|
|
|
89 |
for (Future<GetOrderResponse> future : responses) {
|
|
|
90 |
while (!future.isDone()) {
|
|
|
91 |
Thread.yield();
|
|
|
92 |
}
|
|
|
93 |
try {
|
|
|
94 |
GetOrderResponse response = future.get();
|
|
|
95 |
// Original request corresponding to this response, if needed:
|
|
|
96 |
GetOrderRequest originalRequest = requests.get(responses.indexOf(future));
|
|
|
97 |
System.out.println("Response request id: " + response.getResponseMetadata().getRequestId());
|
|
|
98 |
} catch (Exception e) {
|
|
|
99 |
if (e.getCause() instanceof MarketplaceWebServiceOrdersException) {
|
|
|
100 |
MarketplaceWebServiceOrdersException exception = MarketplaceWebServiceOrdersException.class.cast(e.getCause());
|
|
|
101 |
System.out.println("Caught Exception: " + exception.getMessage());
|
|
|
102 |
System.out.println("Response Status Code: " + exception.getStatusCode());
|
|
|
103 |
System.out.println("Error Code: " + exception.getErrorCode());
|
|
|
104 |
System.out.println("Error Type: " + exception.getErrorType());
|
|
|
105 |
System.out.println("Request ID: " + exception.getRequestId());
|
|
|
106 |
System.out.println("XML: " + exception.getXML());
|
|
|
107 |
System.out.print("ResponseHeaderMetadata: " + exception.getResponseHeaderMetadata());
|
|
|
108 |
} else {
|
|
|
109 |
e.printStackTrace();
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
}
|