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

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

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

Response.getStatusCode介绍

[英]Returns the status code for the request.
[中]返回请求的状态代码。

代码示例

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

@Override
public Response onCompleted(Response response) {
 logger.debug("ON COMPLETED INVOKED " + response.getHeader("X-KEEP-ALIVE"));
 try {
  assertEquals(response.getStatusCode(), 200);
  remoteAddresses.put(response.getHeader("X-KEEP-ALIVE"), true);
 } finally {
  l.countDown();
 }
 return response;
}

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

@Test
public void postWithQueryString() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient()) {
  Future<Response> f = client.preparePost("http://localhost:" + port1 + "/?a=b").setBody("abc".getBytes()).execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
 }
}

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

@Test
public void testGlobalProxy() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient(config().setProxyServer(proxyServer("localhost", port1)))) {
  String target = "http://localhost:1234/";
  Future<Response> f = client.prepareGet(target).execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertEquals(resp.getHeader("target"), "/");
 }
}

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

@Test
public void testPutImageFile() throws Exception {
 try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
  InputStream inputStream = new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE));
  Response response = client.preparePut(getTargetUrl()).addBodyPart(new InputStreamPart("test", inputStream, LARGE_IMAGE_FILE.getName(), LARGE_IMAGE_FILE.length(), "application/octet-stream", UTF_8)).execute().get();
  assertEquals(response.getStatusCode(), 200);
 }
}

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

@Test
public void testPutEmptyBody() throws Exception {
 try (AsyncHttpClient ahc = asyncHttpClient()) {
  Response response = ahc.preparePut(getTargetUrl()).setBody("String").execute().get();
  assertNotNull(response);
  assertEquals(response.getStatusCode(), 204);
  assertEquals(response.getResponseBody(), "");
  assertNotNull(response.getResponseBodyAsStream());
  assertEquals(response.getResponseBodyAsStream().read(), -1);
 }
}

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

@Test
public void testPutLargeTextFile() throws Exception {
 File file = createTempFile(1024 * 1024);
 InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
 try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
  Response response = client.preparePut(getTargetUrl())
      .addBodyPart(new InputStreamPart("test", inputStream, file.getName(), file.length(), "application/octet-stream", UTF_8)).execute().get();
  assertEquals(response.getStatusCode(), 200);
 }
}

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

@Test
public void basicAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient()) {
  Future<Response> f = client.prepareGet(getTargetUrl())
      .setRealm(basicAuthRealm(USER, ADMIN).build())
      .execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertNotNull(resp.getHeader("X-Auth"));
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
 }
}

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

@Test
public void basicAuthNegativeTest() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient()) {
  Future<Response> f = client.prepareGet(getTargetUrl())
      .setRealm(basicAuthRealm("fake", ADMIN).build())
      .execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), 401);
 }
}

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

@Test
public void noneAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient()) {
  BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm(basicAuthRealm(USER, ADMIN).build());
  Future<Response> f = r.execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertNotNull(resp.getHeader("X-Auth"));
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
 }
}

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

@Test
public void testRequestNonProxyHost() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 ProxyServer proxy = proxyServer("localhost", port1 - 1).setNonProxyHost("localhost").build();
 try (AsyncHttpClient client = asyncHttpClient()) {
  String target = "http://localhost:" + port1 + "/";
  Future<Response> f = client.prepareGet(target).setProxyServer(proxy).execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertEquals(resp.getHeader("target"), "/");
 }
}

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

@Test
public void testBothProxies() throws IOException, ExecutionException, TimeoutException, InterruptedException {
 try (AsyncHttpClient client = asyncHttpClient(config().setProxyServer(proxyServer("localhost", port1 - 1)))) {
  String target = "http://localhost:1234/";
  Future<Response> f = client.prepareGet(target).setProxyServer(proxyServer("localhost", port1)).execute();
  Response resp = f.get(3, TimeUnit.SECONDS);
  assertNotNull(resp);
  assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
  assertEquals(resp.getHeader("target"), "/");
 }
}

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

@Test(groups = "online", enabled = false)
public void notRedirected302Test() throws Exception {
 isSet.getAndSet(false);
 try (AsyncHttpClient c = asyncHttpClient(config().setFollowRedirect(true))) {
  Response response = c.prepareGet(getTargetUrl()).setFollowRedirect(false).setHeader("X-redirect", "http://www.microsoft.com/").execute().get();
  assertNotNull(response);
  assertEquals(response.getStatusCode(), 302);
 }
}

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

@Test
public void emptyResponseBodyBytesAreEmpty() throws Throwable {
 withClient().run(client ->
  withServer(server).run(server -> {
   server.enqueueEcho();
   Response response = client.prepareGet(getTargetUrl()).execute().get();
   assertEquals(response.getStatusCode(), 200);
   assertEquals(response.getResponseBodyAsBytes(), new byte[]{});
  }));
}

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

@Test
public void testPutImageFile() throws Exception {
 try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
  Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", UTF_8)).execute().get();
  assertEquals(response.getStatusCode(), 200);
 }
}

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

@Test
 public void testPutLargeTextFile() throws Exception {
  File file = createTempFile(1024 * 1024);

  try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
   Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", file, "application/octet-stream", UTF_8)).execute().get();
   assertEquals(response.getStatusCode(), 200);
  }
 }
}

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

@Test
public void testRequestProxy() throws Exception {
 try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setFollowRedirect(true).setUseInsecureTrustManager(true))) {
  RequestBuilder rb = get(getTargetUrl2()).setProxyServer(proxyServer("localhost", port1));
  Response r = asyncHttpClient.executeRequest(rb.build()).get();
  assertEquals(r.getStatusCode(), 200);
 }
}

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

private void put(int fileSize) throws Exception {
 File file = createTempFile(fileSize);
 try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(2000))) {
  Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get();
  assertEquals(response.getStatusCode(), 200);
 }
}

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

@Test
public void testConfigProxy() throws Exception {
 AsyncHttpClientConfig config = config()
     .setFollowRedirect(true)
     .setProxyServer(proxyServer("localhost", port1).build())
     .setUseInsecureTrustManager(true)
     .build();
 try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config)) {
  Response r = asyncHttpClient.executeRequest(get(getTargetUrl2())).get();
  assertEquals(r.getStatusCode(), 200);
 }
}

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

private void sendEmptyFile0(boolean disableZeroCopy) throws Exception {
 File file = getClasspathFile("empty.txt");
 try (AsyncHttpClient c = asyncHttpClient(config().setDisableZeroCopy(disableZeroCopy))) {
  Request r = post("http://localhost" + ":" + port1 + "/upload")
      .addBodyPart(new FilePart("file", file, "text/plain", UTF_8)).build();
  Response res = c.executeRequest(r).get();
  assertEquals(res.getStatusCode(), 200);
 }
}

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

@Test
public void testNoDirectRequestBodyWithProxy() throws Exception {
 AsyncHttpClientConfig config = config()
  .setFollowRedirect(true)
  .setProxyServer(proxyServer("localhost", port1).build())
  .setUseInsecureTrustManager(true)
  .build();
 try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config)) {
  Response r = asyncHttpClient.executeRequest(post(getTargetUrl2()).setBody(new ByteArrayBodyGenerator(LARGE_IMAGE_BYTES))).get();
  assertEquals(r.getStatusCode(), 200);
 }
}

相关文章