Subversion Repositories SmartDukaan

Rev

Rev 12926 | Details | Compare with Previous | Last modification | View Log | RSS feed

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