Subversion Repositories SmartDukaan

Rev

Rev 12459 | Details | Compare with Previous | 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 in.shop2020.feeds.products.AmazonEnvelope;
21
import in.shop2020.feeds.products.CE;
22
import in.shop2020.feeds.products.HandheldOrPDA;
23
import in.shop2020.feeds.products.Header;
24
import in.shop2020.feeds.products.Product;
25
import in.shop2020.feeds.products.StandardProductID;
26
import in.shop2020.model.v1.catalog.Amazonlisted;
27
import in.shop2020.model.v1.catalog.CatalogService.Client;
28
import in.shop2020.model.v1.catalog.CatalogServiceException;
29
import in.shop2020.thrift.clients.CatalogClient;
30
import in.shop2020.utils.GmailUtils;
31
 
32
import java.io.File;
33
import java.io.FileInputStream;
34
import java.io.FileNotFoundException;
35
import java.io.IOException;
36
import java.io.PrintWriter;
37
import java.io.StringWriter;
38
import java.math.BigInteger;
39
import java.security.DigestInputStream;
40
import java.security.MessageDigest;
41
import java.security.NoSuchAlgorithmException;
42
import java.util.ArrayList;
43
import java.util.Arrays;
44
import java.util.Calendar;
45
import java.util.GregorianCalendar;
46
import java.util.List;
47
import java.util.Random;
48
import java.util.TimeZone;
49
 
50
import javax.xml.bind.JAXBContext;
51
import javax.xml.bind.JAXBException;
52
import javax.xml.bind.Marshaller;
53
import javax.xml.datatype.DatatypeConfigurationException;
54
import javax.xml.datatype.DatatypeFactory;
55
import javax.xml.datatype.XMLGregorianCalendar;
56
import javax.xml.parsers.ParserConfigurationException;
57
 
58
import org.apache.commons.codec.binary.Base64;
59
import org.apache.thrift.TException;
60
import org.apache.thrift.transport.TTransportException;
61
import org.xml.sax.SAXException;
62
 
63
import com.amazonaws.mws.MarketplaceWebService;
64
import com.amazonaws.mws.MarketplaceWebServiceClient;
65
import com.amazonaws.mws.MarketplaceWebServiceConfig;
66
import com.amazonaws.mws.MarketplaceWebServiceException;
67
import com.amazonaws.mws.model.FeedSubmissionInfo;
68
import com.amazonaws.mws.model.IdList;
69
import com.amazonaws.mws.model.ResponseMetadata;
70
import com.amazonaws.mws.model.SubmitFeedRequest;
71
import com.amazonaws.mws.model.SubmitFeedResponse;
72
import com.amazonaws.mws.model.SubmitFeedResult;
73
 
74
/**
75
 * 
76
 * Submit Feed Samples
77
 * 
78
 * 
79
 */
