Subversion Repositories SmartDukaan

Rev

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