Subversion Repositories SmartDukaan

Rev

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