Search in sources :

Example 1 with FluentCaseInsensitiveStringsMap

use of com.ning.http.client.FluentCaseInsensitiveStringsMap in project scribejava by scribejava.

the class OAuthAsyncCompletionHandler method onCompleted.

@Override
public T onCompleted(com.ning.http.client.Response ningResponse) throws IOException {
    final FluentCaseInsensitiveStringsMap map = ningResponse.getHeaders();
    final Map<String, String> headersMap = new HashMap<>();
    for (FluentCaseInsensitiveStringsMap.Entry<String, List<String>> header : map) {
        final StringBuilder value = new StringBuilder();
        for (String str : header.getValue()) {
            value.append(str);
        }
        headersMap.put(header.getKey(), value.toString());
    }
    final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), headersMap, ningResponse.getResponseBodyAsStream());
    @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response);
    if (callback != null) {
        callback.onCompleted(t);
    }
    return t;
}
Also used : Response(com.github.scribejava.core.model.Response) HashMap(java.util.HashMap) FluentCaseInsensitiveStringsMap(com.ning.http.client.FluentCaseInsensitiveStringsMap) List(java.util.List)

Example 2 with FluentCaseInsensitiveStringsMap

use of com.ning.http.client.FluentCaseInsensitiveStringsMap in project pinpoint by naver.

the class ExecuteRequestInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    if (args.length == 0 || !(args[0] instanceof com.ning.http.client.Request)) {
        return;
    }
    final com.ning.http.client.Request httpRequest = (com.ning.http.client.Request) args[0];
    final boolean sampling = trace.canSampled();
    if (!sampling) {
        if (isDebug) {
            logger.debug("set Sampling flag=false");
        }
        if (httpRequest != null) {
            final FluentCaseInsensitiveStringsMap httpRequestHeaders = httpRequest.getHeaders();
            httpRequestHeaders.add(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
        }
        return;
    }
    trace.traceBlockBegin();
    SpanEventRecorder recorder = trace.currentSpanEventRecorder();
    TraceId nextId = trace.getTraceId().getNextTraceId();
    recorder.recordNextSpanId(nextId.getSpanId());
    recorder.recordServiceType(NingAsyncHttpClientPlugin.ASYNC_HTTP_CLIENT);
    if (httpRequest != null) {
        final FluentCaseInsensitiveStringsMap httpRequestHeaders = httpRequest.getHeaders();
        putHeader(httpRequestHeaders, Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
        putHeader(httpRequestHeaders, Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));
        putHeader(httpRequestHeaders, Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId()));
        putHeader(httpRequestHeaders, Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
        putHeader(httpRequestHeaders, Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
        putHeader(httpRequestHeaders, Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
        final String hostString = getEndpoint(httpRequest.getURI().getHost(), httpRequest.getURI().getPort());
        if (hostString != null) {
            putHeader(httpRequestHeaders, Header.HTTP_HOST.toString(), hostString);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) FluentCaseInsensitiveStringsMap(com.ning.http.client.FluentCaseInsensitiveStringsMap) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Aggregations

FluentCaseInsensitiveStringsMap (com.ning.http.client.FluentCaseInsensitiveStringsMap)2 Response (com.github.scribejava.core.model.Response)1 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)1 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)1 HashMap (java.util.HashMap)1 List (java.util.List)1