80
public class SubmitFBBListingFeed {
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
	static java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
96
	static Calendar cal=GregorianCalendar.getInstance();
97
	final public static String AMAZON_FBB_LISTING_XML = "/home/amazon/FbbListing.xml";
98
	final public static String AMAZON_FBB_SKU_PREFIX = "FBB";
99
	final public static boolean PURGE_OR_REPLACE   = false;
100
	private static final BigInteger VALUE = BigInteger.valueOf(1);
101
	public static  List<Amazonlisted> aItems=null;
102
	public static List<Long> itemIdsToUpdate=null;
103
	//public static List<in.shop2020.model.v1.catalog.Item> thriftItems=null;
104
	//public static Map<Long,AmazonItem> allItemsMap = new HashMap<Long,AmazonItem>();
105
 
106
	static{
107
 
108
		CatalogClient catalogServiceClient = null;
109
		try {
110
			catalogServiceClient = new CatalogClient();
111
		} catch (TTransportException e) {
112
			e.printStackTrace();
113
		}
114
		Client catalogClient = catalogServiceClient.getClient();
115
		try {
116
			aItems = catalogClient.getAllFbbListedItems();
117
 
118
		} catch (TException e) {
119
			e.printStackTrace();
120
		}
121
 
122
	}
123
    public static void main(String... args) throws CatalogServiceException, TException {
124
 
125
        /**************************************************	**********************
126
         * Access Key ID and Secret Access Key ID, obtained from:
127
         * http://aws.amazon.com
128
         ***********************************************************************/
129
 
130
 
131
    	//public static final String marketplaceId = "A21TJRUUN4KGV";
132
 
133
 
134
 
135
 
136
        final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
137
        final String secretAccessKey = "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";
138
 
139
        final String appName = "Test";
140
        final String appVersion = "1.0";
141
 
142
        MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
143
 
144
        /************************************************************************
145
         * Uncomment to set the appropriate MWS endpoint.
146
         ************************************************************************/
147
        // US
148
        // config.setServiceURL("https://mws.amazonservices.com");
149
        // UK
150
        // config.setServiceURL("https://mws.amazonservices.co.uk");
151
        // Germany
152
        // config.setServiceURL("https://mws.amazonservices.de");
153
        // France
154
        // config.setServiceURL("https://mws.amazonservices.fr");
155
        // Italy
156
        // config.setServiceURL("https://mws.amazonservices.it");
157
        // Japan
158
        // config.setServiceURL("https://mws.amazonservices.jp");
159
        // China
160
        // config.setServiceURL("https://mws.amazonservices.com.cn");
161
        // Canada
162
        // config.setServiceURL("https://mws.amazonservices.ca");
163
        // India
164
        config.setServiceURL("https://mws.amazonservices.in");
165
 
166
        /************************************************************************
167
         * You can also try advanced configuration options. Available options are:
168
         *
169
         *  - Signature Version
170
         *  - Proxy Host and Proxy Port
171
         *  - User Agent String to be sent to Marketplace Web Service
172
         *
173
         ***********************************************************************/
174
 
175
        /************************************************************************
176
         * Instantiate Http Client Implementation of Marketplace Web Service        
177
         ***********************************************************************/
178
 
179
        MarketplaceWebService service = new MarketplaceWebServiceClient(
180
                accessKeyId, secretAccessKey, appName, appVersion, config);
181
 
182
 
183
        /************************************************************************
184
         * Setup request parameters and uncomment invoke to try out sample for
185
         * Submit Feed
186
         ***********************************************************************/
187
 
188
        /************************************************************************
189
         * Marketplace and Merchant IDs are required parameters for all
190
         * Marketplace Web Service calls.
191
         ***********************************************************************/
192
        //final String merchantId = "AF6E300VE0X4D";
193
        final String merchantId = "AF6E3O0VE0X4D";	
194
        // marketplaces to which this feed will be submitted; look at the
195
        // API reference document on the MWS website to see which marketplaces are
196
        // included if you do not specify the list yourself
197
        final IdList marketplaces = new IdList(Arrays.asList(
198
        		"A21TJRUUN4KGV"));
199
 
200
        SubmitFeedRequest requestlisting = new SubmitFeedRequest();
201
        //SubmitFeedRequest requestinventory = new SubmitFeedRequest();
202
        //SubmitFeedRequest requestpricing = new SubmitFeedRequest();
203
        requestlisting.setMerchant(merchantId);
204
        //requestinventory.setMerchant(merchantId);
205
        //requestpricing.setMerchant(merchantId);
206
        requestlisting.setMarketplaceIdList(marketplaces);
207
        //requestinventory.setMarketplaceIdList(marketplaces);
208
        //requestpricing.setMarketplaceIdList(marketplaces);
209
        requestlisting.setFeedType("_POST_PRODUCT_DATA_");
210
        //requestinventory.setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_");
211
        //requestpricing.setFeedType("_POST_PRODUCT_PRICING_DATA_");
212
        // MWS exclusively offers a streaming interface for uploading your
213
        // feeds. This is because
214
        // feed sizes can grow to the 1GB+ range - and as your business grows
215
        // you could otherwise
216
        // silently reach the feed size where your in-memory solution will no
217
        // longer work, leaving you
218
        // puzzled as to why a solution that worked for a long time suddenly
219
        // stopped working though
220
        // you made no changes. For the same reason, we strongly encourage you
221
        // to generate your feeds to
222
        // local disk then upload them directly from disk to MWS via Java -
223
        // without buffering them in JavaFileNotFoundException
224
        // memory in their entirety.
225
        // Note: MarketplaceWebServiceClient will not retry a submit feed request
226
        // because there is no way to reset the InputStream from our client. 
227
        // To enable retry, recreate the InputStream and resubmit the feed
228
        // with the new InputStream. 
229
        //
230
        try {
231
 
232
        	createFbbListingFeed();
233
        	FileInputStream listingfis = new FileInputStream(AMAZON_FBB_LISTING_XML);
234
        	requestlisting.setContentMD5(computeContentMD5HeaderValue(listingfis));
235
			requestlisting.setFeedContent(listingfis);
236
		} catch (FileNotFoundException e) {
237
			e.printStackTrace();
238
		}
239
 
240
		try {
241
				invokeSubmitFeed(service,requestlisting);
242
				Thread.sleep(10);
243
			} catch (InterruptedException e) {
244
			e.printStackTrace();
245
		}
246
 
247
    }
248
 
249
    /**
250
     * Submit Feed request sample Uploads a file for processing together with
251
     * the necessary metadata to process the file, such as which type of feed it
252
     * is. PurgeAndReplace if true means that your existing e.g. inventory is
253
     * wiped out and replace with the contents ocf this feed - use with caution
254
     * (the default is false).
255
     * 
256
     * @param service
257
     *            instance of MarketplaceWebService service
258
     * @param request
259
     *            Action to invoke
260
     */
261
	public static void invokeSubmitFeed(MarketplaceWebService service,
262
			SubmitFeedRequest request) throws InterruptedException {
263
		boolean retry = false;
264
		int retryCount = 0;
265
		while (!retry) {
266
			try {
267
 
268
				SubmitFeedResponse response = service.submitFeed(request);
269
 
270
				System.out.println("SubmitFeed Action Response");
271
				System.out
272
				.println("=============================================================================");
273
				System.out.println();
274
 
275
				System.out.print("    SubmitFeedResponse");
276
				System.out.println();
277
				FeedSubmissionInfo feedSubmissionInfo=null;
278
				if (response.isSetSubmitFeedResult()) {
279
					System.out.print("        SubmitFeedResult");
280
					System.out.println();
281
					SubmitFeedResult submitFeedResult = response
282
					.getSubmitFeedResult();
283
					if (submitFeedResult.isSetFeedSubmissionInfo()) {
284
						System.out.print("            FeedSubmissionInfo");
285
						System.out.println();
286
						feedSubmissionInfo = submitFeedResult
287
						.getFeedSubmissionInfo();
288
						if (feedSubmissionInfo.isSetFeedSubmissionId()) {
289
							System.out.print("                FeedSubmissionId");
290
							System.out.println();
291
							System.out.print("                    "
292
									+ feedSubmissionInfo.getFeedSubmissionId());
293
 
294
							System.out.println();
295
						}
296
						if (feedSubmissionInfo.isSetFeedType()) {
297
							System.out.print("                FeedType");
298
							System.out.println();
299
							System.out.print("                    "
300
									+ feedSubmissionInfo.getFeedType());
301
							System.out.println();
302
						}
303
						if (feedSubmissionInfo.isSetSubmittedDate()) {
304
							System.out.print("                SubmittedDate");
305
							System.out.println();
306
							System.out.print("                    "
307
									+ feedSubmissionInfo.getSubmittedDate());
308
							System.out.println();
309
						}
310
						if (feedSubmissionInfo.isSetFeedProcessingStatus()) {
311
							System.out
312
							.print("                FeedProcessingStatus");
313
							System.out.println();
314
							System.out.print("                    "
315
									+ feedSubmissionInfo.getFeedProcessingStatus());
316
							System.out.println();
317
						}
318
						if (feedSubmissionInfo.isSetStartedProcessingDate()) {
319
							System.out
320
							.print("                StartedProcessingDate");
321
							System.out.println();
322
							System.out
323
							.print("                    "
324
									+ feedSubmissionInfo
325
									.getStartedProcessingDate());
326
							System.out.println();
327
						}
328
						if (feedSubmissionInfo.isSetCompletedProcessingDate()) {
329
							System.out
330
							.print("                CompletedProcessingDate");
331
							System.out.println();
332
							System.out.print("                    "
333
									+ feedSubmissionInfo
334
									.getCompletedProcessingDate());
335
							System.out.println();
336
						}
337
					}
338
				}
339
				if (response.isSetResponseMetadata()) {
340
					System.out.print("        ResponseMetadata");
341
					System.out.println();
342
					ResponseMetadata responseMetadata = response
343
					.getResponseMetadata();
344
					if (responseMetadata.isSetRequestId()) {
345
						System.out.print("            RequestId");
346
						System.out.println();
347
						System.out.print("                "
348
								+ responseMetadata.getRequestId());
349
						System.out.println();
350
					}
351
				}
352
				System.out.println(response.getResponseHeaderMetadata());
353
				retry =true;
354
				System.out.println("============Sleeping For 10 Minutes=============");
355
				Thread.sleep(600000);
356
				CheckFeedSubmission checkResult = new CheckFeedSubmission();
357
				ProcessFeed feedProcessingResult=null;
358
				int checkResultCount=0;
359
				try {
360
					while (feedProcessingResult == null){
361
						feedProcessingResult = checkResult.getResult(feedSubmissionInfo.getFeedSubmissionId(),"FbbListingFeed",0,itemIdsToUpdate);
362
						if (feedProcessingResult == null){
363
							checkResultCount++;
364
							if (checkResultCount == 5){
365
								String text = "";
12969 amit.gupta 366
								String[] sendTo = {  "kshitij.sood@shop2020.in","chandan.kumar@shop2020.in"};
12459 kshitij.so 367
								String emailSubjectTxt = "Unable To Receive FBB Listing Feed Result.Submission Id "+feedSubmissionInfo.getFeedSubmissionId();
368
								String emailFromAddress = "build@shop2020.in";
369
								String password = "cafe@nes";
370
								GmailUtils mailer = new GmailUtils();
371
								try {
372
									mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
373
								}
374
								catch (Exception e) {
375
									e.printStackTrace();
376
								}
377
								System.exit(1);
378
							}
379
							System.out.println("=====Feed Result Not Ready Retry Again After 5 Minutes=============");
380
							Thread.sleep(600000);
381
 
382
						}
383
 
384
					}
385
 
386
				} catch (ParserConfigurationException e) {
387
					e.printStackTrace();
388
				} catch (SAXException e) {
389
					e.printStackTrace();
390
				} catch (IOException e) {
391
					e.printStackTrace();
392
				}
393
				String emailSubjectTxt="";
394
				String[] sendTo;
395
				if (Boolean.valueOf(feedProcessingResult.getResult())){
396
					emailSubjectTxt = "FBB Listing Feed Success "+sdf.format(cal.getTime());
12969 amit.gupta 397
					sendTo = new String[]{  "kshitij.sood@shop2020.in","chandan.kumar@shop2020.in"};
12459 kshitij.so 398
				}
399
				else {
400
					emailSubjectTxt = "FBB Listing Feed Failure "+sdf.format(cal.getTime());
12969 amit.gupta 401
					sendTo = new String[]{  "kshitij.sood@shop2020.in","chandan.kumar@shop2020.in"};
12459 kshitij.so 402
				}
403
				String text = "MessagesProcessed "+feedProcessingResult.getProcessed()+"\n"+"MessagesSuccessful "+feedProcessingResult.getSuccess()+"\n"+"" +
404
				"MessagesWithError "+feedProcessingResult.getError()+"\n"+"MessagesWithWarning "+feedProcessingResult.getWarn(); 
405
				String emailFromAddress = "build@shop2020.in";
406
				String password = "cafe@nes";
407
				GmailUtils mailer = new GmailUtils();
408
				try {
409
					mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, "/home/amazon/feedSubmission"+"FbbListingFeed"+"Result.xml" );
410
				}
411
				catch (Exception ex) {
412
					ex.printStackTrace();
413
				}
414
				System.out.println();
415
			} catch (MarketplaceWebServiceException ex) {
416
 
417
				System.out.println("Caught Exception: " + ex.getMessage());
418
				System.out.println("Response Status Code: " + ex.getStatusCode());
419
				System.out.println("Error Code: " + ex.getErrorCode());
420
				System.out.println("Error Type: " + ex.getErrorType());
421
				System.out.println("Request ID: " + ex.getRequestId());
422
				System.out.print("XML: " + ex.getXML());
423
				System.out.println("ResponseHeaderMetadata: " + ex.getResponseHeaderMetadata());
424
 
425
				if (retryCount == 2) {
426
					StringWriter errors = new StringWriter();
427
					ex.printStackTrace(new PrintWriter(errors));
428
					String text = errors.toString(); 
12969 amit.gupta 429
					String[] sendTo = {  "kshitij.sood@shop2020.in","chandan.kumar@shop2020.in"};
12459 kshitij.so 430
					String emailSubjectTxt = "Unable To Send FBB Listing Feed ";
431
					String emailFromAddress = "build@shop2020.in";
432
					String password = "cafe@nes";
433
					GmailUtils mailer = new GmailUtils();
434
					try {
435
						mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
436
					}
437
					catch (Exception e) {
438
						e.printStackTrace();
439
					}
440
					System.exit(1);
441
				}
442
				retryCount++;
443
				Thread.sleep(60000);
444
			}
445
		}
446
	}
