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
package com.amazonaws.mws.samples;
19
 
20
import java.io.ByteArrayInputStream;
21
 
22
import java.io.File;
23
import java.io.FileInputStream;
24
import java.io.FileNotFoundException;
25
import java.io.IOException;
26
import java.math.BigDecimal;
27
import java.math.BigInteger;
28
import java.nio.channels.FileChannel;
29
import java.security.DigestInputStream;
30
import java.security.MessageDigest;
31
import java.security.NoSuchAlgorithmException;
32
import java.util.Arrays;
33
import java.util.Calendar;
34
import java.util.Date;
35
import java.util.GregorianCalendar;
36
import java.util.List;
37
import java.util.ArrayList;
38
import java.util.TimeZone;
39
 
40
import javax.xml.bind.JAXBContext;
41
import javax.xml.bind.JAXBException;
42
import javax.xml.bind.Marshaller;
43
import javax.xml.datatype.DatatypeConfigurationException;
44
import javax.xml.datatype.DatatypeFactory;
45
import javax.xml.datatype.XMLGregorianCalendar;
46
 
47
import com.amazonaws.mws.*;
48
import com.amazonaws.mws.model.*;
49
import com.amazonaws.mws.mock.MarketplaceWebServiceMock;
50
import org.apache.commons.codec.binary.*;
51
 
52
import in.shop2020.feeds.products.AmazonEnvelope;
53
import in.shop2020.feeds.products.BaseCurrencyCodeWithDefault;
54
import in.shop2020.feeds.products.CE;
55
import in.shop2020.feeds.products.HandheldOrPDA;
56
import in.shop2020.feeds.products.Header;
57
import in.shop2020.feeds.products.Inventory;
58
import in.shop2020.feeds.products.Listings;
59
import in.shop2020.feeds.products.OverrideCurrencyAmount;
60
import in.shop2020.feeds.products.Price;
61
import in.shop2020.feeds.products.Product;
62
import in.shop2020.feeds.products.StandardProductID;
63
import in.shop2020.model.v1.catalog.CatalogService.Client;
64
import in.shop2020.model.v1.catalog.CatalogServiceException;
65
import in.shop2020.model.v1.catalog.Item;
66
import in.shop2020.model.v1.inventory.InventoryServiceException;
67
import in.shop2020.model.v1.inventory.ItemInventory;
68
import in.shop2020.thrift.clients.CatalogClient;
69
import in.shop2020.thrift.clients.InventoryClient;
70
 
71
import org.apache.thrift.TException;
72
import org.apache.thrift.transport.TTransportException;
73
 
74
/**
75
 * 
76
 * Submit Feed Samples
77
 * 
78
 * 
79
 */
