List of usage examples for com.squareup.okhttp Request url
HttpUrl url
To view the source code for com.squareup.okhttp Request url.
Click Source Link
From source file:com.navercorp.pinpoint.plugin.okhttp.interceptor.HttpEngineSendRequestMethodInterceptor.java
License:Apache License
@Override public void after(Object target, Object[] args, Object result, Throwable throwable) { if (isDebug) { logger.afterInterceptor(target, args); }/*from ww w .j a v a2 s . com*/ final Trace trace = traceContext.currentTraceObject(); if (trace == null) { return; } if (!validate(target)) { return; } try { SpanEventRecorder recorder = trace.currentSpanEventRecorder(); recorder.recordApi(methodDescriptor); recorder.recordException(throwable); // typeCheck validate(); Request request = ((UserRequestGetter) target)._$PINPOINT$_getUserRequest(); if (request != null) { try { recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(request.urlString(), param)); final String endpoint = getDestinationId(request.url()); recorder.recordDestinationId(endpoint); } catch (Exception ignored) { logger.warn("Failed to invoke of request.url(). {}", ignored.getMessage()); } recordRequest(trace, request, throwable); } // clear attachment. InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation(); if (invocation != null && invocation.getAttachment() != null) { invocation.removeAttachment(); } } finally { trace.traceBlockEnd(); } }
From source file:com.navercorp.pinpoint.plugin.okhttp.v2.interceptor.HttpEngineSendRequestMethodInterceptor.java
License:Apache License
@Override public void after(Object target, Object[] args, Object result, Throwable throwable) { if (isDebug) { logger.afterInterceptor(target, args); }/*from w w w . ja va 2 s . co m*/ final Trace trace = traceContext.currentTraceObject(); if (trace == null) { return; } if (!validate(target)) { return; } try { final SpanEventRecorder recorder = trace.currentSpanEventRecorder(); recorder.recordApi(methodDescriptor); recorder.recordException(throwable); // clear attachment. final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation(); final Object attachment = getAttachment(invocation); if (attachment != null) { invocation.removeAttachment(); } // typeCheck validate(); final Request request = ((UserRequestGetter) target)._$PINPOINT$_getUserRequest(); if (request != null) { try { recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(request.urlString(), param)); final String endpoint = getDestinationId(request.url()); recorder.recordDestinationId(endpoint); } catch (Exception ignored) { logger.warn("Failed to invoke of request.url(). {}", ignored.getMessage()); } recordRequest(trace, request, throwable); } } finally { trace.traceBlockEnd(); } }
From source file:com.navercorp.pinpoint.plugin.okhttp.v2.OkHttpClientRequestAdaptor.java
License:Apache License
@Override public String getDestinationId(Request request) { final URL httpUrl = request.url(); if (httpUrl == null || httpUrl.getHost() == null) { return "Unknown"; }/*w ww. ja va 2 s . c o m*/ final int port = EndPointUtils.getPort(httpUrl.getPort(), httpUrl.getDefaultPort()); return HostAndPort.toHostAndPortString(httpUrl.getHost(), port); }
From source file:com.netflix.spinnaker.okhttp.OkHttpMetricsInterceptor.java
License:Apache License
@Override public Response intercept(Interceptor.Chain chain) throws IOException { long start = System.nanoTime(); boolean wasSuccessful = false; int statusCode = -1; Request request = chain.request(); try {/*ww w.j a v a 2 s. c om*/ Response response = chain.proceed(request); wasSuccessful = true; statusCode = response.code(); return response; } finally { recordTimer(registry, request.url(), System.nanoTime() - start, statusCode, wasSuccessful); } }
From source file:com.thoughtworks.lean.oauth2.OAuthServiceWrapper.java
License:Open Source License
public String getAccessToken(String code, String callbackUrl) throws IOException { Request request = new Request.Builder() .url(String.format("%s?redirect_uri=%s&client_id=%s&client_secret=%s&code=%s", getAccessTokenEndpoint(), URLEncoder.encode(callbackUrl, "UTF-8"), settings.clientId(), settings.clientSecret(), URLEncoder.encode(code, "UTF-8") )).build();//from w w w . ja v a2s .c om LOGGER.info("request uri: {}", request.url().toString()); Response response = client.newCall(request).execute(); return responseToAccessToken(response.body().string()); }
From source file:com.yandex.disk.rest.LoggingInterceptor.java
License:Apache License
@Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); String hash = Integer.toHexString(chain.hashCode()); String sendPrefix = hash + SEND_PREFIX; String receivePrefix = hash + RECEIVE_PREFIX; if (logWire) { RequestBody requestBody = request.body(); if (requestBody != null) { logger.info(sendPrefix + "request: " + requestBody); Buffer buffer = new Buffer(); requestBody.writeTo(buffer); byte[] requestBuffer = ByteStreams.toByteArray(buffer.inputStream()); logBuffer(sendPrefix, requestBuffer); }/*w ww . j a v a 2 s . c o m*/ request = request.newBuilder().removeHeader("Accept-Encoding").addHeader("Accept-Encoding", "").build(); } logger.info(sendPrefix + request.method() + " " + request.url()); logger.info(sendPrefix + "on " + chain.connection()); logHeaders(sendPrefix, request.headers()); Response response = chain.proceed(request); logger.info(receivePrefix + response.protocol() + " " + response.code() + " " + response.message()); logHeaders(receivePrefix, response.headers()); if (logWire) { ResponseBody body = response.body(); byte[] responseBuffer = ByteStreams.toByteArray(body.byteStream()); response = response.newBuilder().body(ResponseBody.create(body.contentType(), responseBuffer)).build(); logBuffer(receivePrefix, responseBuffer); } return response; }
From source file:feign.okhttp.OkHttpClient.java
License:Apache License
static Request toOkHttpRequest(feign.Request input) { Request.Builder requestBuilder = new Request.Builder(); requestBuilder.url(input.url()); MediaType mediaType = null;//from w ww. j a v a2s . c om boolean hasAcceptHeader = false; for (String field : input.headers().keySet()) { if (field.equalsIgnoreCase("Accept")) { hasAcceptHeader = true; } for (String value : input.headers().get(field)) { if (field.equalsIgnoreCase("Content-Type")) { mediaType = MediaType.parse(value); if (input.charset() != null) { mediaType.charset(input.charset()); } } else { requestBuilder.addHeader(field, value); } } } // Some servers choke on the default accept string. if (!hasAcceptHeader) { requestBuilder.addHeader("Accept", "*/*"); } RequestBody body = input.body() != null ? RequestBody.create(mediaType, input.body()) : null; requestBuilder.method(input.method(), body); return requestBuilder.build(); }
From source file:io.apiman.gateway.platforms.servlet.connectors.ok.HttpURLConnectionImpl.java
License:Apache License
/** * Aggressively tries to get the final HTTP response, potentially making * many HTTP requests in the process in order to cope with redirects and * authentication.// ww w . j av a 2 s. c o m */ private HttpEngine getResponse() throws IOException { initHttpEngine(); if (httpEngine.hasResponse()) { return httpEngine; } while (true) { if (!execute(true)) { continue; } Response response = httpEngine.getResponse(); Request followUp = httpEngine.followUpRequest(); if (followUp == null) { httpEngine.releaseConnection(); return httpEngine; } if (++followUpCount > HttpEngine.MAX_FOLLOW_UPS) { throw new ProtocolException("Too many follow-up requests: " + followUpCount); } // The first request was insufficient. Prepare for another... url = followUp.url(); requestHeaders = followUp.headers().newBuilder(); // Although RFC 2616 10.3.2 specifies that a HTTP_MOVED_PERM redirect // should keep the same method, Chrome, Firefox and the RI all issue GETs // when following any redirect. Sink requestBody = httpEngine.getRequestBody(); if (!followUp.method().equals(method)) { requestBody = null; } if (requestBody != null && !(requestBody instanceof RetryableSink)) { throw new HttpRetryException("Cannot retry streamed HTTP body", responseCode); } if (!httpEngine.sameConnection(followUp.url())) { httpEngine.releaseConnection(); } Connection connection = httpEngine.close(); httpEngine = newHttpEngine(followUp.method(), connection, (RetryableSink) requestBody, response); } }
From source file:io.minio.RequestSigner.java
License:Apache License
private String getRegion(Request request) { String host = request.url().getHost(); return Regions.INSTANCE.getRegion(host); }
From source file:net.goldenspiral.fetlifeoss.rest.interceptors.LoggingInterceptor.java
License:Open Source License
@Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); long t1 = System.nanoTime(); if (enabled) { Log.i(TAG, String.format("Sending request %s on %s%n%s", request.url(), chain.connection(), request.headers()));//w ww.j a va2 s .c om } Response response = chain.proceed(request); long t2 = System.nanoTime(); if (enabled) { Log.i(TAG, String.format("Received response for %s in %.1fms%n%s", response.request().url(), (t2 - t1) / 1e6d, response.headers())); } return response; }