Java Code Examples for com.squareup.okhttp.Request#method()

The following examples show how to use com.squareup.okhttp.Request#method() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OkHttpClient2xAspect.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@OnBefore
public static @Nullable TraceEntry onBefore(ThreadContext context,
        @BindReceiver Object call, @BindClassMeta OkHttpClientCallInvoker callInvoker) {
    Request originalRequest = (Request) callInvoker.getOriginalRequest(call);
    if (originalRequest == null) {
        return null;
    }
    String method = originalRequest.method();
    if (method == null) {
        method = "";
    } else {
        method += " ";
    }
    String url = originalRequest.urlString();
    return context.startServiceCallEntry("HTTP", method + Uris.stripQueryString(url),
            MessageSupplier.create("http client request: {}{}", method, url), timerName);
}
 
Example 2
Source File: Client.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
private static Response execute(final Request request) {
    try {
        return new Response(HTTP_CLIENT.newCall(request).execute());
    } catch (IOException e) {
        throw new UiAutomator2Exception(request.method() + " \"" + request.urlString() + "\" " +
                "failed. ", e);
    }
}
 
Example 3
Source File: MetricsInterceptor.java    From kork with Apache License 2.0 4 votes vote down vote up
protected final Object doIntercept(Object chainObject) throws IOException {
  long start = System.nanoTime();
  boolean wasSuccessful = false;
  int statusCode = -1;

  Interceptor.Chain chain =
      (chainObject instanceof Interceptor.Chain) ? (Interceptor.Chain) chainObject : null;
  okhttp3.Interceptor.Chain chain3 =
      (chainObject instanceof okhttp3.Interceptor.Chain)
          ? (okhttp3.Interceptor.Chain) chainObject
          : null;

  Request request = (chain != null) ? chain.request() : null;
  okhttp3.Request request3 = (chain3 != null) ? chain3.request() : null;

  List<String> missingHeaders = new ArrayList<>();
  String method = null;
  URL url = null;

  try {
    String xSpinAnonymous = MDC.get(Header.XSpinnakerAnonymous);

    if (xSpinAnonymous == null && !skipHeaderCheck) {
      for (Header header : Header.values()) {
        String headerValue =
            (request != null)
                ? request.header(header.getHeader())
                : request3.header(header.getHeader());

        if (header.isRequired() && StringUtils.isEmpty(headerValue)) {
          missingHeaders.add(header.getHeader());
        }
      }
    }

    Object response;

    if (chain != null) {
      method = request.method();
      url = request.url();
      response = chain.proceed(request);
      statusCode = ((Response) response).code();
    } else {
      method = request3.method();
      url = request3.url().url();
      response = chain3.proceed(request3);
      statusCode = ((okhttp3.Response) response).code();
    }

    wasSuccessful = true;
    return response;
  } finally {
    boolean missingAuthHeaders = missingHeaders.size() > 0;

    if (missingAuthHeaders) {
      List<String> stack =
          Arrays.stream(Thread.currentThread().getStackTrace())
              .map(StackTraceElement::toString)
              .filter(x -> x.contains("com.netflix.spinnaker"))
              .collect(Collectors.toList());

      String stackTrace = String.join("\n\tat ", stack);
      log.warn(
          String.format(
              "Request %s:%s is missing %s authentication headers and will be treated as anonymous.\nRequest from: %s",
              method, url, missingHeaders, stackTrace));
    }

    recordTimer(
        registry.get(),
        url,
        System.nanoTime() - start,
        statusCode,
        wasSuccessful,
        !missingAuthHeaders);
  }
}