org.asynchttpclient.Response.getUri()方法的使用及代码示例

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

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

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

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test(groups = "online", enabled = false)
public void redirected302Test() throws Exception {
 isSet.getAndSet(false);
 try (AsyncHttpClient c = asyncHttpClient()) {
  Response response = c.prepareGet(getTargetUrl()).setFollowRedirect(true).setHeader("X-redirect", "https://www.microsoft.com/").execute().get();
  assertNotNull(response);
  assertEquals(response.getStatusCode(), 200);
  String anyMicrosoftPage = "https://www.microsoft.com[^:]*:443";
  String baseUrl = getBaseUrl(response.getUri());
  assertTrue(baseUrl.matches(anyMicrosoftPage), "response does not show redirection to " + anyMicrosoftPage);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test(enabled = false)
public void absolutePathRedirectTest() throws Exception {
 isSet.getAndSet(false);
 try (AsyncHttpClient c = asyncHttpClient(config().setFollowRedirect(true))) {
  String redirectTarget = "/bar/test";
  String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString();
  Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get();
  assertNotNull(response);
  assertEquals(response.getStatusCode(), 200);
  assertEquals(response.getUri().toString(), destinationUrl);
  logger.debug("{} was redirected to {}", redirectTarget, destinationUrl);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test(enabled = false)
public void relativePathRedirectTest() throws Exception {
 isSet.getAndSet(false);
 try (AsyncHttpClient c = asyncHttpClient(config().setFollowRedirect(true))) {
  String redirectTarget = "bar/test1";
  String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString();
  Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get();
  assertNotNull(response);
  assertEquals(response.getStatusCode(), 200);
  assertEquals(response.getUri().toString(), destinationUrl);
  logger.debug("{} was redirected to {}", redirectTarget, destinationUrl);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test(groups = "online", enabled = false)
public void redirected302Test() throws Exception {
 isSet.getAndSet(false);
 try (AsyncHttpClient c = asyncHttpClient(config().setFollowRedirect(true))) {
  Response response = c.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: AsyncHttpClient/async-http-client

@Test(enabled = false)
public void relativeLocationUrl() throws Exception {
 isSet.getAndSet(false);
 try (AsyncHttpClient c = asyncHttpClient()) {
  Response response = c.preparePost(getTargetUrl()).setFollowRedirect(true).setHeader("X-redirect", "/foo/test").execute().get();
  assertNotNull(response);
  assertEquals(response.getStatusCode(), 200);
  assertEquals(response.getUri().toString(), getTargetUrl());
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void testHEAD302() throws IOException, InterruptedException, ExecutionException, TimeoutException {
 AsyncHttpClientConfig clientConfig = new DefaultAsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
 try (AsyncHttpClient client = asyncHttpClient(clientConfig)) {
  final CountDownLatch l = new CountDownLatch(1);
  Request request = head("http://localhost:" + port1 + "/Test").build();
  Response response = client.executeRequest(request, new AsyncCompletionHandlerBase() {
   @Override
   public Response onCompleted(Response response) throws Exception {
    l.countDown();
    return super.onCompleted(response);
   }
  }).get(3, TimeUnit.SECONDS);
  if (l.await(TIMEOUT, TimeUnit.SECONDS)) {
   assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
   assertTrue(response.getUri().getPath().endsWith("_moved"));
  } else {
   fail("Timeout out");
  }
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test(enabled = false)
public void relativeLocationUrl() throws Exception {
 redirectDone.getAndSet(false);
 AsyncHttpClientConfig cg = config()
     .setMaxRedirects(5)
     .setFollowRedirect(true)
     .setUseInsecureTrustManager(true)
     .build();
 try (AsyncHttpClient c = asyncHttpClient(cg)) {
  Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", "/foo/test").execute().get();
  assertNotNull(response);
  assertEquals(response.getStatusCode(), 200);
  assertEquals(response.getUri().toString(), getTargetUrl());
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void getUrlWithPathWithQuery() throws Throwable {
 withClient().run(client ->
  withServer(server).run(server -> {
   String targetUrl = getTargetUrl() + "?q=+%20x";
   Request request = get(targetUrl).build();
   assertEquals(request.getUrl(), targetUrl);
   server.enqueueOk();
   Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter()).get(TIMEOUT, SECONDS);
   assertEquals(response.getUri().toUrl(), targetUrl);
  }));
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void getRootUrl() throws Throwable {
 withClient().run(client ->
  withServer(server).run(server -> {
   String url = server.getHttpUrl();
   server.enqueueOk();
   Response response = client.executeRequest(get(url), new AsyncCompletionHandlerAdapter()).get(TIMEOUT, SECONDS);
   assertEquals(response.getUri().toUrl(), url);
  }));
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void getUrlWithPathWithoutQuery() throws Throwable {
 withClient().run(client ->
  withServer(server).run(server -> {
   server.enqueueOk();
   Response response = client.executeRequest(get(getTargetUrl()), new AsyncCompletionHandlerAdapter()).get(TIMEOUT, SECONDS);
   assertEquals(response.getUri().toUrl(), getTargetUrl());
  }));
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void getUrlWithPathWithQueryParams() throws Throwable {
 withClient().run(client ->
  withServer(server).run(server -> {
   server.enqueueOk();
   Response response = client.executeRequest(get(getTargetUrl()).addQueryParam("q", "a b"), new AsyncCompletionHandlerAdapter()).get(TIMEOUT, SECONDS);
   assertEquals(response.getUri().toUrl(), getTargetUrl() + "?q=a%20b");
  }));
}

代码示例来源:origin: AsyncHttpClient/async-http-client

/**
 * Tests that after a redirect the final url in the response reflect the redirect
 */
@Test
public void testGetRedirectFinalUrl() throws Exception {
 AsyncHttpClientConfig config = config()
     .setKeepAlive(true)
     .setMaxConnectionsPerHost(1)
     .setMaxConnections(1)
     .setConnectTimeout(1000)
     .setRequestTimeout(1000)
     .setFollowRedirect(true)
     .build();
 try (AsyncHttpClient c = asyncHttpClient(config)) {
  ListenableFuture<Response> response = c.executeRequest(get(servletEndpointRedirectUrl));
  Response res = response.get();
  assertNotNull(res.getResponseBody());
  assertEquals(res.getUri().toString(), BASE_URL + "/overthere");
 }
}

代码示例来源:origin: org.asynchttpclient/async-http-client-api

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

代码示例来源:origin: com.typesafe.play/play-java-ws

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

代码示例来源:origin: ribasco/async-gamequery-lib

if (error != null)
  throw new WebException(error);
log.debug("Handling response for {}, with status code = {}", response.getMessage().getUri(), response.getMessage().getStatusCode());
if (response.getStatus() == HttpStatusClass.SERVER_ERROR ||
    response.getStatus() == HttpStatusClass.CLIENT_ERROR) {

相关文章