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