Example usage for org.apache.commons.httpclient.methods RequestEntity isRepeatable

List of usage examples for org.apache.commons.httpclient.methods RequestEntity isRepeatable

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods RequestEntity isRepeatable.

Prototype

public abstract boolean isRepeatable();

Source Link

Usage

From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3EntityExtractor.java

@Override
public String getEntity(HttpMethod httpMethod) {
    if (httpMethod instanceof EntityEnclosingMethod) {
        final EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) httpMethod;
        final RequestEntity entity = entityEnclosingMethod.getRequestEntity();
        if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
            try {
                String entityValue;
                String charSet = entityEnclosingMethod.getRequestCharSet();
                if (StringUtils.isEmpty(charSet)) {
                    charSet = HttpConstants.DEFAULT_CONTENT_CHARSET;
                }/*from  w  w  w. j  ava  2 s  .  c  o m*/
                if (entity instanceof ByteArrayRequestEntity || entity instanceof StringRequestEntity) {
                    entityValue = entityUtilsToString(entity, charSet);
                } else {
                    entityValue = entity.getClass() + " (ContentType:" + entity.getContentType() + ")";
                }
                return entityValue;
            } catch (Exception e) {
                if (isDebug) {
                    logger.debug("Failed to get entity. httpMethod={}", httpMethod, e);
                }
            }
        }
    }
    return null;
}

From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3RequestTrace.java

@Override
public String getEntityValue() {
    if (httpMethod instanceof EntityEnclosingMethod) {
        final EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) httpMethod;
        final RequestEntity entity = entityEnclosingMethod.getRequestEntity();
        if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
            try {
                String entityValue;
                String charSet = entityEnclosingMethod.getRequestCharSet();
                if (StringUtils.isEmpty(charSet)) {
                    charSet = HttpConstants.DEFAULT_CONTENT_CHARSET;
                }/*from  ww  w . ja v  a 2 s  .  c  o  m*/
                if (entity instanceof ByteArrayRequestEntity || entity instanceof StringRequestEntity) {
                    entityValue = entityUtilsToString(entity, charSet);
                } else {
                    entityValue = entity.getClass() + " (ContentType:" + entity.getContentType() + ")";
                }
                return entityValue;
            } catch (Exception e) {
                if (isDebug) {
                    logger.debug("Failed to get entity. httpMethod={}", this.httpMethod, e);
                }
            }
        }
    }
    return null;
}

From source file:com.baidu.oped.apm.profiler.modifier.connector.httpclient3.interceptor.ExecuteInterceptor.java

private void recordEntity(HttpMethod httpMethod, Trace trace) {
    if (httpMethod instanceof EntityEnclosingMethod) {
        final EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) httpMethod;
        final RequestEntity entity = entityEnclosingMethod.getRequestEntity();

        if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
            if (entitySampler.isSampling()) {
                try {
                    String entityValue;
                    String charSet = entityEnclosingMethod.getRequestCharSet();

                    if (charSet == null || charSet.isEmpty()) {
                        charSet = HttpConstants.DEFAULT_CONTENT_CHARSET;
                    }/*  w  w  w  . j  ava2 s .co m*/
                    if (entity instanceof ByteArrayRequestEntity) {
                        entityValue = readByteArray((ByteArrayRequestEntity) entity, charSet);
                    } else if (entity instanceof StringRequestEntity) {
                        entityValue = readString((StringRequestEntity) entity);
                    } else {
                        entityValue = entity.getClass() + " (ContentType:" + entity.getContentType() + ")";
                    }

                    trace.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, entityValue);
                } catch (Exception e) {
                    logger.debug("HttpEntityEnclosingRequest entity record fail. Caused:{}", e.getMessage(), e);
                }
            }
        }
    }

}

From source file:org.tuleap.mylyn.task.core.internal.client.rest.TuleapRestConnector.java

/**
 * Logs a debug message of the REST request/response.
 *
 * @param method/*  w w w .j a va  2  s  .  c  o m*/
 *            The method executed
 * @param bodyReceived
 *            The response body received
 */
private void debugRestCall(HttpMethod method, String bodyReceived) {
    int responseStatus = method.getStatusCode();
    StringBuilder b = new StringBuilder();
    b.append(method.getName());
    b.append(" ").append(method.getPath()); //$NON-NLS-1$
    String qs = method.getQueryString();
    if (qs != null && !qs.isEmpty()) {
        b.append('?').append(method.getQueryString());
    }
    if (method instanceof EntityEnclosingMethod) {
        RequestEntity requestEntity = ((EntityEnclosingMethod) method).getRequestEntity();
        String body = ""; //$NON-NLS-1$
        if (requestEntity.isRepeatable()) {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            try {
                requestEntity.writeRequest(os);
                body = os.toString("UTF-8"); //$NON-NLS-1$
            } catch (UnsupportedEncodingException e) {
                // Nothing to do
            } catch (IOException e) {
                // Nothing to do
            }
        }
        b.append("\nbody:\n").append(body.replaceAll(//$NON-NLS-1$
                "\"password\" *: *\".*\"", "\"password\":\"(hidden in debug)\"")); //$NON-NLS-1$ //$NON-NLS-2$
    }
    b.append("\n__________\nresponse:\n"); //$NON-NLS-1$
    b.append(method.getStatusLine()).append("\n"); //$NON-NLS-1$
    b.append("body:\n"); //$NON-NLS-1$
    b.append(bodyReceived);
    int status = IStatus.INFO;
    if (responseStatus != HttpURLConnection.HTTP_OK) {
        status = IStatus.ERROR;
    }
    this.logger.log(new Status(status, TuleapCoreActivator.PLUGIN_ID, b.toString()));
}