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.List;
23
import java.util.ArrayList;
24
import java.io.ByteArrayOutputStream;
25
import java.io.FileOutputStream;
26
import java.io.OutputStream;
27
import com.amazonaws.mws.*;
28
import com.amazonaws.mws.model.*;
29
import com.amazonaws.mws.mock.MarketplaceWebServiceMock;
30
 
31
/**
32
 *
33
 * Get Report  Samples
34
 *
35
 *
36
 */
37
public class GetReportSample {
38
 
39
    /**
40
     * Just add a few required parameters, and try the service
41
     * Get Report functionality
42
     *
43
     * @param args unused
44
     */
45
    public static void main(String... args) {
46
 
47
        /************************************************************************
48
         * Access Key ID and Secret Access Key ID, obtained from:
49
         * http://aws.amazon.com
50
         ***********************************************************************/
51
        final String accessKeyId = "<Your Access Key ID>";
52
        final String secretAccessKey = "<Your Secret Access Key>";
53
 
54
        final String appName = "<Your Application or Company Name>";
55
        final String appVersion = "<Your Application Version or Build Number or Release Date>";
56
 
57
        MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
58
 
59
        /************************************************************************
60
         * Uncomment to set the appropriate MWS endpoint.
61
         ************************************************************************/
62
        // US
63
        // config.setServiceURL("https://mws.amazonservices.com");
64
        // UK
65
        // config.setServiceURL("https://mws.amazonservices.co.uk");
66
        // Germany
67
        // config.setServiceURL("https://mws.amazonservices.de");
68
        // France
69
        // config.setServiceURL("https://mws.amazonservices.fr");
70
        // Italy
71
        // config.setServiceURL("https://mws.amazonservices.it");
72
        // Japan
73
        // config.setServiceURL("https://mws.amazonservices.jp");
74
        // China
75
        // config.setServiceURL("https://mws.amazonservices.com.cn");
76
        // Canada
77
        // config.setServiceURL("https://mws.amazonservices.ca");
78
        // India
79
        // config.setServiceURL("https://mws.amazonservices.in");
80
 
81
        /************************************************************************
82
         * You can also try advanced configuration options. Available options are:
83
         *
84
         *  - Signature Version
85
         *  - Proxy Host and Proxy Port
86
         *  - User Agent String to be sent to Marketplace Web Service
87
         *
88
         ***********************************************************************/
89
 
90
        /************************************************************************
91
         * Instantiate Http Client Implementation of Marketplace Web Service        
92
         ***********************************************************************/
93
 
94
        MarketplaceWebService service = new MarketplaceWebServiceClient(
95
                accessKeyId, secretAccessKey, appName, appVersion, config);
96
 
97
        /************************************************************************
98
         * Setup request parameters and uncomment invoke to try out 
99
         * sample for Get Report 
100
         ***********************************************************************/
101
 
102
        /************************************************************************
103
         * Marketplace and Merchant IDs are required parameters for all 
104
         * Marketplace Web Service calls.
105
         ***********************************************************************/
106
        final String merchantId = "<Your Merchant ID>";
107
 
108
        GetReportRequest request = new GetReportRequest();
109
        request.setMerchant( merchantId );
110
 
111
        request.setReportId( "<Report ID>" );
112
 
113
        // Note that depending on the type of report being downloaded, a report can reach 
114
        // sizes greater than 1GB. For this reason we recommend that you _always_ program to
115
        // MWS in a streaming fashion. Otherwise, as your business grows you may silently reach
116
        // the in-memory size limit and have to re-work your solution.
117
        //
118
        // OutputStream report = new FileOutputStream( "report.xml" );
119
        // request.setReportOutputStream( report );
120
 
121
        // invokeGetReport(service, request);
122
 
123
    }
124
 
125
 
126
 
127
    /**
128
     * Get Report  request sample
129
     * The GetReport operation returns the contents of a report. Reports can potentially be
130
     * very large (>100MB) which is why we only return one report at a time, and in a
131
     * streaming fashion.
132
     *   
133
     * @param service instance of MarketplaceWebService service
134
     * @param request Action to invoke
135
     */
136
    public static void invokeGetReport(MarketplaceWebService service, GetReportRequest request) {
137
        try {
138
 
139
            GetReportResponse response = service.getReport(request);
140
 
141
 
142
            System.out.println ("GetReport Action Response");
143
            System.out.println ("=============================================================================");
144
            System.out.println ();
145
 
146
            System.out.print("    GetReportResponse");
147
            System.out.println();
148
            System.out.print("    GetReportResult");
149
            System.out.println();
150
            System.out.print("            MD5Checksum");
151
            System.out.println();
152
            System.out.print("                " + response.getGetReportResult().getMD5Checksum());
153
            System.out.println();
154
            if (response.isSetResponseMetadata()) {
155
                System.out.print("        ResponseMetadata");
156
                System.out.println();
157
                ResponseMetadata  responseMetadata = response.getResponseMetadata();
158
                if (responseMetadata.isSetRequestId()) {
159
                    System.out.print("            RequestId");
160
                    System.out.println();
161
                    System.out.print("                " + responseMetadata.getRequestId());
162
                    System.out.println();
163
                }
164
            } 
165
            System.out.println();
166
 
167
            System.out.println("Report");
168
            System.out.println ("=============================================================================");
169
            System.out.println();
170
            System.out.println( request.getReportOutputStream().toString() );
171
            System.out.println();
172
 
173
            System.out.println(response.getResponseHeaderMetadata());
174
            System.out.println();
175
 
176
 
177
        } catch (MarketplaceWebServiceException ex) {
178
 
179
            System.out.println("Caught Exception: " + ex.getMessage());
180
            System.out.println("Response Status Code: " + ex.getStatusCode());
181
            System.out.println("Error Code: " + ex.getErrorCode());
182
            System.out.println("Error Type: " + ex.getErrorType());
183
            System.out.println("Request ID: " + ex.getRequestId());
184
            System.out.print("XML: " + ex.getXML());
185
            System.out.println("ResponseHeaderMetadata: " + ex.getResponseHeaderMetadata());
186
        }
187
    }
188
 
189
}