Subversion Repositories SmartDukaan

Rev

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