本文整理了Java中com.linecorp.armeria.client.HttpClient.get()
方法的一些代码示例,展示了HttpClient.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.get()
方法的具体详情如下:
包路径:com.linecorp.armeria.client.HttpClient
类名称:HttpClient
方法名:get
[英]Sends an HTTP GET request.
[中]发送HTTP GET请求。
代码示例来源:origin: line/armeria
@Override
public CompletableFuture<Boolean> isHealthy(Endpoint endpoint) {
return httpClient.get(healthCheckPath)
.aggregate()
.thenApply(message -> HttpStatus.OK.equals(message.status()));
}
}
代码示例来源:origin: line/armeria
@Test(timeout = 10000)
public void testSpanInThreadPoolHasSameTraceId() throws Exception {
poolHttpClient.get("pool").aggregate().get();
final Span[] spans = spanReporter.take(5);
assertThat(Arrays.stream(spans).map(Span::traceId).collect(toImmutableSet())).hasSize(1);
assertThat(Arrays.stream(spans).map(Span::parentId)
.filter(Objects::nonNull)
.collect(toImmutableSet())).hasSize(1);
}
代码示例来源:origin: line/armeria
@Test
public void success() {
final AggregatedHttpMessage response = client.get("/hello/Spring").aggregate().join();
assertThat(response.status()).isEqualTo(HttpStatus.OK);
assertThat(response.content().toStringUtf8())
.isEqualTo("Hello, Spring! This message is from Armeria annotated service!");
}
代码示例来源:origin: line/armeria
@Test
public void healthCheck() throws Exception {
final AggregatedHttpMessage res = client.get("/internal/healthcheck").aggregate().join();
assertThat(res.status()).isEqualTo(HttpStatus.OK);
assertThat(res.content().toStringUtf8()).isEqualTo("ok");
}
}
代码示例来源:origin: line/armeria
@Test
public void hello() throws Exception {
final AggregatedHttpMessage res = client.get("/hello").aggregate().join();
assertThat(res.status()).isEqualTo(HttpStatus.OK);
assertThat(res.content().toStringUtf8()).isEqualTo("Hello, World");
}
代码示例来源:origin: line/armeria
@Test
public void index() {
final AggregatedHttpMessage res = client.get("/").aggregate().join();
assertThat(res.status()).isEqualTo(HttpStatus.OK);
assertThat(res.content().toStringUtf8()).isEqualTo("index");
}
代码示例来源:origin: line/armeria
@Test
public void testAnnotatedServiceRegistrationBean() throws Exception {
final HttpClient client = HttpClient.of(newUrl("h1c"));
HttpResponse response = client.get("/annotated/get");
AggregatedHttpMessage msg = response.aggregate().get();
assertThat(msg.status()).isEqualTo(HttpStatus.OK);
assertThat(msg.content().toStringUtf8()).isEqualTo("annotated");
response = client.get("/annotated/get/2");
msg = response.aggregate().get();
assertThat(msg.status()).isEqualTo(HttpStatus.OK);
assertThat(msg.content().toStringUtf8()).isEqualTo("exception");
}
代码示例来源:origin: line/armeria
@Test
public void shouldGetHelloFromRestController() throws Exception {
protocols.forEach(scheme -> {
final HttpClient client = HttpClient.of(clientFactory, scheme + "://example.com:" + port);
final AggregatedHttpMessage response = client.get("/hello").aggregate().join();
assertThat(response.content().toStringUtf8()).isEqualTo("hello");
});
}
代码示例来源:origin: line/armeria
@Test
public void completable() {
final HttpClient client = HttpClient.of(rule.uri("/completable"));
AggregatedHttpMessage msg;
msg = client.get("/done").aggregate().join();
assertThat(msg.headers().status()).isEqualTo(HttpStatus.OK);
msg = client.get("/error").aggregate().join();
assertThat(msg.headers().status()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
代码示例来源:origin: line/armeria
@Test
public void shouldGetHelloFromRestController() throws Exception {
final HttpClient client = HttpClient.of("http://127.0.0.1:" + port);
final AggregatedHttpMessage response = client.get("/proxy?port=" + port).aggregate().join();
assertThat(response.content().toStringUtf8()).isEqualTo("hello");
}
}
代码示例来源:origin: line/armeria
@Test
public void testHttpServiceRegistrationBean() throws Exception {
final HttpClient client = HttpClient.of(newUrl("h1c"));
final HttpResponse response = client.get("/ok");
final AggregatedHttpMessage msg = response.aggregate().get();
assertThat(msg.status()).isEqualTo(HttpStatus.OK);
assertThat(msg.content().toStringUtf8()).isEqualTo("ok");
}
}
代码示例来源:origin: line/armeria
@Test
public void testHttpServiceRegistrationBean() throws Exception {
final HttpClient client = HttpClient.of(newUrl("h1c"));
final HttpResponse response = client.get("/ok");
final AggregatedHttpMessage msg = response.aggregate().get();
assertThat(msg.status()).isEqualTo(HttpStatus.OK);
assertThat(msg.content().toStringUtf8()).isEqualTo("ok");
}
代码示例来源:origin: line/armeria
@Test
public void single() {
final HttpClient client = HttpClient.of(rule.uri("/single"));
AggregatedHttpMessage msg;
msg = client.get("/string").aggregate().join();
assertThat(msg.headers().contentType()).isEqualTo(MediaType.PLAIN_TEXT_UTF_8);
assertThat(msg.content().toStringUtf8()).isEqualTo("a");
msg = client.get("/json").aggregate().join();
assertThat(msg.headers().contentType()).isEqualTo(MediaType.JSON_UTF_8);
assertThatJson(msg.content().toStringUtf8()).isStringEqualTo("a");
msg = client.get("/error").aggregate().join();
assertThat(msg.headers().status()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
代码示例来源:origin: line/armeria
@Test
public void shouldGetNotFound() {
protocols.forEach(scheme -> {
final HttpClient client = HttpClient.of(clientFactory, scheme + "://example.com:" + port);
assertThat(client.get("/route2").aggregate().join().status()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(client.execute(
HttpHeaders.of(HttpMethod.POST, "/route2")
.contentType(com.linecorp.armeria.common.MediaType.PLAIN_TEXT_UTF_8),
HttpData.of("text".getBytes())).aggregate().join().status())
.isEqualTo(HttpStatus.NOT_FOUND);
});
}
}
代码示例来源:origin: line/armeria
@Test
public void shouldReturnBadRequestDueToException() {
final ArmeriaReactiveWebServerFactory factory = factory();
runServer(factory, AlwaysFailureHandler.INSTANCE, server -> {
final HttpClient client = httpClient(server);
final AggregatedHttpMessage res1 = client.post("/hello", "hello").aggregate().join();
assertThat(res1.status()).isEqualTo(com.linecorp.armeria.common.HttpStatus.BAD_REQUEST);
final AggregatedHttpMessage res2 = client.get("/hello").aggregate().join();
assertThat(res2.status()).isEqualTo(com.linecorp.armeria.common.HttpStatus.BAD_REQUEST);
});
}
代码示例来源:origin: line/armeria
@Test
public void failure() {
final AggregatedHttpMessage response = client.get("/hello/a").aggregate().join();
assertThat(response.status()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThatJson(response.content().toStringUtf8())
.node("message")
.isEqualTo("hello.name: name should have between 3 and 10 characters");
}
}
代码示例来源:origin: line/armeria
@Test
public void testMetrics() throws Exception {
final String metricReport = HttpClient.of(newUrl("http"))
.get("/internal/metrics")
.aggregate().join()
.content().toStringUtf8();
assertThat(metricReport).contains("# TYPE jvm_gc_live_data_size_bytes gauge");
}
}
代码示例来源:origin: line/armeria
@Test
public void shouldReturnEchoResponse() {
final ArmeriaReactiveWebServerFactory factory = factory();
runEchoServer(factory, server -> {
final HttpClient client = httpClient(server);
validateEchoResponse(sendPostRequest(client));
final AggregatedHttpMessage res = client.get("/hello").aggregate().join();
assertThat(res.status()).isEqualTo(com.linecorp.armeria.common.HttpStatus.OK);
assertThat(res.content().toStringUtf8()).isEmpty();
});
}
代码示例来源:origin: line/armeria
@Test
public void testThriftServiceRegistrationBean() throws Exception {
final HelloService.Iface client = Clients.newClient(newUrl("tbinary+h1c") + "/thrift",
HelloService.Iface.class);
assertThat(client.hello("world")).isEqualTo("hello world");
final HttpClient httpClient = HttpClient.of(newUrl("h1c"));
final HttpResponse response = httpClient.get("/internal/docs/specification.json");
final AggregatedHttpMessage msg = response.aggregate().get();
assertThat(msg.status()).isEqualTo(HttpStatus.OK);
assertThatJson(msg.content().toStringUtf8())
.node("services[1].exampleHttpHeaders[0].x-additional-header").isStringEqualTo("headerVal");
}
代码示例来源:origin: line/armeria
@Test
public void normal() {
final HttpClient client = new HttpClientBuilder(rule.httpsUri("/"))
.factory(new ClientFactoryBuilder()
.sslContextCustomizer(ctx -> ctx
.keyManager(clientCert.certificateFile(), clientCert.privateKeyFile())
.trustManager(InsecureTrustManagerFactory.INSTANCE))
.build())
.decorator(new LoggingClientBuilder().newDecorator())
.build();
assertThat(client.get("/").aggregate().join().status()).isEqualTo(HttpStatus.OK);
}
}
内容来源于网络,如有侵权,请联系作者删除!