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

The following examples show how to use com.squareup.okhttp.Request#urlString() . 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: Log.java    From tencentcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
  Request request = chain.request();
  String req = ("send request, request url: " + request.urlString() + ". request headers information: " + request.headers().toString());
  req = req.replaceAll("\n", ";");
  this.debug(req);
  Response response = chain.proceed(request);
  String resp = ("recieve response, response url: " + response.request().urlString() + ", response headers: " + response.headers().toString() + ",response body information: " + response.body().toString());
  resp = resp.replaceAll("\n", ";");
  this.debug(resp);
  return response;
}
 
Example 3
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 4
Source File: TokenRefreshInterceptorTest.java    From wear-notify-for-reddit with Apache License 2.0 5 votes vote down vote up
private Matcher<Request> hasUrl(String url) {
    return new FeatureMatcher<Request, String>(equalTo(url), "Url", "Unexpected url") {
        @Override protected String featureValueOf(Request actual) {
            return actual.urlString();
        }
    };
}
 
Example 5
Source File: ApiKeyAuth.java    From huaweicloud-cs-sdk with Apache License 2.0 4 votes vote down vote up
public Request applyToParams(Request request) {
    if (serviceName == null || region == null || accessKey == null || secretKey == null) {
        return request;
    }
    DefaultRequest reqForSigner = new DefaultRequest(this.serviceName);
    try {
        reqForSigner.setEndpoint(request.uri());

        reqForSigner.setHttpMethod(HttpMethodName.valueOf(request.method()));

        if(!projectId.isEmpty()) {
            reqForSigner.addHeader("X-Project-Id", projectId);
        }

        // add query string
        String urlString = request.urlString();
        if (urlString.contains("?")) {
            String parameters = urlString.substring(urlString.indexOf("?") + 1);
            Map<String, String> parametersMap = new HashMap<>();

            if (!parameters.isEmpty()) {
                for (String p : parameters.split("&")) {

                    String key = p.split("=")[0];
                    String value = p.split("=")[1];
                    parametersMap.put(key, value);
                }
                reqForSigner.setParameters(parametersMap);
            }
        }

        // add body
        if (request.body() != null) {
            Request copy = request.newBuilder().build();
            Buffer buffer = new Buffer();
            copy.body().writeTo(buffer);
            reqForSigner.setContent(new ByteArrayInputStream(buffer.readByteArray()));
        }

        Signer signer = SignerFactory.getSigner(serviceName, region);
        signer.sign(reqForSigner, new BasicCredentials(this.accessKey, this.secretKey));

        Request.Builder builder = request.newBuilder();
        builder.headers(Headers.of(reqForSigner.getHeaders()));
        return builder.build();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return request;
}
 
Example 6
Source File: ApiKeyAuth.java    From huaweicloud-cs-sdk with Apache License 2.0 4 votes vote down vote up
public Request applyToParams(Request request) {
    if (serviceName == null || region == null || accessKey == null || secretKey == null) {
        return request;
    }
    DefaultRequest reqForSigner = new DefaultRequest(this.serviceName);
    try {
        reqForSigner.setEndpoint(request.uri());

        reqForSigner.setHttpMethod(HttpMethodName.valueOf(request.method()));

        if(!projectId.isEmpty()) {
            reqForSigner.addHeader("X-Project-Id", projectId);
        }

        // add query string
        String urlString = request.urlString();
        if (urlString.contains("?")) {
            String parameters = urlString.substring(urlString.indexOf("?") + 1);
            Map<String, String> parametersMap = new HashMap<>();

            if (!parameters.isEmpty()) {
                for (String p : parameters.split("&")) {

                    String key = p.split("=")[0];
                    String value = p.split("=")[1];
                    parametersMap.put(key, value);
                }
                reqForSigner.setParameters(parametersMap);
            }
        }

        // add body
        if (request.body() != null) {
            Request copy = request.newBuilder().build();
            Buffer buffer = new Buffer();
            copy.body().writeTo(buffer);
            reqForSigner.setContent(new ByteArrayInputStream(buffer.readByteArray()));
        }

        Signer signer = SignerFactory.getSigner(serviceName, region);
        signer.sign(reqForSigner, new BasicCredentials(this.accessKey, this.secretKey));

        Request.Builder builder = request.newBuilder();
        builder.headers(Headers.of(reqForSigner.getHeaders()));
        return builder.build();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return request;
}
 
Example 7
Source File: OkHttpClientRequestAdaptor.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public String getUrl(Request request) {
    return request.urlString();
}