80
public class SubmitFeed {
81
 
82
    /**
83
     * Just add a few required parameters, and try the service Submit Feed
84
     * functionality
85
     * 
86
     * @param args
87
     *            unused
88
     *            
89
     */
90
    /**
91
     * @param args
92
     * @throws TException 
93
     * @throws CatalogServiceException 
94
     */
95
 
96
	final public static String AMAZON_LISTING_XML = "/home/vikram/listing.xml";
97
	final public static String AMAZON_INVENTORY_XML = "/home/vikram/inventory.xml";
98
	final public static String AMAZON_PRICING_XML   = "/home/vikram/pricing.xml";
99
    public static void main(String... args) throws CatalogServiceException, TException {
100
 
101
        /************************************************************************
102
         * Access Key ID and Secret Access Key ID, obtained from:
103
         * http://aws.amazon.com
104
         ***********************************************************************/
105
 
106
 
107
    	//public static final String marketplaceId = "A21TJRUUN4KGV";
108
 
109
 
110
 
111
 
112
        final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
113
        final String secretAccessKey = "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";
114
 
115
        final String appName = "Test";
116
        final String appVersion = "1.0";
117
 
118
        MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
119
 
120
        /************************************************************************
121
         * Uncomment to set the appropriate MWS endpoint.
122
         ************************************************************************/
123
        // US
124
        // config.setServiceURL("https://mws.amazonservices.com");
125
        // UK
126
        // config.setServiceURL("https://mws.amazonservices.co.uk");
127
        // Germany
128
        // config.setServiceURL("https://mws.amazonservices.de");
129
        // France
130
        // config.setServiceURL("https://mws.amazonservices.fr");
131
        // Italy
132
        // config.setServiceURL("https://mws.amazonservices.it");
133
        // Japan
134
        // config.setServiceURL("https://mws.amazonservices.jp");
135
        // China
136
        // config.setServiceURL("https://mws.amazonservices.com.cn");
137
        // Canada
138
        // config.setServiceURL("https://mws.amazonservices.ca");
139
        // India
140
        config.setServiceURL("https://mws.amazonservices.in");
141
 
142
        /************************************************************************
143
         * You can also try advanced configuration options. Available options are:
144
         *
145
         *  - Signature Version
146
         *  - Proxy Host and Proxy Port
147
         *  - User Agent String to be sent to Marketplace Web Service
148
         *
149
         ***********************************************************************/
150
 
151
        /************************************************************************
152
         * Instantiate Http Client Implementation of Marketplace Web Service        
153
         ***********************************************************************/
154
 
155
        MarketplaceWebService service = new MarketplaceWebServiceClient(
156
                accessKeyId, secretAccessKey, appName, appVersion, config);
157
 
158
 
159
        /************************************************************************
160
         * Setup request parameters and uncomment invoke to try out sample for
161
         * Submit Feed
162
         ***********************************************************************/
163
 
164
        /************************************************************************
165
         * Marketplace and Merchant IDs are required parameters for all
166
         * Marketplace Web Service calls.
167
         ***********************************************************************/
168
        //final String merchantId = "AF6E300VE0X4D";
169
        final String merchantId = "AF6E3O0VE0X4D";	
170
        // marketplaces to which this feed will be submitted; look at the
171
        // API reference document on the MWS website to see which marketplaces are
172
        // included if you do not specify the list yourself
173
        final IdList marketplaces = new IdList(Arrays.asList(
174
        		"A21TJRUUN4KGV"));
175
 
176
        SubmitFeedRequest requestlisting = new SubmitFeedRequest();
177
        SubmitFeedRequest requestinventory = new SubmitFeedRequest();
178
        SubmitFeedRequest requestpricing = new SubmitFeedRequest();
179
        requestlisting.setMerchant(merchantId);
180
        requestinventory.setMerchant(merchantId);
181
        requestpricing.setMerchant(merchantId);
182
        requestlisting.setMarketplaceIdList(marketplaces);
183
        requestinventory.setMarketplaceIdList(marketplaces);
184
        requestpricing.setMarketplaceIdList(marketplaces);
185
        requestlisting.setFeedType("_POST_PRODUCT_DATA_");
186
        requestinventory.setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_");
187
        requestpricing.setFeedType("_POST_PRODUCT_PRICING_DATA_");
188
        // MWS exclusively offers a streaming interface for uploading your
189
        // feeds. This is because
190
        // feed sizes can grow to the 1GB+ range - and as your business grows
191
        // you could otherwise
192
        // silently reach the feed size where your in-memory solution will no
193
        // longer work, leaving you
194
        // puzzled as to why a solution that worked for a long time suddenly
195
        // stopped working though
196
        // you made no changes. For the same reason, we strongly encourage you
197
        // to generate your feeds to
198
        // local disk then upload them directly from disk to MWS via Java -
199
        // without buffering them in JavaFileNotFoundException
200
        // memory in their entirety.
201
        // Note: MarketplaceWebServiceClient will not retry a submit feed request
202
        // because there is no way to reset the InputStream from our client. 
203
        // To enable retry, recreate the InputStream and resubmit the feed
204
        // with the new InputStream. 
205
        //
206
        try {
207
 
208
        	createListingFeed();
209
        	createInventoryFeed();
210
        	createPricingFeed();
211
        	FileInputStream listingfis = new FileInputStream(AMAZON_LISTING_XML);
212
        	FileInputStream inventoryfis = new FileInputStream(AMAZON_INVENTORY_XML);
213
        	FileInputStream pricingfis = new FileInputStream(AMAZON_PRICING_XML);
214
        	requestlisting.setContentMD5(computeContentMD5HeaderValue(listingfis));
215
        	requestinventory.setContentMD5(computeContentMD5HeaderValue(inventoryfis));
216
        	requestpricing.setContentMD5(computeContentMD5HeaderValue(pricingfis));
217
			requestlisting.setFeedContent(listingfis);
218
			requestinventory.setFeedContent(inventoryfis);
219
			requestpricing.setFeedContent(pricingfis);
220
		} catch (FileNotFoundException e) {
221
			// TODO Auto-generated catch block
222
			e.printStackTrace();
223
		}
224
 
225
		try {
226
			invokeSubmitFeed(service,requestlisting);
227
			Thread.sleep(60000);
228
			invokeSubmitFeed(service,requestinventory);
229
			Thread.sleep(60000);
230
			invokeSubmitFeed(service,requestpricing);
231
			Thread.sleep(60000);
232
		} catch (InterruptedException e) {
233
			// TODO Auto-generated catch block
234
			e.printStackTrace();
235
		}
236
 
237
    }
238
 
239
    /**
240
     * Submit Feed request sample Uploads a file for processing together with
241
     * the necessary metadata to process the file, such as which type of feed it
242
     * is. PurgeAndReplace if true means that your existing e.g. inventory is
243
     * wiped out and replace with the contents ocf this feed - use with caution
244
     * (the default is false).
245
     * 
246
     * @param service
247
     *            instance of MarketplaceWebService service
248
     * @param request
249
     *            Action to invoke
250
     */
251
    public static void invokeSubmitFeed(MarketplaceWebService service,
252
            SubmitFeedRequest request) {
253
        try {
254
 
255
            SubmitFeedResponse response = service.submitFeed(request);
256
 
257
            System.out.println("SubmitFeed Action Response");
258
            System.out
259
            .println("=============================================================================");
260
            System.out.println();
261
 
262
            System.out.print("    SubmitFeedResponse");
263
            System.out.println();
264
            if (response.isSetSubmitFeedResult()) {
265
                System.out.print("        SubmitFeedResult");
266
                System.out.println();
267
                SubmitFeedResult submitFeedResult = response
268
                .getSubmitFeedResult();
269
                if (submitFeedResult.isSetFeedSubmissionInfo()) {
270
                    System.out.print("            FeedSubmissionInfo");
271
                    System.out.println();
272
                    FeedSubmissionInfo feedSubmissionInfo = submitFeedResult
273
                    .getFeedSubmissionInfo();
274
                    if (feedSubmissionInfo.isSetFeedSubmissionId()) {
275
                        System.out.print("                FeedSubmissionId");
276
                        System.out.println();
277
                        System.out.print("                    "
278
                                + feedSubmissionInfo.getFeedSubmissionId());
279
                        System.out.println();
280
                    }
281
                    if (feedSubmissionInfo.isSetFeedType()) {
282
                        System.out.print("                FeedType");
283
                        System.out.println();
284
                        System.out.print("                    "
285
                                + feedSubmissionInfo.getFeedType());
286
                        System.out.println();
287
                    }
288
                    if (feedSubmissionInfo.isSetSubmittedDate()) {
289
                        System.out.print("                SubmittedDate");
290
                        System.out.println();
291
                        System.out.print("                    "
292
                                + feedSubmissionInfo.getSubmittedDate());
293
                        System.out.println();
294
                    }
295
                    if (feedSubmissionInfo.isSetFeedProcessingStatus()) {
296
                        System.out
297
                        .print("                FeedProcessingStatus");
298
                        System.out.println();
299
                        System.out.print("                    "
300
                                + feedSubmissionInfo.getFeedProcessingStatus());
301
                        System.out.println();
302
                    }
303
                    if (feedSubmissionInfo.isSetStartedProcessingDate()) {
304
                        System.out
305
                        .print("                StartedProcessingDate");
306
                        System.out.println();
307
                        System.out
308
                        .print("                    "
309
                                + feedSubmissionInfo
310
                                .getStartedProcessingDate());
311
                        System.out.println();
312
                    }
313
                    if (feedSubmissionInfo.isSetCompletedProcessingDate()) {
314
                        System.out
315
                        .print("                CompletedProcessingDate");
316
                        System.out.println();
317
                        System.out.print("                    "
318
                                + feedSubmissionInfo
319
                                .getCompletedProcessingDate());
320
                        System.out.println();
321
                    }
322
                }
323
            }
324
            if (response.isSetResponseMetadata()) {
325
                System.out.print("        ResponseMetadata");
326
                System.out.println();
327
                ResponseMetadata responseMetadata = response
328
                .getResponseMetadata();
329
                if (responseMetadata.isSetRequestId()) {
330
                    System.out.print("            RequestId");
331
                    System.out.println();
332
                    System.out.print("                "
333
                            + responseMetadata.getRequestId());
334
                    System.out.println();
335
                }
336
            }
337
            System.out.println(response.getResponseHeaderMetadata());
338
            System.out.println();
339
            System.out.println();
340
 
341
        } catch (MarketplaceWebServiceException ex) {
342
 
343
            System.out.println("Caught Exception: " + ex.getMessage());
344
            System.out.println("Response Status Code: " + ex.getStatusCode());
345
            System.out.println("Error Code: " + ex.getErrorCode());
346
            System.out.println("Error Type: " + ex.getErrorType());
347
            System.out.println("Request ID: " + ex.getRequestId());
348
            System.out.print("XML: " + ex.getXML());
349
            System.out.println("ResponseHeaderMetadata: " + ex.getResponseHeaderMetadata());
350
        }
351
    }
352
 
353
public static void createListingFeed() throws CatalogServiceException, TException{
354
 
355
 
356
		File file = new File(AMAZON_LISTING_XML);
357
		AmazonEnvelope amazonenvelope =  new AmazonEnvelope();
358
		Header header = new Header();
359
		header.setDocumentVersion("1.0");
360
		header.setMerchantIdentifier("AF6E3O0VE0X4D");
361
		header.setOverrideReleaseId(null);
362
		amazonenvelope.setHeader(header);
363
		amazonenvelope.setMessageType("Product");
364
		amazonenvelope.setMarketplaceName(null);
365
		amazonenvelope.setPurgeAndReplace(false);
366
		JAXBContext context;
367
		Marshaller m=null;
368
		try {
369
			context = JAXBContext.newInstance(AmazonEnvelope.class);
370
			m = context.createMarshaller();
371
		} catch (JAXBException e1) {
372
			e1.printStackTrace();
373
		}
374
 
375
 
376
		XMLGregorianCalendar today = null;
377
		Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
378
 
379
	    int currentMonth = localCalendar.get(Calendar.MONTH);
380
	    int currentYear = localCalendar.get(Calendar.YEAR);
381
	    int currentDayOfMonth = localCalendar.get(Calendar.DAY_OF_MONTH);
382
 
383
 
384
		try {
385
		  today = DatatypeFactory.newInstance()
386
		    .newXMLGregorianCalendar(
387
		    		new GregorianCalendar(currentYear,currentMonth,currentDayOfMonth));
388
		} catch (DatatypeConfigurationException e) {
389
		  // TODO Auto-generated catch block
390
		  e.printStackTrace();
391
		}
392
 
393
		amazonenvelope.setEffectiveDate(today);
394
		List <AmazonEnvelope.Message> messages = amazonenvelope.getMessage();
395
		AmazonEnvelope.Message message1 = new AmazonEnvelope.Message();
396
		//Listings listing1 = new Listings();
397
		Product product = new Product();
398
	    CatalogClient catalogServiceClient = null;
399
		try {
400
			catalogServiceClient = new CatalogClient();
401
		} catch (TTransportException e) {
402
			// TODO Auto-generated catch block
403
			e.printStackTrace();
404
		}
405
	    Client catalogClient = catalogServiceClient.getClient();
406
	    in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(2483);
407
	    System.out.println(thriftItem);
408
	    product.setSKU(String.valueOf(thriftItem.getId()));
409
	    StandardProductID spid = new StandardProductID();
410
	    spid.setType("EAN");
411
	    spid.setValue("8806085002418");
412
	    product.setItemPackageQuantity(BigInteger.valueOf(1));	    
413
	    product.setStandardProductID(spid);
414
	    Product.DescriptionData descdata = new Product.DescriptionData();
415
	    descdata.setBrand(thriftItem.getBrand());
416
	    descdata.setAutographed(false);
417
	    	if(thriftItem.getModelName()!=null){
418
	    		descdata.setTitle(thriftItem.getModelName());	
419
	    	}
420
	    	else{
421
	    		descdata.setTitle(thriftItem.getModelNumber());
422
	    	}
423
 
424
	    descdata.setManufacturer(thriftItem.getBrand());
425
	    product.setDescriptionData(descdata);
426
	    Product.ProductData productdata = new Product.ProductData();
427
	    CE ce = new CE();
428
	    ce.setColor(thriftItem.getColor());
429
	    ce.setModel(thriftItem.getModelNumber());
430
	    ce.setModelName(thriftItem.getModelName());
431
	    HandheldOrPDA hhd = new HandheldOrPDA();
432
	    CE.ProductType productype = new CE.ProductType();
433
	    productype.setHandheldOrPDA(hhd);
434
	    ce.setProductType(productype);
435
	    productdata.setCE(ce);
436
	    product.setProductData(productdata);
437
	    message1.setMessageID(BigInteger.valueOf(41));
438
	    //listing1.setProduct(product);
439
		//message1.setListings(listing1);
440
		message1.setProduct(product);
441
		messages.add(message1);
442
		try {
443
			m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
444
			m.marshal(amazonenvelope, file);
445
			m.marshal(amazonenvelope, System.out);
446
 
447
		} catch (Exception e) {
448
			// TODO Auto-generated catch block
449
			e.printStackTrace();
450
		}
451
 
452
 
453
		}
454
 
455
public static void createInventoryFeed() throws CatalogServiceException, TException{
456
 
457
 
458
	File file = new File(AMAZON_INVENTORY_XML);
459
	AmazonEnvelope amazonenvelope =  new AmazonEnvelope();
460
	Header header = new Header();
461
	header.setDocumentVersion("1.0");
462
	header.setMerchantIdentifier("AF6E3O0VE0X4D");
463
	header.setOverrideReleaseId(null);
464
	amazonenvelope.setHeader(header);
465
	amazonenvelope.setMessageType("Inventory");
466
	amazonenvelope.setMarketplaceName(null);
467
	amazonenvelope.setPurgeAndReplace(false);
468
	JAXBContext context;
469
	Marshaller m=null;
470
	try {
471
		context = JAXBContext.newInstance(AmazonEnvelope.class);
472
		m = context.createMarshaller();
473
	} catch (JAXBException e1) {
474
		// TODO Auto-generated catch block
475
		e1.printStackTrace();
476
	}
477
 
478
	XMLGregorianCalendar today = null;
479
	Calendar localCalendar = Calendar.getInstance();
480
 
481
    int currentMonth = localCalendar.get(Calendar.MONTH);
482
    int currentYear = localCalendar.get(Calendar.YEAR);
483
    int currentDayOfMonth = localCalendar.get(Calendar.DAY_OF_MONTH);
484
 
485
	try {
486
	  today = DatatypeFactory.newInstance()
487
	    .newXMLGregorianCalendar(
488
	    		new GregorianCalendar(currentYear,currentMonth,currentDayOfMonth));
489
	} catch (DatatypeConfigurationException e) {
490
	  // TODO Auto-generated catch block
491
	  e.printStackTrace();
492
	}
493
	amazonenvelope.setEffectiveDate(today);
494
	List <AmazonEnvelope.Message> messages = amazonenvelope.getMessage();
495
	AmazonEnvelope.Message message1 = new AmazonEnvelope.Message();
496
	//Listings listing1 = new Listings();
497
	Inventory inventory = new Inventory();
498
    InventoryClient inventoryServiceClient = null;
499
	try {
500
		inventoryServiceClient = new InventoryClient();
501
	} catch (TTransportException e) {
502
		// TODO Auto-generated catch block
503
		e.printStackTrace();
504
	}
505
	in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
506
    ItemInventory availability=null;
507
	try {
508
		availability = inventoryClient.getItemInventoryByItemId(2483);
509
	} catch (InventoryServiceException e1) {
510
		// TODO Auto-generated catch block
511
		e1.printStackTrace();
512
	}
513
    if(availability.getAvailabilitySize() > 0)
514
    //inventory.setAvailable(true);
515
    inventory.setSKU("2483");
516
    inventory.setRestockDate(today);
517
    inventory.setFulfillmentLatency(BigInteger.valueOf(1));
518
    inventory.setQuantity(BigInteger.valueOf(availability.getAvailabilitySize()));
519
    //inventory.setQuantity(BigInteger.valueOf(availability.getAvailabilitySize()));
520
    inventory.setSwitchFulfillmentTo("MFN");
521
    message1.setMessageID(BigInteger.valueOf(42));
522
    //listing1.setProduct(product);
523
	//message1.setListings(listing1);
524
	message1.setInventory(inventory);
525
	messages.add(message1);
526
	try {
527
		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
528
		m.marshal(amazonenvelope, file);
529
		m.marshal(amazonenvelope, System.out);
530
 
531
	} catch (Exception e) {
532
		// TODO Auto-generated catch block
533
		e.printStackTrace();
534
	}
535
 
536
 
537
	}
538
 
539
public static void createPricingFeed() throws CatalogServiceException, TException{
540
 
541
 
542
	File file = new File(AMAZON_PRICING_XML);
543
	AmazonEnvelope amazonenvelope =  new AmazonEnvelope();
544
	Header header = new Header();
545
	header.setDocumentVersion("1.0");
546
	header.setMerchantIdentifier("AF6E3O0VE0X4D");
547
	header.setOverrideReleaseId(null);
548
	amazonenvelope.setHeader(header);
549
	amazonenvelope.setMessageType("Price");
550
	amazonenvelope.setMarketplaceName(null);
551
	amazonenvelope.setPurgeAndReplace(false);
552
	JAXBContext context;
553
	Marshaller m=null;
554
	try {
555
		context = JAXBContext.newInstance(AmazonEnvelope.class);
556
		m = context.createMarshaller();
557
	} catch (JAXBException e1) {
558
		e1.printStackTrace();
559
	}
560
	XMLGregorianCalendar today = null;
561
	Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
562
 
563
    int currentMonth = localCalendar.get(Calendar.MONTH);
564
    int currentYear = localCalendar.get(Calendar.YEAR);
565
    int currentDayOfMonth = localCalendar.get(Calendar.DAY_OF_MONTH);
566
 
567
 
568
	try {
569
	  today = DatatypeFactory.newInstance()
570
	    .newXMLGregorianCalendar(
571
	    		new GregorianCalendar(currentYear,currentMonth,currentDayOfMonth));
572
	} catch (DatatypeConfigurationException e) {
573
	  // TODO Auto-generated catch block
574
	  e.printStackTrace();
575
	}
576
	amazonenvelope.setEffectiveDate(today);
577
	List <AmazonEnvelope.Message> messages = amazonenvelope.getMessage();
578
	AmazonEnvelope.Message message1 = new AmazonEnvelope.Message();
579
	Price price = new Price();
580
	//Product product = new Product();
581
    CatalogClient catalogServiceClient = null;
582
	try {
583
		catalogServiceClient = new CatalogClient(); 
584
	} catch (TTransportException e) {
585
		// TODO Auto-generated catch block
586
		e.printStackTrace();
587
	}
588
    Client catalogClient = catalogServiceClient.getClient();
589
    List<in.shop2020.model.v1.catalog.Amazonlisted> AItem = catalogClient.getAllAmazonListedItems();
590
    System.out.println("Amazon items are" + AItem);
591
    in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(2483);
592
    price.setSKU(String.valueOf(thriftItem.getId()));
593
    OverrideCurrencyAmount overridecurrencyamount = new OverrideCurrencyAmount();
594
    overridecurrencyamount.setCurrency(BaseCurrencyCodeWithDefault.DEFAULT);
595
    overridecurrencyamount.setValue(BigDecimal.valueOf(thriftItem.getSellingPrice()));
596
    price.setStandardPrice(overridecurrencyamount);
597
    message1.setMessageID(BigInteger.valueOf(43));
598
    //listing1.setProduct(product);
599
	//message1.setListings(listing1);
600
	message1.setPrice(price);
601
	messages.add(message1);
602
	try {
603
		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
604
		m.marshal(amazonenvelope, file);
605
		m.marshal(amazonenvelope, System.out);
606
 
607
	} catch (Exception e) {
608
		// TODO Auto-generated catch block
609
		e.printStackTrace();
610
	}
611
 
612
 
613
	}
614
 
615
 
616
    public static String computeContentMD5HeaderValue( FileInputStream fis) {
617
    	try {
618
			DigestInputStream dis = new DigestInputStream( fis,
619
					MessageDigest.getInstance( "MD5" ));
620
			byte[] buffer = new byte[8192];
621
			while( dis.read( buffer ) > 0 );
622
			String md5Content = new String(Base64.encodeBase64(dis.getMessageDigest().digest())
623
				);
624
 // Effectively resets the stream to be beginning of the file via a
625
			fis.getChannel().position( 0 );
626
			return md5Content;
627
		} catch (NoSuchAlgorithmException e) {
628
			// TODO Auto-generated catch block
629
			e.printStackTrace();
630
		} catch (IOException e) {
631
			// TODO Auto-generated catch block
632
			e.printStackTrace();
633
		}
634
		return null;
635
 
636
 }
637
 
638
 
639
 
640
 
641
 
642
}