Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12459 kshitij.so 1
/******************************************************************************* 
2
 *  Copyright 2009 Amazon Services.
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 Java Library
13
 *  API Version: 2009-01-01
14
 *  Generated: Wed Feb 18 13:28:48 PST 2009 
15
 * 
16
 */
17
 
18
 
19
 
20
package com.amazonaws.mws.samples;
21
 
22
import java.io.ByteArrayOutputStream;
23
import java.util.List;
24
import java.util.ArrayList;
25
import com.amazonaws.mws.*;
26
import com.amazonaws.mws.model.*;
27
import java.util.concurrent.Future;
28
 
29
/**
30
 *
31
 * Get Feed Submission Result  Samples
32
 *
33
 *
34
 */
35
public class GetFeedSubmissionResultAsyncSample {
36
 
37
    /**
38
     * Just add a few required parameters, and try the service
39
     * Get Feed Submission Result functionality
40
     *
41
     * @param args unused
42
     */
43
    public static void main(String... args) {
44
 
45
        /************************************************************************
46
         * Access Key ID and Secret Access Key ID, obtained from:
47
         * http://aws.amazon.com
48
         ***********************************************************************/
49
        final String accessKeyId = "<Your Access Key ID>";
50
        final String secretAccessKey = "<Your Secret Access Key>";
51
        final String appName = "<Your Application or Company Name>";
52
        final String appVersion = "<Your Application Version or Build Number or Release Date>";
53
 
54
        MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
55
 
56
        /************************************************************************
57
         * Uncomment to set the appropriate MWS endpoint.
58
         ************************************************************************/
59
        // US
60
        // config.setServiceURL("https://mws.amazonservices.com");
61
        // UK
62
        // config.setServiceURL("https://mws.amazonservices.co.uk");
63
        // Germany
64
        // config.setServiceURL("https://mws.amazonservices.de");
65
        // France
66
        // config.setServiceURL("https://mws.amazonservices.fr");
67
        // Italy
68
        // config.setServiceURL("https://mws.amazonservices.it");
69
        // Japan
70
        // config.setServiceURL("https://mws.amazonservices.jp");
71
        // China
72
        // config.setServiceURL("https://mws.amazonservices.com.cn");
73
        // Canada
74
        // config.setServiceURL("https://mws.amazonservices.ca");
75
        // India
76
        // config.setServiceURL("https://mws.amazonservices.in");
77
 
78
        /************************************************************************
79
         * The argument (35) set below is the number of threads client should
80
         * spawn for processing.
81
         ***********************************************************************/
82
 
83
        config.setMaxAsyncThreads(35);
84
 
85
        /************************************************************************
86
         * You can also try advanced configuration options. Available options are:
87
         *
88
         *  - Signature Version
89
         *  - Proxy Host and Proxy Port
90
         *  - User Agent String to be sent to Marketplace Web Service
91
         *
92
         ***********************************************************************/
93
 
94
        /************************************************************************
95
         * Instantiate Http Client Implementation of Marketplace Web Service        
96
         ***********************************************************************/
97
 
98
        MarketplaceWebService service = new MarketplaceWebServiceClient(
99
                accessKeyId, secretAccessKey, appName, appVersion, config);
100
 
101
        /************************************************************************
102
         * Setup requests parameters and invoke parallel processing. Of course
103
         * in real world application, there will be much more than a couple of
104
         * requests to process.
105
         ***********************************************************************/
106
 
107
        /************************************************************************
108
         * Marketplace and Merchant IDs are required parameters for all 
109
         * Marketplace Web Service calls.
110
         ***********************************************************************/
111
        final String merchantId = "<Your Merchant ID>";
112
 
113
        GetFeedSubmissionResultRequest requestOne = new GetFeedSubmissionResultRequest();
114
        requestOne.setMerchant( merchantId );
115
 
116
        requestOne.setFeedSubmissionId( "<Feed Submission ID 1>" );
117
 
118
        // Note that depending on the size of the feed sent in, and the number of errors and warnings,
119
        // the result can reach sizes greater than 1GB. For this reason we recommend that you _always_ 
120
        // program to MWS in a streaming fashion. Otherwise, as your business grows you may silently reach
121
        // the in-memory size limit and have to re-work your solution.
122
        //
123
        // OutputStream processingResultOne = new FileOutputStream( "feedSubmissionResult-1.xml" );
124
        // requestOne.setFeedSubmissionResultOutputStream( processingResultOne );
125
 
126
        GetFeedSubmissionResultRequest requestTwo = new GetFeedSubmissionResultRequest();
127
        requestTwo.setMerchant( merchantId );
128
 
129
        requestTwo.setFeedSubmissionId( "<Feed Submission ID 2>" );
130
 
131
        // OutputStream processingResultTwo = new FileOutputStream( "feedSubmissionResult-2.xml" );
132
        // requestTwo.setFeedSubmissionResultOutputStream( processingResultTwo );
133
 
134
        List<GetFeedSubmissionResultRequest> requests = new ArrayList<GetFeedSubmissionResultRequest>();
135
        requests.add(requestOne);
136
        requests.add(requestTwo);
137
 
138
        // invokeGetFeedSubmissionResult(service, requests);
139
 
140
    }
141
 
142
 
143
 
144
    /**
145
     * Get Feed Submission Result request sample
146
     * retrieves the feed processing report
147
     *   
148
     * @param service instance of MarketplaceWebService service
149
     * @param requests list of requests to process
150
     */
151
    public static void invokeGetFeedSubmissionResult(MarketplaceWebService service, List<GetFeedSubmissionResultRequest> requests) {
152
        List<Future<GetFeedSubmissionResultResponse>> responses = new ArrayList<Future<GetFeedSubmissionResultResponse>>();
153
        for (GetFeedSubmissionResultRequest request : requests) {
154
            responses.add(service.getFeedSubmissionResultAsync(request));
155
        }
156
        for (Future<GetFeedSubmissionResultResponse> future : responses) {
157
            while (!future.isDone()) {
158
                Thread.yield();
159
            }
160
            try {
161
                GetFeedSubmissionResultResponse response = future.get();
162
                // Original request corresponding to this response, if needed:
163
                GetFeedSubmissionResultRequest originalRequest = requests.get(responses.indexOf(future));
164
                System.out.println("Result md5checksum : " + response.getGetFeedSubmissionResultResult().getMD5Checksum());
165
                System.out.println("Response request id: " + response.getResponseMetadata().getRequestId());
166
                System.out.println("FeedSubmissionResult: " );
167
                System.out.println( requests.get( responses.indexOf(future)).getFeedSubmissionResultOutputStream().toString());
168
                System.out.println(response.getResponseHeaderMetadata());
169
                System.out.println();
170
            } catch (Exception e) {
171
                if (e.getCause() instanceof MarketplaceWebServiceException) {
172
                    MarketplaceWebServiceException exception = MarketplaceWebServiceException.class.cast(e.getCause());
173
                    System.out.println("Caught Exception: " + exception.getMessage());
174
                    System.out.println("Response Status Code: " + exception.getStatusCode());
175
                    System.out.println("Error Code: " + exception.getErrorCode());
176
                    System.out.println("Error Type: " + exception.getErrorType());
177
                    System.out.println("Request ID: " + exception.getRequestId());
178
                    System.out.print("XML: " + exception.getXML());
179
                    System.out.println("ResponseHeaderMetadata: " + exception.getResponseHeaderMetadata());
180
                } else {
181
                    e.printStackTrace();
182
                }
183
            }
184
        }
185
    }
186
 
187
}