com.ning.http.client.Response.getUri()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(153)

本文整理了Java中com.ning.http.client.Response.getUri方法的一些代码示例,展示了Response.getUri的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getUri方法的具体详情如下:
包路径:com.ning.http.client.Response
类名称:Response
方法名:getUri

Response.getUri介绍

[英]Return the request Uri. Note that if the request got redirected, the value of the URI will be the last valid redirect url.
[中]返回请求Uri。请注意,如果请求被重定向,URI的值将是最后一个有效的重定向url。

代码示例

代码示例来源:origin: com.ning/async-http-client

public Uri getUri() {
  return response.getUri();
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http-client

public Uri getUri() {
  return response.getUri();
}

代码示例来源:origin: javaee/grizzly-ahc

public Uri getUri() {
  return response.getUri();
}

代码示例来源:origin: io.gatling/async-http-client

public UriComponents getUri() {
  return response.getUri();
}

代码示例来源:origin: play/play-java

/**
   * Return the request {@link java.net.URI}. Note that if the request got redirected, the value of the
   * {@link java.net.URI} will be the last valid redirect url.
   *
   * @return the request {@link java.net.URI}.
   */
  public URI getUri() {
    try {
      return ahcResponse.getUri();
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: outbrain/ob1k

@Override
public URI getUri() throws URISyntaxException {
 return ningResponse.getUri().toJavaNetURI();
}

代码示例来源:origin: outbrain/ob1k

@Override
public String getUrl() {
 return ningResponse.getUri().toUrl();
}

代码示例来源:origin: javaee/grizzly-ahc

@Override
public String onCompleted(Response response) throws Exception {
  return response.getUri().toString();
}

代码示例来源:origin: javaee/grizzly-ahc

@Override
public String onCompleted(Response response) throws Exception {
  return response.getUri().toString();
}

代码示例来源:origin: javaee/grizzly-ahc

@Override
public String onCompleted(Response response) throws Exception {
  return response.getUri().toString();
}

代码示例来源:origin: palominolabs/benchpress

/**
 * Send an HTTP message to a worker, producing helpful logging if there was a problem
 *
 * @param uriRequest     The request to make
 * @param expectedStatus The expected return status
 * @return true if the method was successfully delivered & the worker gave the expected response
 */
private boolean tellWorker(AsyncHttpClient.BoundRequestBuilder uriRequest, Response.Status expectedStatus) {
  try {
    com.ning.http.client.Response response = uriRequest.execute().get();
    if (response.getStatusCode() != expectedStatus.getStatusCode()) {
      logger.warn(
        "Problem telling worker <" + metadata.getWorkerId() + "> " + "(" + response.getUri() + "), " +
          "reason [" + response.getStatusCode() + ": " + response.getStatusText() + "]");
      return false;
    }
    return true;
  } catch (IOException | ExecutionException e) {
    logger.warn("Unable to communicated with worker " + metadata.toString());
    return false;
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    logger.info("Interrupted");
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: palominolabs/benchpress

/**
   * Send an HTTP message to a worker and get the result
   *
   * Note: expects the worker to respond with OK (200) status code.
   *
   * @param uriRequest The request to make
   * @return An InputStream of the response content
   */
  private InputStream askWorker(AsyncHttpClient.BoundRequestBuilder uriRequest) {
    try {
      com.ning.http.client.Response response = uriRequest.execute().get();

      if (response.getStatusCode() != Response.Status.OK.getStatusCode()) {
        logger.warn(
          "Problem asking worker <" + metadata.getWorkerId() + "> " + "(" + response.getUri() + "), " +
            "reason [" + response.getStatusCode() + ": " + response.getStatusText() + "]");
      }

      return response.getResponseBodyAsStream();
    } catch (IOException | ExecutionException e) {
      logger.warn("Unable to communicated with worker " + metadata.toString());
      throw new RuntimeException(e);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      logger.info("Interrupted");
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: org.apache.tez/tez-runtime-library

LOG.debug("Request url={}, id={}", response.getUri());
throw new IOException("Got invalid response code " + rc + " from "
  + url + ": " + response.getStatusText());

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "online", "default_provider" })
public void redirected302Test() throws Throwable {
  isSet.getAndSet(false);
  try (AsyncHttpClient client = getAsyncHttpClient(null)) {
    // once
    Response response = client.prepareGet(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "http://www.stackoverflow.com/").execute().get();
    assertNotNull(response);
    assertEquals(response.getStatusCode(), 200);
    String anyWebPage = "https://(www.)?stackoverflow.com[^:]*:443";
    String baseUrl = getBaseUrl(response.getUri());
    assertTrue(baseUrl.matches(anyWebPage), "response baseUrl \'" + baseUrl +"\' does not show redirection to " + anyWebPage);
  }
}

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "online", "default_provider" })
public void redirected302Test() throws Throwable {
  isSet.getAndSet(false);
  AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
  try (AsyncHttpClient client = getAsyncHttpClient(cg)) {
    // once
    Response response = client.prepareGet(getTargetUrl()).setHeader("X-redirect", "http://www.google.com/").execute().get();
    assertNotNull(response);
    assertEquals(response.getStatusCode(), 200);
    String baseUrl = getBaseUrl(response.getUri());
    assertTrue(baseUrl.startsWith("http://www.google."), "response does not show redirection to a google subdomain, got " + baseUrl);
  }
}

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "standalone", "default_provider" })
public void absolutePathRedirectTest() throws Throwable {
  isSet.getAndSet(false);
  AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
  try (AsyncHttpClient client = getAsyncHttpClient(cg)) {
    String redirectTarget = "/bar/test";
    String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString();
    Response response = client.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get();
    assertNotNull(response);
    assertEquals(response.getStatusCode(), 200);
    assertEquals(response.getUri().toString(), destinationUrl);
    log.debug("{} was redirected to {}", redirectTarget, destinationUrl);
  }
}

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "standalone", "default_provider" })
  public void relativePathRedirectTest() throws Throwable {
    isSet.getAndSet(false);

    AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
    try (AsyncHttpClient client = getAsyncHttpClient(cg)) {
      String redirectTarget = "bar/test1";
      String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString();

      Response response = client.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get();
      assertNotNull(response);
      assertEquals(response.getStatusCode(), 200);
      assertEquals(response.getUri().toString(), destinationUrl);

      log.debug("{} was redirected to {}", redirectTarget, destinationUrl);
    }
  }
}

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "standalone", "default_provider" })
  public void relativeLocationUrl() throws Throwable {
    isSet.getAndSet(false);

    try (AsyncHttpClient client = getAsyncHttpClient(null)) {
      Response response = client.preparePost(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "/foo/test").execute().get();
      assertNotNull(response);
      assertEquals(response.getStatusCode(), 200);
      assertEquals(response.getUri().toString(), getTargetUrl());
    }
  }
}

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "standalone", "default_provider" })
  public void relativeLocationUrl() throws Throwable {
    isSet.getAndSet(false);

    AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder()//
        .setMaxRedirects(5)//
        .setFollowRedirect(true)//
        .setAcceptAnyCertificate(true)//
        .build();
    try (AsyncHttpClient client = getAsyncHttpClient(cg)) {
      Response response = client.prepareGet(getTargetUrl()).setHeader("X-redirect", "/foo/test").execute().get();
      assertNotNull(response);
      assertEquals(response.getStatusCode(), 200);
      assertEquals(response.getUri().toString(), getTargetUrl());
    }
  }
}

代码示例来源:origin: javaee/grizzly-ahc

res = response.get();
assertNotNull(res.getResponseBody());
assertEquals(BASE_URL + "/overthere", BASE_URL + "/overthere", res.getUri().toString());

相关文章