Java Code Examples for reactor.netty.http.server.HttpServer#bindNow()

The following examples show how to use reactor.netty.http.server.HttpServer#bindNow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpClientTest.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
private void doTestIssue719(Publisher<ByteBuf> clientSend,
		Consumer<HttpHeaders> clientSendHeaders, boolean ssl) throws Exception {
	HttpServer server =
			HttpServer.create()
			          .port(0)
			          .wiretap(true)
			          .handle((req, res) -> req.receive()
			                                   .then(res.sendString(Mono.just("test"))
			                                            .then()));

	if (ssl) {
		SelfSignedCertificate cert = new SelfSignedCertificate();
		server = server.secure(spec -> spec.sslContext(
				SslContextBuilder.forServer(cert.certificate(), cert.privateKey())));
	}

	disposableServer = server.bindNow();

	HttpClient client = createHttpClientForContextWithAddress();
	if (ssl) {
		client = client.secure(spec ->
				spec.sslContext(SslContextBuilder.forClient()
				                                 .trustManager(InsecureTrustManagerFactory.INSTANCE)));
	}

	StepVerifier.create(
			client.headers(clientSendHeaders)
			      .post()
			      .uri("/")
			      .send(clientSend)
			      .responseContent()
			      .aggregate()
			      .asString())
	            .expectNext("test")
	            .expectComplete()
	            .verify(Duration.ofSeconds(30));

	StepVerifier.create(
			client.headers(clientSendHeaders)
			      .post()
			      .uri("/")
			      .send(clientSend)
			      .responseContent()
			      .aggregate()
			      .asString())
	            .expectNext("test")
	            .expectComplete()
	            .verify(Duration.ofSeconds(30));
}
 
Example 2
Source File: Http2Tests.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
private void doTestConcurrentStreams(HttpClient baseClient, boolean isSecured,
		HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols) throws Exception {
	SelfSignedCertificate cert = new SelfSignedCertificate();
	SslContextBuilder serverCtx = SslContextBuilder.forServer(cert.certificate(), cert.privateKey());
	SslContextBuilder clientCtx = SslContextBuilder.forClient()
	                                               .trustManager(InsecureTrustManagerFactory.INSTANCE);

	HttpServer httpServer =
			HttpServer.create()
			          .port(0)
			          .protocol(serverProtocols).wiretap(true)
			          .handle((req, res) -> res.sendString(Mono.just("test")));
	if (isSecured) {
		httpServer = httpServer.secure(spec -> spec.sslContext(serverCtx));
	}

	disposableServer = httpServer.bindNow();

	HttpClient client;
	if (isSecured) {
		client = baseClient.port(disposableServer.port()).wiretap(true)
		                   .protocol(clientProtocols)
		                   .secure(spec -> spec.sslContext(clientCtx));
	}
	else {
		client = baseClient.port(disposableServer.port())
		                   .protocol(clientProtocols);
	}

	CountDownLatch latch = new CountDownLatch(1);
	List<String> responses =
			Flux.range(0, 10)
			    .flatMapDelayError(i ->
			        client.get()
			              .uri("/")
			              .responseContent()
			              .aggregate()
			              .asString(),
			        256, 32)
			        .collectList()
			        .doFinally(fin -> latch.countDown())
			        .block(Duration.ofSeconds(30));

	assertThat(responses).isNotNull();
	assertThat(responses.size()).isEqualTo(10);
}