当前位置: 首页>>代码示例>>Java>>正文


Java HttpClient.create方法代码示例

本文整理汇总了Java中reactor.ipc.netty.http.client.HttpClient.create方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClient.create方法的具体用法?Java HttpClient.create怎么用?Java HttpClient.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reactor.ipc.netty.http.client.HttpClient的用法示例。


在下文中一共展示了HttpClient.create方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: httpRespondsEmpty

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void httpRespondsEmpty() {
	NettyContext server =
			HttpServer.create(0)
			          .newRouter(r ->
			              r.post("/test/{param}", (req, res) -> Mono.empty()))
			          .block(Duration.ofSeconds(30));

	HttpClient client =
			HttpClient.create("localhost", server.address().getPort());

	Mono<ByteBuf> content = client
			            .post("/test/World", req -> req.header("Content-Type", "text/plain")
			                                           .sendString(Mono.just("Hello")
			                                           .log("client-send")))
			            .flatMap(res -> res.receive()
			                               .log("client-received")
			                               .next())
			            .doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage()));

	StepVerifier.create(content)
			    .expectComplete()
			    .verify(Duration.ofSeconds(5000));

	server.dispose();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:27,代码来源:HttpTests.java

示例2: testIssue186

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void testIssue186() {
	NettyContext server =
			HttpServer.create(0)
			          .newHandler((req, res) -> res.status(200).send())
			          .block(Duration.ofSeconds(300));

	HttpClient client =
			HttpClient.create(ops -> ops.connectAddress(() -> server.address())
					                    .poolResources(PoolResources.fixed("test", 1)));

	try {
		doTestIssue186(client);
		doTestIssue186(client);
	}
	finally {
		server.dispose();
	}

}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:21,代码来源:HttpServerTests.java