447
 
448
    public static void createFbbListingFeed() throws CatalogServiceException, TException{
449
 
450
    	File file = new File(AMAZON_FBB_LISTING_XML);
451
    	AmazonEnvelope amazonenvelope =  new AmazonEnvelope();
452
    	Header header = new Header();
453
    	header.setDocumentVersion("1.0");
454
    	header.setMerchantIdentifier("AF6E3O0VE0X4D");
455
    	header.setOverrideReleaseId(null);
456
    	amazonenvelope.setHeader(header);
457
    	amazonenvelope.setMessageType("Product");
458
    	amazonenvelope.setMarketplaceName(null);
459
    	amazonenvelope.setPurgeAndReplace(PURGE_OR_REPLACE);
460
    	JAXBContext context;
461
    	Marshaller m=null;
462
    	try {
463
    		context = JAXBContext.newInstance(AmazonEnvelope.class);
464
    		m = context.createMarshaller();
465
    	} catch (JAXBException e) {
466
    		e.printStackTrace();
467
    	}
468
 
469
 
470
    	XMLGregorianCalendar today = null;
471
    	Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
472
 
473
    	int currentMonth = localCalendar.get(Calendar.MONTH);
474
    	int currentYear = localCalendar.get(Calendar.YEAR);
475
    	int currentDayOfMonth = localCalendar.get(Calendar.DAY_OF_MONTH);
476
 
477
 
478
    	try {
479
    		today = DatatypeFactory.newInstance()
480
    		.newXMLGregorianCalendar(
481
    				new GregorianCalendar(currentYear,currentMonth,currentDayOfMonth));
482
    	} catch (DatatypeConfigurationException e) {
483
    		e.printStackTrace();
484
    	}
485
 
486
    	amazonenvelope.setEffectiveDate(today);
487
    	List <AmazonEnvelope.Message> messages = amazonenvelope.getMessage();
488
    	int count=0;
489
    	itemIdsToUpdate = new ArrayList<Long>();
490
    	for(Amazonlisted AItem:aItems){
491
    		//long itemid = AItem.getItemid();
492
    		//if(allItemsMap.get(Long.valueOf(itemid))!=null){
493
    		AmazonEnvelope.Message message = new AmazonEnvelope.Message();
494
    		Product product = new Product();
495
    		product.setSKU(AMAZON_FBB_SKU_PREFIX+String.valueOf(AItem.getItemid()));
496
    		/*System.out.println("Amazon Item id is " + AItem);
497
				    System.out.println("Amazon Item id is " + AItem.getItemid());
498
				    System.out.println("Item is " + item);
499
				    System.out.println("Item id is " + item.getId());
500
				    System.out.println("Item color is " + item.getColor());*/
501
    		/*if(AItem.getEan().length() > 0){
502
					    	StandardProductID spid = new StandardProductID();
503
					    	spid.setType("EAN");
504
						    spid.setValue(AItem.getEan());
505
						    product.setStandardProductID(spid);
506
					    }
507
				    else{
508
				    	if(AItem.getUpc().length() > 0){
509
					    	StandardProductID spid = new StandardProductID();
510
					    	spid.setType("UPC");
511
						    spid.setValue(AItem.getUpc());
512
						    product.setStandardProductID(spid);
513
				    	}
514
				    }*/
515
    		StandardProductID spid = new StandardProductID();
516
	    	spid.setType("ASIN");
517
		    spid.setValue(AItem.getAsin());
518
		    product.setStandardProductID(spid);
519
		    Product.DescriptionData descdata = new Product.DescriptionData();
520
		    descdata.setMaxOrderQuantity(VALUE);
521
    		//product.setItemPackageQuantity(BigInteger.valueOf(1));
522
    		/*if(AItem.getCategory_code()==10002)
523
    		{//Buisness Phones
524
    			descdata.getRecommendedBrowseNode().add(BigInteger.valueOf(1389432031));
525
    			descdata.getRecommendedBrowseNode().add(BigInteger.valueOf(1805560031));
526
    		}
527
    		if(AItem.getCategory_code()==10003)
528
    		{//High End media Phones
529
    			descdata.getRecommendedBrowseNode().add(BigInteger.valueOf(1389432031));
530
    			descdata.getRecommendedBrowseNode().add(BigInteger.valueOf(1805560031));
531
    		}
532
    		if(AItem.getCategory_code()==10004)
533
    		{//Low End media Phones
534
    			descdata.getRecommendedBrowseNode().add(BigInteger.valueOf(1389432031));
535
    			descdata.getRecommendedBrowseNode().add(BigInteger.valueOf(1805559031));
536
    		}
537
 
538
    		if(AItem.getCategory_code()==10005)
539
    		{//Basic Phones
540
    			descdata.getRecommendedBrowseNode().add(BigInteger.valueOf(1389432031));
541
    			descdata.getRecommendedBrowseNode().add(BigInteger.valueOf(1805559031));
542
    		}
543
    		descdata.setMfrPartNumber(AItem.getPart_number());
544
    		descdata.setBrand(AItem.getBrand());
545
    		descdata.setAutographed(false);
546
    		descdata.setTitle(AItem.getName());	
547
    		descdata.setManufacturer(AItem.getManufacturer_name());
548
    		descdata.setIsGiftWrapAvailable(true);
549
    		descdata.setIsGiftMessageAvailable(true);*/
550
    		//product.setDescriptionData(descdata);
551
    		//Product.ProductData productdata = new Product.ProductData();
552
    		//CE ce = new CE();
553
    		//ce.setColor(AItem.getColor());	
554
    		//HandheldOrPDA hhd = new HandheldOrPDA();
555
    		//CE.ProductType productype = new CE.ProductType();
556
    		//productype.setHandheldOrPDA(hhd);
557
    		//ce.setProductType(productype);
558
    		//productdata.setCE(ce);
559
    		//product.setProductData(productdata);
560
    		product.setProductTaxCode(AItem.getFbbtaxCode());
561
    		Random rand = new Random();
562
    		message.setMessageID(BigInteger.valueOf(Math.abs(rand.nextInt())));
563
    		message.setProduct(product);
564
    		message.setOperationType("Update");
565
    		messages.add(message);
566
    		itemIdsToUpdate.add(AItem.getItemid());
567
    		count++;
568
    	}	
569
 
570
 
571
    	try {
572
    		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
573
    		m.marshal(amazonenvelope, file);
574
    		m.marshal(amazonenvelope, System.out);
575
 
576
    	} catch (Exception e) {
577
    		e.printStackTrace();
578
    	}
579
 
580
    }
581
 
582
 
583
 
584
    public static String computeContentMD5HeaderValue( FileInputStream fis) {
585
    	try {
586
			DigestInputStream dis = new DigestInputStream( fis,
587
					MessageDigest.getInstance( "MD5" ));
588
			byte[] buffer = new byte[8192];
589
			while( dis.read( buffer ) > 0 );
590
			String md5Content = new String(Base64.encodeBase64(dis.getMessageDigest().digest())
591
				);
592
			// Effectively resets the stream to be beginning of the file via a
593
			fis.getChannel().position( 0 );
594
			return md5Content;
595
		} catch (NoSuchAlgorithmException e) {
596
			e.printStackTrace();
597
		} catch (IOException e) {
598
			e.printStackTrace();
599
		}
600
		return null;
601
 
602
 }
603
 
604
 
605
 
606
 
607
 
608
}