Subversion Repositories SmartDukaan

Rev

Rev 8224 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8224 manish.sha 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.util.Arrays;
23
import java.util.GregorianCalendar;
24
 
25
import javax.xml.datatype.DatatypeConfigurationException;
26
import javax.xml.datatype.DatatypeFactory;
27
import javax.xml.datatype.XMLGregorianCalendar;
28
 
29
import com.amazonaws.mws.*;
30
import com.amazonaws.mws.model.*;
31
import com.amazonaws.mws.mock.MarketplaceWebServiceMock;
32
 
33
/**
34
 *
35
 * Request Report  Samples
36
 *
37
 *
38
 */
39
public class RequestReportSample {
40
 
41
    /**
42
     * Just add a few required parameters, and try the service
43
     * Request Report functionality
44
     *
45
     * @param args unused
8363 vikram.rag 46
     * @throws MarketplaceWebServiceException 
8224 manish.sha 47
     */
8363 vikram.rag 48
    public static void main(String... args) throws MarketplaceWebServiceException {
8224 manish.sha 49
 
50
        /************************************************************************
51
         * Access Key ID and Secret Access Key ID, obtained from:
52
         * http://aws.amazon.com
53
         ***********************************************************************/
54
		final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
55
		final String secretAccessKey = "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";
56
 
57
		final String appName = "Test";
58
		final String appVersion = "1.0";
59
		final String merchantId = "AF6E3O0VE0X4D";
60
 
61
        MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
62
 
63
        /************************************************************************
64
         * Uncomment to set the appropriate MWS endpoint.
65
         ************************************************************************/
66
        // US
67
        // config.setServiceURL("https://mws.amazonservices.com");
68
        // UK
69
        // config.setServiceURL("https://mws.amazonservices.co.uk");
70
        // Germany
71
        // config.setServiceURL("https://mws.amazonservices.de");
72
        // France
73
        // config.setServiceURL("https://mws.amazonservices.fr");
74
        // Italy
75
        // config.setServiceURL("https://mws.amazonservices.it");
76
        // Japan
77
        // config.setServiceURL("https://mws.amazonservices.jp");
78
        // China
79
        // config.setServiceURL("https://mws.amazonservices.com.cn");
80
        // Canada
81
        // config.setServiceURL("https://mws.amazonservices.ca");
82
        // India
83
           config.setServiceURL("https://mws.amazonservices.in");
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
         * Uncomment to try out Mock Service that simulates Marketplace Web Service 
103
         * responses without calling Marketplace Web Service  service.
104
         *
105
         * Responses are loaded from local XML files. You can tweak XML files to
106
         * experiment with various outputs during development
107
         *
108
         * XML files available under com/amazonaws/mws/mock tree
109
         *
110
         ***********************************************************************/
111
        // MarketplaceWebService service = new MarketplaceWebServiceMock();
112
 
113
        /************************************************************************
114
         * Setup request parameters and uncomment invoke to try out 
115
         * sample for Request Report 
116
         ***********************************************************************/
117
 
118
        /************************************************************************
119
         * Marketplace and Merchant IDs are required parameters for all 
120
         * Marketplace Web Service calls.
121
         ***********************************************************************/
122
        // marketplaces from which data should be included in the report; look at the
123
        // API reference document on the MWS website to see which marketplaces are
124
        // included if you do not specify the list yourself
125
    	final IdList marketplaces = new IdList(Arrays.asList(
126
		"A21TJRUUN4KGV"));        
127
        RequestReportRequest request = new RequestReportRequest()
128
		        .withMerchant(merchantId)
129
		        .withMarketplaceIdList(marketplaces)
130
		        .withReportType("_GET_AFN_INVENTORY_DATA_")
131
		        .withReportOptions("ShowSalesChannel=true");
132
 
133
        // demonstrates how to set the date range
134
		DatatypeFactory df = null;
135
		try {
136
			df = DatatypeFactory.newInstance();
137
		} catch (DatatypeConfigurationException e) {
138
			e.printStackTrace();
139
			throw new RuntimeException(e);
140
		}
141
		XMLGregorianCalendar startDate = df
142
				.newXMLGregorianCalendar(new GregorianCalendar());
143
		XMLGregorianCalendar endDate = df
144
		.newXMLGregorianCalendar(new GregorianCalendar());
145
		//request.setStartDate(startDate);
146
		//request.setEndDate(endDate);
147
	    // @TODO: set additional request parameters here
148
 
149
		invokeRequestReport(service, request);
150
    }
151
 
152
 
153
 
154
    /**
155
     * Request Report  request sample
156
     * requests the generation of a report
157
     *   
158
     * @param service instance of MarketplaceWebService service
159
     * @param request Action to invoke
8363 vikram.rag 160
     * @throws MarketplaceWebServiceException 
8224 manish.sha 161
     */
8363 vikram.rag 162
    public static String invokeRequestReport(MarketplaceWebService service, RequestReportRequest request) throws MarketplaceWebServiceException {
8224 manish.sha 163
    	String requestId = null;   	
164
        try {
165
 
166
            RequestReportResponse response = service.requestReport(request);
167
 
168
 
169
 
170
            System.out.println ("RequestReport Action Response");
171
            System.out.println ("=============================================================================");
172
            System.out.println ();
173
 
174
            System.out.print("    RequestReportResponse");
175
            System.out.println();
176
            if (response.isSetRequestReportResult()) {
177
                System.out.print("        RequestReportResult");
178
                System.out.println();
179
                RequestReportResult  requestReportResult = response.getRequestReportResult();
180
                if (requestReportResult.isSetReportRequestInfo()) {
181
                    System.out.print("            ReportRequestInfo");
182
                    System.out.println();
183
                    ReportRequestInfo  reportRequestInfo = requestReportResult.getReportRequestInfo();
184
                    if (reportRequestInfo.isSetReportRequestId()) {
185
                        System.out.print("                ReportRequestId");
186
                        System.out.println();
187
                        System.out.print("                    " + reportRequestInfo.getReportRequestId());
188
                        requestId = reportRequestInfo.getReportRequestId();
189
                        System.out.println();
190
                    }
191
                    if (reportRequestInfo.isSetReportType()) {
192
                        System.out.print("                ReportType");
193
                        System.out.println();
194
                        System.out.print("                    " + reportRequestInfo.getReportType());
195
                        System.out.println();
196
                    }
197
                    if (reportRequestInfo.isSetStartDate()) {
198
                        System.out.print("                StartDate");
199
                        System.out.println();
200
                        System.out.print("                    " + reportRequestInfo.getStartDate());
201
                        System.out.println();
202
                    }
203
                    if (reportRequestInfo.isSetEndDate()) {
204
                        System.out.print("                EndDate");
205
                        System.out.println();
206
                        System.out.print("                    " + reportRequestInfo.getEndDate());
207
                        System.out.println();
208
                    }
209
                    if (reportRequestInfo.isSetSubmittedDate()) {
210
                        System.out.print("                SubmittedDate");
211
                        System.out.println();
212
                        System.out.print("                    " + reportRequestInfo.getSubmittedDate());
213
                        System.out.println();
214
                    }
215
                    if (reportRequestInfo.isSetReportProcessingStatus()) {
216
                        System.out.print("                ReportProcessingStatus");
217
                        System.out.println();
218
                        System.out.print("                    " + reportRequestInfo.getReportProcessingStatus());
219
                        System.out.println();
220
                    }
221
                } 
222
            } 
223
            if (response.isSetResponseMetadata()) {
224
                System.out.print("        ResponseMetadata");
225
                System.out.println();
226
                ResponseMetadata  responseMetadata = response.getResponseMetadata();
227
                if (responseMetadata.isSetRequestId()) {
228
                    System.out.print("            RequestId");
229
                    System.out.println();
230
                    System.out.print("                " + responseMetadata.getRequestId());
231
                    System.out.println();
232
                }
233
            } 
234
            System.out.println();
235
            System.out.println(response.getResponseHeaderMetadata());
236
            System.out.println();
237
 
238
        } catch (MarketplaceWebServiceException ex) {
239
 
240
            System.out.println("Caught Exception: " + ex.getMessage());
241
            System.out.println("Response Status Code: " + ex.getStatusCode());
242
            System.out.println("Error Code: " + ex.getErrorCode());
243
            System.out.println("Error Type: " + ex.getErrorType());
244
            System.out.println("Request ID: " + ex.getRequestId());
245
            System.out.print("XML: " + ex.getXML());
246
            System.out.println("ResponseHeaderMetadata: " + ex.getResponseHeaderMetadata());
8363 vikram.rag 247
            throw(ex);
8224 manish.sha 248
        }
249
		return requestId;
250
    }
251
 
252
}