| 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 |
package com.amazonaws.mws.samples;
|
|
|
19 |
|
|
|
20 |
import java.io.ByteArrayInputStream;
|
|
|
21 |
import java.util.Arrays;
|
|
|
22 |
import java.util.GregorianCalendar;
|
|
|
23 |
import java.util.List;
|
|
|
24 |
import java.util.ArrayList;
|
|
|
25 |
|
|
|
26 |
import javax.xml.datatype.DatatypeConfigurationException;
|
|
|
27 |
import javax.xml.datatype.DatatypeFactory;
|
|
|
28 |
import javax.xml.datatype.XMLGregorianCalendar;
|
|
|
29 |
|
|
|
30 |
import com.amazonaws.mws.*;
|
|
|
31 |
import com.amazonaws.mws.model.*;
|
|
|
32 |
import com.amazonaws.mws.mock.MarketplaceWebServiceMock;
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
*
|
|
|
36 |
* Submit Feed Samples
|
|
|
37 |
*
|
|
|
38 |
*
|
|
|
39 |
*/
|
|
|
40 |
public class SubmitFeedSample {
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Just add a few required parameters, and try the service Submit Feed
|
|
|
44 |
* functionality
|
|
|
45 |
*
|
|
|
46 |
* @param args
|
|
|
47 |
* unused
|
|
|
48 |
*/
|
|
|
49 |
/**
|
|
|
50 |
* @param args
|
|
|
51 |
*/
|
|
|
52 |
public static void main(String... args) {
|
|
|
53 |
|
|
|
54 |
/************************************************************************
|
|
|
55 |
* Access Key ID and Secret Access Key ID, obtained from:
|
|
|
56 |
* http://aws.amazon.com
|
|
|
57 |
***********************************************************************/
|
|
|
58 |
final String accessKeyId = "<Your Access Key ID>";
|
|
|
59 |
final String secretAccessKey = "<Your Secret Access Key>";
|
|
|
60 |
|
|
|
61 |
final String appName = "<Your Application or Company Name>";
|
|
|
62 |
final String appVersion = "<Your Application Version or Build Number or Release Date>";
|
|
|
63 |
|
|
|
64 |
MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
|
|
|
65 |
|
|
|
66 |
/************************************************************************
|
|
|
67 |
* Uncomment to set the appropriate MWS endpoint.
|
|
|
68 |
************************************************************************/
|
|
|
69 |
// US
|
|
|
70 |
// config.setServiceURL("https://mws.amazonservices.com");
|
|
|
71 |
// UK
|
|
|
72 |
// config.setServiceURL("https://mws.amazonservices.co.uk");
|
|
|
73 |
// Germany
|
|
|
74 |
// config.setServiceURL("https://mws.amazonservices.de");
|
|
|
75 |
// France
|
|
|
76 |
// config.setServiceURL("https://mws.amazonservices.fr");
|
|
|
77 |
// Italy
|
|
|
78 |
// config.setServiceURL("https://mws.amazonservices.it");
|
|
|
79 |
// Japan
|
|
|
80 |
// config.setServiceURL("https://mws.amazonservices.jp");
|
|
|
81 |
// China
|
|
|
82 |
// config.setServiceURL("https://mws.amazonservices.com.cn");
|
|
|
83 |
// Canada
|
|
|
84 |
// config.setServiceURL("https://mws.amazonservices.ca");
|
|
|
85 |
// India
|
|
|
86 |
// config.setServiceURL("https://mws.amazonservices.in");
|
|
|
87 |
|
|
|
88 |
/************************************************************************
|
|
|
89 |
* You can also try advanced configuration options. Available options are:
|
|
|
90 |
*
|
|
|
91 |
* - Signature Version
|
|
|
92 |
* - Proxy Host and Proxy Port
|
|
|
93 |
* - User Agent String to be sent to Marketplace Web Service
|
|
|
94 |
*
|
|
|
95 |
***********************************************************************/
|
|
|
96 |
|
|
|
97 |
/************************************************************************
|
|
|
98 |
* Instantiate Http Client Implementation of Marketplace Web Service
|
|
|
99 |
***********************************************************************/
|
|
|
100 |
|
|
|
101 |
MarketplaceWebService service = new MarketplaceWebServiceClient(
|
|
|
102 |
accessKeyId, secretAccessKey, appName, appVersion, config);
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
/************************************************************************
|
|
|
106 |
* Setup request parameters and uncomment invoke to try out sample for
|
|
|
107 |
* Submit Feed
|
|
|
108 |
***********************************************************************/
|
|
|
109 |
|
|
|
110 |
/************************************************************************
|
|
|
111 |
* Marketplace and Merchant IDs are required parameters for all
|
|
|
112 |
* Marketplace Web Service calls.
|
|
|
113 |
***********************************************************************/
|
|
|
114 |
final String merchantId = "<Your Merchant ID>";
|
|
|
115 |
// marketplaces to which this feed will be submitted; look at the
|
|
|
116 |
// API reference document on the MWS website to see which marketplaces are
|
|
|
117 |
// included if you do not specify the list yourself
|
|
|
118 |
final IdList marketplaces = new IdList(Arrays.asList(
|
|
|
119 |
"Marketplae1",
|
|
|
120 |
"Marketplace2"));
|
|
|
121 |
|
|
|
122 |
SubmitFeedRequest request = new SubmitFeedRequest();
|
|
|
123 |
request.setMerchant(merchantId);
|
|
|
124 |
request.setMarketplaceIdList(marketplaces);
|
|
|
125 |
|
|
|
126 |
request.setFeedType("<Feed Type>");
|
|
|
127 |
|
|
|
128 |
// MWS exclusively offers a streaming interface for uploading your
|
|
|
129 |
// feeds. This is because
|
|
|
130 |
// feed sizes can grow to the 1GB+ range - and as your business grows
|
|
|
131 |
// you could otherwise
|
|
|
132 |
// silently reach the feed size where your in-memory solution will no
|
|
|
133 |
// longer work, leaving you
|
|
|
134 |
// puzzled as to why a solution that worked for a long time suddenly
|
|
|
135 |
// stopped working though
|
|
|
136 |
// you made no changes. For the same reason, we strongly encourage you
|
|
|
137 |
// to generate your feeds to
|
|
|
138 |
// local disk then upload them directly from disk to MWS via Java -
|
|
|
139 |
// without buffering them in Java
|
|
|
140 |
// memory in their entirety.
|
|
|
141 |
// Note: MarketplaceWebServiceClient will not retry a submit feed request
|
|
|
142 |
// because there is no way to reset the InputStream from our client.
|
|
|
143 |
// To enable retry, recreate the InputStream and resubmit the feed
|
|
|
144 |
// with the new InputStream.
|
|
|
145 |
//
|
|
|
146 |
// request.setFeedContent( new FileInputStream("my-feed.xml" /*or
|
|
|
147 |
// "my-flat-file.txt" if you use flat files*/);
|
|
|
148 |
|
|
|
149 |
invokeSubmitFeed(service, request);
|
|
|
150 |
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
/**
|
|
|
154 |
* Submit Feed request sample Uploads a file for processing together with
|
|
|
155 |
* the necessary metadata to process the file, such as which type of feed it
|
|
|
156 |
* is. PurgeAndReplace if true means that your existing e.g. inventory is
|
|
|
157 |
* wiped out and replace with the contents of this feed - use with caution
|
|
|
158 |
* (the default is false).
|
|
|
159 |
*
|
|
|
160 |
* @param service
|
|
|
161 |
* instance of MarketplaceWebService service
|
|
|
162 |
* @param request
|
|
|
163 |
* Action to invoke
|
|
|
164 |
*/
|
|
|
165 |
public static void invokeSubmitFeed(MarketplaceWebService service,
|
|
|
166 |
SubmitFeedRequest request) {
|
|
|
167 |
try {
|
|
|
168 |
|
|
|
169 |
SubmitFeedResponse response = service.submitFeed(request);
|
|
|
170 |
|
|
|
171 |
System.out.println("SubmitFeed Action Response");
|
|
|
172 |
System.out
|
|
|
173 |
.println("=============================================================================");
|
|
|
174 |
System.out.println();
|
|
|
175 |
|
|
|
176 |
System.out.print(" SubmitFeedResponse");
|
|
|
177 |
System.out.println();
|
|
|
178 |
if (response.isSetSubmitFeedResult()) {
|
|
|
179 |
System.out.print(" SubmitFeedResult");
|
|
|
180 |
System.out.println();
|
|
|
181 |
SubmitFeedResult submitFeedResult = response
|
|
|
182 |
.getSubmitFeedResult();
|
|
|
183 |
if (submitFeedResult.isSetFeedSubmissionInfo()) {
|
|
|
184 |
System.out.print(" FeedSubmissionInfo");
|
|
|
185 |
System.out.println();
|
|
|
186 |
FeedSubmissionInfo feedSubmissionInfo = submitFeedResult
|
|
|
187 |
.getFeedSubmissionInfo();
|
|
|
188 |
if (feedSubmissionInfo.isSetFeedSubmissionId()) {
|
|
|
189 |
System.out.print(" FeedSubmissionId");
|
|
|
190 |
System.out.println();
|
|
|
191 |
System.out.print(" "
|
|
|
192 |
+ feedSubmissionInfo.getFeedSubmissionId());
|
|
|
193 |
System.out.println();
|
|
|
194 |
}
|
|
|
195 |
if (feedSubmissionInfo.isSetFeedType()) {
|
|
|
196 |
System.out.print(" FeedType");
|
|
|
197 |
System.out.println();
|
|
|
198 |
System.out.print(" "
|
|
|
199 |
+ feedSubmissionInfo.getFeedType());
|
|
|
200 |
System.out.println();
|
|
|
201 |
}
|
|
|
202 |
if (feedSubmissionInfo.isSetSubmittedDate()) {
|
|
|
203 |
System.out.print(" SubmittedDate");
|
|
|
204 |
System.out.println();
|
|
|
205 |
System.out.print(" "
|
|
|
206 |
+ feedSubmissionInfo.getSubmittedDate());
|
|
|
207 |
System.out.println();
|
|
|
208 |
}
|
|
|
209 |
if (feedSubmissionInfo.isSetFeedProcessingStatus()) {
|
|
|
210 |
System.out
|
|
|
211 |
.print(" FeedProcessingStatus");
|
|
|
212 |
System.out.println();
|
|
|
213 |
System.out.print(" "
|
|
|
214 |
+ feedSubmissionInfo.getFeedProcessingStatus());
|
|
|
215 |
System.out.println();
|
|
|
216 |
}
|
|
|
217 |
if (feedSubmissionInfo.isSetStartedProcessingDate()) {
|
|
|
218 |
System.out
|
|
|
219 |
.print(" StartedProcessingDate");
|
|
|
220 |
System.out.println();
|
|
|
221 |
System.out
|
|
|
222 |
.print(" "
|
|
|
223 |
+ feedSubmissionInfo
|
|
|
224 |
.getStartedProcessingDate());
|
|
|
225 |
System.out.println();
|
|
|
226 |
}
|
|
|
227 |
if (feedSubmissionInfo.isSetCompletedProcessingDate()) {
|
|
|
228 |
System.out
|
|
|
229 |
.print(" CompletedProcessingDate");
|
|
|
230 |
System.out.println();
|
|
|
231 |
System.out.print(" "
|
|
|
232 |
+ feedSubmissionInfo
|
|
|
233 |
.getCompletedProcessingDate());
|
|
|
234 |
System.out.println();
|
|
|
235 |
}
|
|
|
236 |
}
|
|
|
237 |
}
|
|
|
238 |
if (response.isSetResponseMetadata()) {
|
|
|
239 |
System.out.print(" ResponseMetadata");
|
|
|
240 |
System.out.println();
|
|
|
241 |
ResponseMetadata responseMetadata = response
|
|
|
242 |
.getResponseMetadata();
|
|
|
243 |
if (responseMetadata.isSetRequestId()) {
|
|
|
244 |
System.out.print(" RequestId");
|
|
|
245 |
System.out.println();
|
|
|
246 |
System.out.print(" "
|
|
|
247 |
+ responseMetadata.getRequestId());
|
|
|
248 |
System.out.println();
|
|
|
249 |
}
|
|
|
250 |
}
|
|
|
251 |
System.out.println(response.getResponseHeaderMetadata());
|
|
|
252 |
System.out.println();
|
|
|
253 |
System.out.println();
|
|
|
254 |
|
|
|
255 |
} catch (MarketplaceWebServiceException ex) {
|
|
|
256 |
|
|
|
257 |
System.out.println("Caught Exception: " + ex.getMessage());
|
|
|
258 |
System.out.println("Response Status Code: " + ex.getStatusCode());
|
|
|
259 |
System.out.println("Error Code: " + ex.getErrorCode());
|
|
|
260 |
System.out.println("Error Type: " + ex.getErrorType());
|
|
|
261 |
System.out.println("Request ID: " + ex.getRequestId());
|
|
|
262 |
System.out.print("XML: " + ex.getXML());
|
|
|
263 |
System.out.println("ResponseHeaderMetadata: " + ex.getResponseHeaderMetadata());
|
|
|
264 |
}
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
}
|