Subversion Repositories SmartDukaan

Rev

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