本文整理了Java中reactor.netty.http.client.HttpClient.get()
方法的一些代码示例,展示了HttpClient.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.get()
方法的具体详情如下:
包路径:reactor.netty.http.client.HttpClient
类名称:HttpClient
方法名:get
[英]HTTP GET to connect the HttpClient.
[中]HTTP获取以连接HttpClient。
代码示例来源:origin: reactor/reactor-netty
private void doSimpleTest404(HttpClient client) {
Integer res = client.followRedirect(true)
.get()
.uri("/unsupportedURI")
.responseSingle((r, buf) -> Mono.just(r.status().code()))
.log()
.block();
assertThat(res).isNotNull();
if (res != 404) {
throw new IllegalStateException("test status failed with " + res);
}
}
代码示例来源:origin: com.rabbitmq/http-client
private <T> Mono<T> doGetMono(Class<T> type, String... pathSegments) {
return Mono.from(client
.headersWhen(authorizedHeader())
.get()
.uri(uri(pathSegments))
.response(decode(type)));
}
代码示例来源:origin: rabbitmq/hop
private <T> Mono<T> doGetMono(Class<T> type, String... pathSegments) {
return Mono.from(client
.headersWhen(authorizedHeader())
.get()
.uri(uri(pathSegments))
.response(decode(type)));
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void nettyNetChannelAcceptsNettyChannelHandlers() throws InterruptedException {
HttpClient client = HttpClient.create()
.wiretap(true);
final CountDownLatch latch = new CountDownLatch(1);
System.out.println(client.get()
.uri("http://www.google.com/?q=test%20d%20dq")
.responseContent()
.asString()
.collectList()
.doOnSuccess(v -> latch.countDown())
.block(Duration.ofSeconds(30)));
assertTrue("Latch didn't time out", latch.await(15, TimeUnit.SECONDS));
}
代码示例来源:origin: io.netifi.proteus/proteus-tracing-openzipkin
private static Function<Integer, Publisher<InputStream>> zipkinServerStream(
String zipkinUrl, Mono<HttpClient> client) {
return lookbackSeconds ->
client.flatMapMany(
c ->
c.doOnRequest(
(__, connection) -> connection.addHandler(new JsonObjectDecoder(true)))
.get()
.uri(zipkinQuery(zipkinUrl, lookbackSeconds))
.responseContent()
.asInputStream());
}
代码示例来源:origin: netifi-proteus/proteus-java
private static Function<Integer, Publisher<InputStream>> zipkinServerStream(
String zipkinUrl, Mono<HttpClient> client) {
return lookbackSeconds ->
client.flatMapMany(
c ->
c.doOnRequest(
(__, connection) -> connection.addHandler(new JsonObjectDecoder(true)))
.get()
.uri(zipkinQuery(zipkinUrl, lookbackSeconds))
.responseContent()
.asInputStream());
}
代码示例来源:origin: reactor/reactor-netty
private List<String> getClientDataPromise() {
HttpClient httpClient =
HttpClient.create()
.port(httpServer.address().getPort())
.wiretap(true);
Mono<List<String>> content = httpClient.get()
.uri("/data")
.responseContent()
.asString()
.collectList()
.cache();
List<String> res = content.block(Duration.ofSeconds(30));
return res;
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void errorResponseAndReturn() {
DisposableServer c = HttpServer.create()
.port(0)
.handle((req, resp) -> Mono.error(new Exception("returnError")))
.wiretap(true)
.bindNow();
int code =
HttpClient.create()
.port(c.address().getPort())
.wiretap(true)
.get()
.uri("/return")
.responseSingle((res, buf) -> Mono.just(res.status().code()))
.block();
assertThat(code).isEqualTo(500);
c.disposeNow();
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void disableChunkForced2() {
Tuple2<HttpResponseStatus, String> r =
HttpClient.newConnection()
.tcpConfiguration(tcpClient -> tcpClient.host("google.com"))
.wiretap(true)
.keepAlive(false)
.chunkedTransfer(false)
.get()
.uri("/unsupportedURI")
.responseSingle((res, conn) -> Mono.just(res.status())
.zipWith(conn.asString()))
.block(Duration.ofSeconds(30));
assertThat(r).isNotNull();
Assert.assertEquals(r.getT1(), HttpResponseStatus.NOT_FOUND);
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void simpleTestHttps() {
StepVerifier.create(HttpClient.create()
.wiretap(true)
.get()
.uri("https://developer.chrome.com")
.response((r, buf) -> Mono.just(r.status().code())))
.expectNextMatches(status -> status >= 200 && status < 400)
.expectComplete()
.verify();
StepVerifier.create(HttpClient.create()
.wiretap(true)
.get()
.uri("https://developer.chrome.com")
.response((r, buf) -> Mono.just(r.status().code())))
.expectNextMatches(status -> status >= 200 && status < 400)
.expectComplete()
.verify();
}
代码示例来源:origin: reactor/reactor-netty
private Mono<Void> proxy(HttpServerRequest request, HttpServerResponse response) {
return HttpClient.create()
.wiretap(true)
.headers(h -> h.add(filterRequestHeaders(request.requestHeaders())))
.get()
.uri(URI.create("http://localhost:" + CONTENT_SERVER_PORT +
"/" + request.path())
.toString())
.response((targetResponse, buf) -> response.headers(filterResponseHeaders(targetResponse.responseHeaders()))
.send(buf.retain())
.then())
.then();
}
代码示例来源:origin: reactor/reactor-netty
private void doTestIssue309(String path, HttpServer httpServer) {
DisposableServer server =
httpServer.handle((req, res) -> res.sendString(Mono.just("Should not be reached")))
.bindNow();
Mono<HttpResponseStatus> status =
HttpClient.create()
.port(server.address().getPort())
.get()
.uri(path)
.responseSingle((res, byteBufMono) -> Mono.just(res.status()));
StepVerifier.create(status)
.expectNextMatches(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE::equals)
.expectComplete()
.verify();
server.disposeNow();
}
代码示例来源:origin: reactor/reactor-netty
private Mono<List<String>> getClientDataPromise() {
HttpClient httpClient =
HttpClient.create()
.port(httpServer.address().getPort())
.wiretap(true);
return httpClient.get()
.uri("/data")
.responseContent()
.asString()
.log("client")
.collectList()
.cache()
.toProcessor();
}
代码示例来源:origin: reactor/reactor-netty
@Test
@Ignore
public void proxyTest() {
HttpServer server = HttpServer.create();
server.route(r -> r.get("/search/{search}",
(in, out) -> HttpClient.create()
.wiretap(true)
.get()
.uri("foaas.herokuapp.com/life/" + in.param("search"))
.response((repliesOut, buf) -> out.send(buf))))
.wiretap(true)
.bindNow()
.onDispose()
.block(Duration.ofSeconds(30));
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void testDeferredHeader() {
DisposableServer context =
HttpServer.create()
.host("localhost")
.route(r -> r.get("/201", (req, res) -> res.addHeader
("Content-Length", "0")
.status(HttpResponseStatus.CREATED)
.sendHeaders()))
.bindNow();
createHttpClientForContextWithAddress(context)
.headersWhen(h -> Mono.just(h.set("test", "test")).delayElement(Duration.ofSeconds(2)))
.observe((c, s) -> System.out.println(s + "" + c))
.get()
.uri("/201")
.responseContent()
.repeat(4)
.blockLast();
context.disposeNow();
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void sslExchangeAbsoluteGet() throws CertificateException, SSLException {
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
SslContext sslClient = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
DisposableServer context =
HttpServer.create()
.secure(ssl -> ssl.sslContext(sslServer))
.handle((req, resp) -> resp.sendString(Flux.just("hello ", req.uri())))
.wiretap(true)
.bindNow();
String responseString = createHttpClientForContextWithAddress(context)
.secure(ssl -> ssl.sslContext(sslClient))
.get()
.uri("/foo")
.responseSingle((res, buf) -> buf.asString(CharsetUtil.UTF_8))
.block();
context.disposeNow();
assertThat(responseString).isEqualTo("hello /foo");
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void proxy_2() {
StepVerifier.create(
HttpClient.create()
.tcpConfiguration(tcpClient -> tcpClient.proxy(ops -> ops.type(ProxyProvider.Proxy.HTTP)
.host("localhost")
.port(hoverflyRule.getProxyPort())))
.wiretap(true)
.get()
.uri("http://127.0.0.1:7000/")
.responseSingle((response, body) -> Mono.zip(body.asString(),
Mono.just(response.responseHeaders()))))
.expectNextMatches(t ->
t.getT2().contains("Hoverfly") &&
"test".equals(t.getT1()))
.expectComplete()
.verify(Duration.ofSeconds(30));
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void proxy_1() {
StepVerifier.create(
HttpClient.create()
.tcpConfiguration(tcpClient -> tcpClient.proxy(ops -> ops.type(ProxyProvider.Proxy.HTTP)
.host("localhost")
.port(hoverflyRule.getProxyPort())))
.addressSupplier(server::address)
.wiretap(true)
.get()
.uri("/")
.responseSingle((response, body) -> Mono.zip(body.asString(),
Mono.just(response.responseHeaders()))))
.expectNextMatches(t ->
t.getT2().contains("Hoverfly") &&
"test".equals(t.getT1()))
.expectComplete()
.verify(Duration.ofSeconds(30));
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void nonProxyHosts_2() {
StepVerifier.create(
HttpClient.create()
.tcpConfiguration(tcpClient -> tcpClient.proxy(ops -> ops.type(ProxyProvider.Proxy.HTTP)
.host("localhost")
.port(hoverflyRule.getProxyPort())
.nonProxyHosts("localhost")))
.wiretap(true)
.get()
.uri("http://localhost:7000/")
.responseSingle((response, body) -> Mono.zip(body.asString(),
Mono.just(response.responseHeaders()))))
.expectNextMatches(t ->
!t.getT2().contains("Hoverfly") &&
"test".equals(t.getT1()))
.expectComplete()
.verify(Duration.ofSeconds(30));
}
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void nonProxyHosts_1() {
StepVerifier.create(
HttpClient.create()
.tcpConfiguration(tcpClient -> tcpClient.proxy(ops -> ops.type(ProxyProvider.Proxy.HTTP)
.host("localhost")
.port(hoverflyRule.getProxyPort())
.nonProxyHosts("127.0.0.1")))
.addressSupplier(server::address)
.wiretap(true)
.get()
.uri("/")
.responseSingle((response, body) -> Mono.zip(body.asString(),
Mono.just(response.responseHeaders()))))
.expectNextMatches(t ->
!t.getT2().contains("Hoverfly") &&
"test".equals(t.getT1()))
.expectComplete()
.verify(Duration.ofSeconds(30));
}
内容来源于网络,如有侵权,请联系作者删除!