Java Code Examples for reactor.netty.http.client.httpclient#create()

The following examples show how to use reactor.netty.http.client.httpclient#create() . 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: TitusWebClientAddOns.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
public static WebClient.Builder addTitusDefaults(WebClient.Builder clientBuilder,
                                                 boolean secure,
                                                 WebClientMetric webClientMetric) {
    HttpClient httpClient = HttpClient.create();
    // SSL
    if (secure) {
        try {
            SslContext sslContext = SslContextBuilder.forClient().build();
            httpClient = httpClient.secure(spec -> spec.sslContext(sslContext));
        } catch (SSLException e) {
            logger.error("Unable configure Docker registry client SSL context: {}", e.getMessage());
            throw new RuntimeException("Error configuring SSL context", e);
        }
    }

    return addTitusDefaults(clientBuilder, httpClient, webClientMetric);
}
 
Example 2
Source File: ClientHttpConnectorFactory.java    From spring-vault with Apache License 2.0 6 votes vote down vote up
static ClientHttpConnector usingReactorNetty(ClientOptions options, SslConfiguration sslConfiguration) {
	HttpClient client = HttpClient.create();

	if (hasSslConfiguration(sslConfiguration)) {

		SslContextBuilder sslContextBuilder = SslContextBuilder.forClient();
		configureSsl(sslConfiguration, sslContextBuilder);

		client = client.secure(builder -> {
			builder.sslContext(sslContextBuilder);
		});
	}

	client = client.tcpConfiguration(it -> it.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
			Math.toIntExact(options.getConnectionTimeout().toMillis())));

	return new ReactorClientHttpConnector(client);
}
 
Example 3
Source File: ClientHttpConnectorFactory.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@link ClientHttpConnector} for the given {@link ClientOptions}.
 * @param options must not be {@literal null}
 * @return a new {@link ClientHttpConnector}.
 */
public static ClientHttpConnector create(ClientOptions options) {
	HttpClient httpClient = HttpClient.create();

	if (usingCustomCerts(options)) {
		TrustManagerFactory trustManagerFactory = sslCertificateUtils
				.createTrustManagerFactory(options.getCaCertFiles());

		httpClient = httpClient.secure((sslContextSpec) -> sslContextSpec.sslContext(
				SslContextBuilder.forClient().sslProvider(SslProvider.JDK).trustManager(trustManagerFactory)));
	}
	else {
		httpClient = httpClient.secure((sslContextSpec) -> {
			try {
				sslContextSpec.sslContext(new JdkSslContext(SSLContext.getDefault(), true, null,
						IdentityCipherSuiteFilter.INSTANCE, null, ClientAuth.REQUIRE, null, false));
			}
			catch (NoSuchAlgorithmException ex) {
				logger.error("Error configuring HTTP connections", ex);
				throw new RuntimeException("Error configuring HTTP connections", ex);
			}
		});
	}

	if (options.getConnectionTimeout() != null) {
		httpClient = httpClient
				.tcpConfiguration((tcpClient) -> tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
						Math.toIntExact(options.getConnectionTimeout().toMillis())));
	}

	return new ReactorClientHttpConnector(httpClient);
}
 
Example 4
Source File: ReactorHttpRpcClient.java    From etherjar with Apache License 2.0 5 votes vote down vote up
public ReactorHttpRpcClient build() {
    if (transportType == null) {
        transportType = TransportType.BATCH;
    }
    if (target == null) {
        target = Mono.just("http://127.0.0.1:8545");
    }
    if (rpcConverter == null) {
        rpcConverter = new JacksonRpcConverter();
    }
    HttpClient clientBuilder = HttpClient.create();
    if (headers != null) {
        clientBuilder = clientBuilder.headers(headers);
    }
    clientBuilder = clientBuilder.headers((h) -> {
        h.add(HttpHeaderNames.CONTENT_TYPE, "application/json");
    });
    if (sslProviderBuilder != null) {
        clientBuilder = clientBuilder.secure(sslProviderBuilder);
    }
    ReactorRpcTransport transport;
    if (transportType == TransportType.BATCH) {
        BatchToString batchToString = new BatchToString(rpcConverter);
        transport = new BatchTransport(clientBuilder, target, rpcConverter, batchToString);
    } else if (transportType == TransportType.SEPARATED) {
        transport = new SeparatedTransport(clientBuilder, target, rpcConverter);
    } else {
        throw new IllegalStateException("Transport type cannot be null");
    }
    return new ReactorHttpRpcClient(transport);
}
 
Example 5
Source File: HttpServerTests.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
@Test
public void testHttpServerWithDomainSockets() throws Exception {
	HttpServer server = HttpServer.create();
	HttpClient client = HttpClient.create();

	doTestHttpServerWithDomainSockets(server, client);

	SelfSignedCertificate cert = new SelfSignedCertificate();
	SslContextBuilder serverCtx = SslContextBuilder.forServer(cert.certificate(), cert.privateKey());
	SslContextBuilder clientCtx = SslContextBuilder.forClient()
	                                               .trustManager(InsecureTrustManagerFactory.INSTANCE);
	doTestHttpServerWithDomainSockets(
			server.protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)),
			client.protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)));
}
 
Example 6
Source File: WebFluxIT.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
    new CreateTraceEntry().traceEntryMarker();
    HttpClient httpClient = HttpClient.create();
    return httpClient.baseUrl("http://example.org")
            .get()
            .response()
            .doOnError(t -> {
                t.printStackTrace();
            }).doOnNext(res -> {
                response.writeWith(
                        Mono.just(response.bufferFactory().wrap("xyzo".getBytes())));
            }).then();
}
 
Example 7
Source File: ReactorNettyWebSocketClient.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Default constructor.
 */
public ReactorNettyWebSocketClient() {
	this(HttpClient.create());
}
 
Example 8
Source File: Module.java    From reactor-guice with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
public HttpClient httpClient () {
    return HttpClient.create();
}
 
Example 9
Source File: ReactorNettyWebSocketClient.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Default constructor.
 */
public ReactorNettyWebSocketClient() {
	this(HttpClient.create());
}
 
Example 10
Source File: ReactorNettySender.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public ReactorNettySender() {
    this(HttpClient.create());
}
 
Example 11
Source File: Http2Tests.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testMaxHttp2ConnectionsNegative() {
	HttpClient.create(ConnectionProvider.create("testMaxHttp2ConnectionsNegative", 1), -1);
}
 
Example 12
Source File: Http2Tests.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testMaxHttp2ConnectionsZero() {
	HttpClient.create(ConnectionProvider.create("testMaxHttp2ConnectionsZero", 1), 0);
}
 
Example 13
Source File: ReactorNettyHttpClientSpringBootTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
HttpClient reactorHttpClient() {
	return HttpClient.create();
}