示例3: testIssue196

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
@Test
@Ignore
public void testIssue196() throws Exception {
	ExecutorService threadPool = Executors.newCachedThreadPool();

	int testServerPort = SocketUtils.findAvailableTcpPort();
	TestServer testServer = new TestServer(testServerPort);

	threadPool.submit(testServer);

	if(!testServer.await(10, TimeUnit.SECONDS)){
		throw new IOException("Fail to start test server");
	}

	HttpClient client =
	        HttpClient.create(opt -> opt.port(testServerPort)
	                                    .poolResources(PoolResources.fixed("test", 1)));

	Flux.range(0, 2)
	    .flatMap(i -> client.get("/205")
	                        .flatMap(res -> res.receive()
	                                           .aggregate()
	                                           .asString()))
	    .blockLast(Duration.ofSeconds(100));

	testServer.close();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:28,代码来源:ChannelOperationsHandlerTest.java

示例4: nettyNetChannelAcceptsNettyChannelHandlers

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void nettyNetChannelAcceptsNettyChannelHandlers() throws InterruptedException {
	HttpClient client = HttpClient.create();

	final CountDownLatch latch = new CountDownLatch(1);
	System.out.println(client.get("http://www.google.com/?q=test%20d%20dq")
	                         .flatMap(r -> r.receive()
	                                     .asString()
	                                     .collectList())
	                         .doOnSuccess(v -> latch.countDown())
	                         .block(Duration.ofSeconds(30)));

	assertTrue("Latch didn't time out", latch.await(15, TimeUnit.SECONDS));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:15,代码来源:TcpClientTests.java

示例5: getClientDataPromise

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
private Mono<List<String>> getClientDataPromise() throws Exception {
	HttpClient httpClient = HttpClient.create("localhost", httpServer.address()
	                                                                 .getPort());

	return httpClient.get("/data")
	                 .flatMapMany(s -> s.receive()
	                                .asString()
	                                .log("client")
	                                .next())
	                 .collectList()
	                 .cache()
	                 .toProcessor();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:14,代码来源:ClientServerHttpTests.java

示例6: httpRespondsToRequestsFromClients

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void httpRespondsToRequestsFromClients() {
	NettyContext server =
			HttpServer.create(0)
			          .newRouter(r ->
			              r.post("/test/{param}", (req, res) ->
			                  res.sendString(req.receive()
			                                    .asString()
			                                    .log("server-received")
			                                    .map(it -> it + ' ' + req.param("param") + '!')
			                                    .log("server-reply"))))
			          .block(Duration.ofSeconds(30));

	HttpClient client =
			HttpClient.create("localhost", server.address().getPort());

	Mono<String> content =
			client.post("/test/World", req -> req.header("Content-Type", "text/plain")
			                                     .sendString(Flux.just("Hello")
			                                     .log("client-send")))
			      .flatMap(res -> res.receive()
			                         .aggregate()
			                         .asString()
			                         .log("client-received"))
			      .doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage()));

	StepVerifier.create(content)
			    .expectNextMatches(s -> s.equals("Hello World!"))
			    .expectComplete()
			    .verify(Duration.ofSeconds(5000));

	server.dispose();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:34,代码来源:HttpTests.java

示例7: getClientDataPromise

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
private List<String> getClientDataPromise() throws Exception {
	HttpClient httpClient =
			HttpClient.create(opts -> opts.host("localhost")
					              .port(httpServer.address().getPort()));

	Mono<List<String>> content = httpClient.get("/data")
	                                       .flatMap(f -> f.receive()
	                                                   .asString()
	                                                   .collectList())
	                                       .cache();

	List<String> res = content.block(Duration.ofSeconds(30));
	return res;
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:15,代码来源:SmokeTests.java

示例8: test

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void test() {
	NettyContext server = HttpServer.create(0)
	                                .newRouter(httpServerRoutes -> httpServerRoutes.get(
			                                "/",
			                                (httpServerRequest, httpServerResponse) -> {
				                                return httpServerResponse.sendString(
						                                Mono.error(new IllegalArgumentException()));
			                                }))
	                                .block(Duration.ofSeconds(30));

	HttpClient client = HttpClient.create(opt -> opt.host("localhost")
	                                                .port(server.address().getPort())
	                                                .disablePool());

	HttpClientResponse r = client.get("/")
	                             .block(Duration.ofSeconds(30));

	Mono<List<String>> result = r.receive()
	                    .asString(StandardCharsets.UTF_8)
	                    .collectList();

	StepVerifier.create(result)
	            .expectError(IOException.class)
	            .verify(Duration.ofSeconds(30));

	System.out.println("END");

	FutureMono.from(r.context().channel().closeFuture()).block(Duration.ofSeconds(30));

	r.dispose();
	server.dispose();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:34,代码来源:HttpErrorTests.java

示例9: httpStatusCode404IsHandledByTheClient

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void httpStatusCode404IsHandledByTheClient() {
	NettyContext server =
			HttpServer.create(0)
			          .newRouter(r -> r.post("/test", (req, res) -> res.send(req.receive()
			                                                                    .log("server-received"))))
			          .block(Duration.ofSeconds(30));

	HttpClient client = HttpClient.create("localhost", server.address().getPort());

	List<String> replyReceived = new ArrayList<>();
	Mono<String> content = client.get("/unsupportedURI", req ->
			                         req.addHeader("Content-Type", "text/plain")
			                            .sendString(Flux.just("Hello")
			                                            .log("client-send"))
			                     )
			                     .flatMapMany(res -> res.receive()
			                                            .asString()
			                                            .log("client-received")
			                                            .doOnNext(s -> replyReceived.add(s)))
			                     .next()
			                     .doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage()));

	StepVerifier.create(content)
			    .expectErrorMatches(t -> t.getMessage().equals("HTTP request failed with code: 404.\nFailing URI: " +
					"/unsupportedURI"))
			    .verify(Duration.ofSeconds(30));

	Assertions.assertThat(replyReceived).isEmpty();

	server.dispose();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:33,代码来源:HttpResponseStatusCodesHandlingTests.java

示例10: httpClient

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean
public HttpClient httpClient(@Qualifier("nettyClientOptions") Consumer<? super HttpClientOptions.Builder> options) {
	return HttpClient.create(options);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:6,代码来源:GatewayAutoConfiguration.java

示例11: webSocketRespondsToRequestsFromClients

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void webSocketRespondsToRequestsFromClients() {
	AtomicInteger clientRes = new AtomicInteger();
	AtomicInteger serverRes = new AtomicInteger();

	NettyContext server =
			HttpServer.create(0)
			          .newRouter(r -> r.get("/test/{param}", (req, res) -> {
			              System.out.println(req.requestHeaders().get("test"));
			              return res.header("content-type", "text/plain")
			                        .sendWebsocket((in, out) ->
			                            out.options(c -> c.flushOnEach())
			                               .sendString(in.receive()
			                                             .asString()
			                                             .publishOn(Schedulers.single())
			                                             .doOnNext(s -> serverRes.incrementAndGet())
			                                             .map(it -> it + ' ' + req.param("param") + '!')
			                                             .log("server-reply")));
			          }))
			          .block(Duration.ofSeconds(5));

	HttpClient client = HttpClient.create("localhost", server.address().getPort());

	Mono<List<String>> response =
	    client.get("/test/World", req ->
	              req.header("Content-Type", "text/plain")
	                 .header("test", "test")
	                 .options(c -> c.flushOnEach())
	                 .sendWebsocket()
	                 .sendString(Flux.range(1, 1000)
	                                 .log("client-send")
	                                 .map(i -> "" + i)))
	          .flatMapMany(res -> res.receive()
	                                 .asString()
	                                 .log("client-received")
	                                 .publishOn(Schedulers.parallel())
	                                 .doOnNext(s -> clientRes.incrementAndGet()))
	          .take(1000)
	          .collectList()
	          .cache()
	          .doOnError(i -> System.err.println("Failed requesting server: " + i));

	System.out.println("STARTING: server[" + serverRes.get() + "] / client[" + clientRes.get() + "]");

	StepVerifier.create(response)
	            .expectNextMatches(list -> "1000 World!".equals(list.get(999)))
	            .expectComplete()
	            .verify(Duration.ofSeconds(30));

	System.out.println("FINISHED: server[" + serverRes.get() + "] / client[" + clientRes + "]");

	server.dispose();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:54,代码来源:HttpTests.java

示例12: httpClient

import reactor.ipc.netty.http.client.HttpClient; //导入方法依赖的package包/类
@Bean
HttpClient httpClient() {
    return HttpClient.create();
}
 
开发者ID:cloudfoundry,项目名称:java-buildpack-dependency-builder,代码行数:5,代码来源:CommonConfiguration.java


注:本文中的reactor.ipc.netty.http.client.HttpClient.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。