Search in sources :

Example 1 with HttpConnection

use of org.apache.commons.httpclient.HttpConnection in project pinpoint by naver.

the class HttpMethodBaseExecuteMethodInterceptor method getHost.

private String getHost(HttpMethod httpMethod, Object[] args) {
    try {
        final URI url = httpMethod.getURI();
        if (url.isAbsoluteURI()) {
            return getEndpoint(url.getHost(), url.getPort());
        }
        if (isDebug) {
            logger.debug("URI is not absolute. {}", url.getURI());
        }
        // if not found schema, use httpConnection.
        final HttpConnection httpConnection = getHttpConnection(args);
        if (httpConnection != null) {
            final String host = httpConnection.getHost();
            int port = httpConnection.getPort();
            // if port is default port number.
            if (httpConnection.getProtocol() != null && port == httpConnection.getProtocol().getDefaultPort()) {
                port = -1;
            }
            return getEndpoint(host, port);
        }
    } catch (URIException e) {
        // unexpected error, perhaps of user fault.
        logger.error("[HttpClient3] Fail get URI", e);
    }
    return null;
}
Also used : URIException(org.apache.commons.httpclient.URIException) HttpConnection(org.apache.commons.httpclient.HttpConnection) URI(org.apache.commons.httpclient.URI)

Example 2 with HttpConnection

use of org.apache.commons.httpclient.HttpConnection in project pinpoint by naver.

the class HttpMethodBaseExecuteMethodInterceptor method recordDestination.

private void recordDestination(final Trace trace, final HttpMethod httpMethod, final Object[] args) {
    final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
    try {
        final URI uri = httpMethod.getURI();
        final HttpConnection httpConnection = getHttpConnection(args);
        // if uri have schema or not found HttpConnection argument.
        if (uri.isAbsoluteURI() || httpConnection == null) {
            recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(uri.getURI(), param));
            recorder.recordDestinationId(getEndpoint(uri.getHost(), uri.getPort()));
            return;
        }
        if (isDebug) {
            logger.debug("URI is not absolute. {}", uri.getURI());
        }
        // use HttpConnection argument.
        final String host = httpConnection.getHost();
        int port = httpConnection.getPort();
        final StringBuilder httpUrl = new StringBuilder();
        final Protocol protocol = httpConnection.getProtocol();
        if (protocol != null) {
            httpUrl.append(protocol.getScheme()).append("://");
            httpUrl.append(httpConnection.getHost());
            // if port is default port number.
            if (httpConnection.getPort() == protocol.getDefaultPort()) {
                port = -1;
            } else {
                httpUrl.append(":").append(port);
            }
        }
        httpUrl.append(uri.getURI());
        recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(httpUrl.toString(), param));
        recorder.recordDestinationId(getEndpoint(host, port));
    } catch (URIException e) {
        logger.error("Fail get URI", e);
        recorder.recordDestinationId("unknown");
    }
}
Also used : URIException(org.apache.commons.httpclient.URIException) HttpConnection(org.apache.commons.httpclient.HttpConnection) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) Protocol(org.apache.commons.httpclient.protocol.Protocol) URI(org.apache.commons.httpclient.URI)

Aggregations

HttpConnection (org.apache.commons.httpclient.HttpConnection)2 URI (org.apache.commons.httpclient.URI)2 URIException (org.apache.commons.httpclient.URIException)2 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 Protocol (org.apache.commons.httpclient.protocol.Protocol)1