Example usage for org.apache.commons.httpclient HttpConstants DEFAULT_CONTENT_CHARSET

List of usage examples for org.apache.commons.httpclient HttpConstants DEFAULT_CONTENT_CHARSET

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpConstants DEFAULT_CONTENT_CHARSET.

Prototype

String DEFAULT_CONTENT_CHARSET

To view the source code for org.apache.commons.httpclient HttpConstants DEFAULT_CONTENT_CHARSET.

Click 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;
                }/* ww  w  .  j  a va2s  .c om*/
                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;
                }/*  ww w  .j  a va 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;
                    }/*from w  w w  . j av a2 s .  c  o 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);
                }
            }
        }
    }

}