Search in sources :

Example 1 with NoHttpResponseException

use of org.apache.commons.httpclient.NoHttpResponseException in project zm-mailbox by Zimbra.

the class ElasticSearchConnector method executeMethod.

public int executeMethod(HttpMethod method) throws IndexStoreException, IOException {
    String reqBody = "";
    if (ZimbraLog.elasticsearch.isTraceEnabled() && method instanceof EntityEnclosingMethod) {
        EntityEnclosingMethod eem = (EntityEnclosingMethod) method;
        RequestEntity re = eem.getRequestEntity();
        if (re instanceof StringRequestEntity) {
            StringRequestEntity sre = (StringRequestEntity) re;
            reqBody = Strings.nullToEmpty(sre.getContent());
            if (reqBody.length() > 0) {
                reqBody = String.format("\nREQUEST BODY=%s", reqBody);
            }
        }
    }
    try {
        HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
        statusCode = client.executeMethod(method);
    } catch (ConnectException ce) {
        throw new ZimbraElasticSearchDownException(ce);
    } catch (NoHttpResponseException nhre) {
        // them after retrying a number of times.
        throw new ZimbraElasticSearchNoResponseException(nhre);
    }
    body = method.getResponseBodyAsString();
    ZimbraLog.elasticsearch.trace("ElasticSearch request:%s %s - statusCode=%d%s\nRESPONSE BODY=%s", method.getName(), method.getURI(), statusCode, reqBody, body);
    return statusCode;
}
Also used : NoHttpResponseException(org.apache.commons.httpclient.NoHttpResponseException) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) EntityEnclosingMethod(org.apache.commons.httpclient.methods.EntityEnclosingMethod) HttpClient(org.apache.commons.httpclient.HttpClient) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) RequestEntity(org.apache.commons.httpclient.methods.RequestEntity) ConnectException(java.net.ConnectException)

Aggregations

ConnectException (java.net.ConnectException)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 NoHttpResponseException (org.apache.commons.httpclient.NoHttpResponseException)1 EntityEnclosingMethod (org.apache.commons.httpclient.methods.EntityEnclosingMethod)1 RequestEntity (org.apache.commons.httpclient.methods.RequestEntity)1 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)1