buildframework/helium/sf/java/diamonds/src/com/nokia/helium/diamonds/DiamondsClient.java
author wbernard
Thu, 22 Jul 2010 17:08:43 +0300
branchhelium-9.0
changeset 618 df88fead2976
parent 587 85df38eb4012
child 628 7c4a911dc066
permissions -rw-r--r--
helium_9.0.5-4399343f4f50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
/*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
* All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
* This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
* which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
* Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
* Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
* Description:  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
*/
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
package com.nokia.helium.diamonds;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import org.apache.commons.httpclient.HttpClient;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import org.apache.commons.httpclient.HttpException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import org.apache.commons.httpclient.methods.FileRequestEntity;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import org.apache.commons.httpclient.methods.PostMethod;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import org.apache.commons.httpclient.methods.RequestEntity;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import org.apache.commons.lang.StringUtils;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import org.apache.log4j.Logger;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import com.nokia.helium.core.EmailDataSender;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
import java.io.IOException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
import java.io.File;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
/**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
 * Diamonds client used to connect to get build id and also to send the build
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
 * results
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
public class DiamondsClient {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
    private static final int INT_SERV_ERROR = 500;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
    private static final int SERV_NOT_FOUND = 404;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
    private static final int SERV_OK = 200;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
    private boolean isRecordOnly;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
    private Logger log = Logger.getLogger(DiamondsClient.class);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
    private String host;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
    private String port;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
    private String path;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
    private String emailID;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
    private HttpClient httpClient;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
    public DiamondsClient(String hst, String prt, String pth, String mailID) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        host = hst;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        port = prt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        path = pth;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
        emailID = mailID;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        httpClient = new HttpClient();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    private int executeMethod(PostMethod postMethod) throws DiamondsException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        int result = 0;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
            result = httpClient.executeMethod(postMethod);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        } catch (IOException e) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
            isRecordOnly = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
            throw new DiamondsException("IOException while sending http request." + e.getMessage());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
            // e.printStackTrace();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        return result;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
    private String checkForProtocol(String url) throws DiamondsException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
        String retURL = url;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
        if (!StringUtils.containsIgnoreCase(url, "http://")) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
            retURL = "http://" + url;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
        return retURL;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
    private String getURL() throws DiamondsException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        return getURL(null);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
    private String getURL(String subPath) throws DiamondsException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
        String urlPath = path;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
        if (subPath != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
            urlPath = subPath;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
        return checkForProtocol("http://" + host + ":" + port + urlPath);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
    private PostMethod getPostMethod(String fileName, String urlPath) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
        // Get the Diamonds XML-file which is to be exported
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
        File input = new File(fileName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
        // Prepare HTTP post
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
        PostMethod post = new PostMethod(urlPath);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
        // Request content will be retrieved directly
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
        // from the input stream
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
        RequestEntity entity = new FileRequestEntity(input,
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
                "text/xml; charset=ISO-8859-1");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
        post.setRequestEntity(entity);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
        return post;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
    private int processPostMethodResult(int result) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
        // Log status code
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
        switch (result) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
        case INT_SERV_ERROR:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
            // log.error("Internal server error");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
            break;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
        case SERV_NOT_FOUND:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
            // log.error("Server not found");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
            break;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
        case SERV_OK:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
            // log.info("Connection to diamonds server - OK");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
            break;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
        default:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
            // log.debug("Response code: " + result);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
        return result;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
     * @param fileName
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
     *            Filename to export to Diamonds
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
     * @return diamonds build id
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
    public String getBuildId(String fileName) throws DiamondsException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
        String diamondsBuildID = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
        PostMethod postMethod = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
        // Get HTTP client
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
        // MyHttpClient httpclient = createHttpClient();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
        // Execute post request
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
            if (!isRecordOnly) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
                String strURL = getURL();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
                log.debug("strURL:" + strURL);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
                postMethod = getPostMethod(fileName, strURL);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
                log.debug("postmethod:" + postMethod);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
                int postMethodResult = httpClient.executeMethod(postMethod);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
                log.debug("postmethod-result:" + postMethodResult);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
                int result = processPostMethodResult(postMethodResult);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
                if (result == SERV_OK) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
                    // Display and save response code which functions as a id for
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
                    // the build.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
                    diamondsBuildID = postMethod.getResponseBodyAsString();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
                    log.debug("diamondsBuildID: " + diamondsBuildID);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
                } else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
                    isRecordOnly = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
                    log.error("Diamonds data not sent, because of connection failure.");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
                    //throw new DiamondsException("Connection Failed");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
        } catch (HttpException ex) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
            isRecordOnly = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
            log.error("Diamonds data not sent: " + ex.getMessage());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
            log.debug("Diamonds data not sent:s", ex);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
        } catch (IOException ex) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
            isRecordOnly = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
            log.error("Diamonds data not sent: " + ex.getMessage());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
            log.debug("Diamonds data not sent:", ex);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
        } finally {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
            // Release current connection to the connection pool once you are
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
            // done
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
            if (postMethod != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
                postMethod.releaseConnection();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
        return diamondsBuildID;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
    public int sendData(String fileName, String urlPath) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
        PostMethod postMethod = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
        int result = -1;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
        if (urlPath != null && !isRecordOnly) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
            try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
                String strURL = getURL(urlPath);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
                postMethod = getPostMethod(fileName, strURL);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
                result = processPostMethodResult(httpClient
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
                        .executeMethod(postMethod));
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   200
            } catch (IllegalArgumentException e) {
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   201
                // Catching this exception is needed because it is raised by httpclient
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   202
                // library if the server is under update.
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   203
                log.error("sendData:The final data via http not sent because errors:IllegalArgumentException ", e);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
            } catch (DiamondsException e) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
                log.error("sendData:The final data via http not sent because errors:DiamondsException ", e);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
            } catch (IOException e) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
                log.error("sendData:The final data via http not sent because errors:IOException ", e);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
        return result;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
    public int sendDataByMail(String fileName, String smtpServer,
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
            String ldapServer) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
        log.debug("DiamondsClient:sendDataByEmail:emailID" + emailID);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
        EmailDataSender emailSender = new EmailDataSender(emailID, smtpServer,
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
                ldapServer);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
        log.debug("DiamondsClient:sendDataByEmail: " + fileName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
        emailSender.sendData("diamonds", fileName, "application/xml",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
                "[DIAMONDS_DATA]", null);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
        log.debug("DiamondsClient:sendDataByEmail:succeeds");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
        return 0;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
}