Search in sources :

Example 11 with RequestEntity

use of org.apache.commons.httpclient.methods.RequestEntity 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

RequestEntity (org.apache.commons.httpclient.methods.RequestEntity)11 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)6 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)5 IOException (java.io.IOException)3 EntityEnclosingMethod (org.apache.commons.httpclient.methods.EntityEnclosingMethod)3 FileRequestEntity (org.apache.commons.httpclient.methods.FileRequestEntity)3 InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)3 PostMethod (org.apache.commons.httpclient.methods.PostMethod)3 PutMethod (org.apache.commons.httpclient.methods.PutMethod)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 InputStream (java.io.InputStream)2 Message (org.apache.camel.Message)2 HttpClient (org.apache.commons.httpclient.HttpClient)2 HttpMethod (org.apache.commons.httpclient.HttpMethod)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 Serializable (java.io.Serializable)1 StringReader (java.io.StringReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1