本文整理了Java中reactor.netty.http.client.HttpClient.secure()
方法的一些代码示例,展示了HttpClient.secure()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.secure()
方法的具体详情如下:
包路径:reactor.netty.http.client.HttpClient
类名称:HttpClient
方法名:secure
[英]Enable default sslContext support. The default SslContext will be assigned to with a default value of 10 seconds handshake timeout unless the environment property reactor.netty.tcp.sslHandshakeTimeout is set.
[中]启用默认sslContext支持。默认SslContext将被分配给,默认值为10秒握手超时,除非环境属性为reactor。内蒂。tcp。已设置sslHandshakeTimeout。
代码示例来源:origin: spring-projects/spring-data-elasticsearch
private static WebClientProvider getWebClientProvider(ClientConfiguration clientConfiguration) {
Duration connectTimeout = clientConfiguration.getConnectTimeout();
Duration soTimeout = clientConfiguration.getSocketTimeout();
TcpClient tcpClient = TcpClient.create();
if (!connectTimeout.isNegative()) {
tcpClient = tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.toIntExact(connectTimeout.toMillis()));
}
if (!soTimeout.isNegative()) {
tcpClient = tcpClient.doOnConnected(connection -> connection //
.addHandlerLast(new ReadTimeoutHandler(soTimeout.toMillis(), TimeUnit.MILLISECONDS))
.addHandlerLast(new WriteTimeoutHandler(soTimeout.toMillis(), TimeUnit.MILLISECONDS)));
}
String scheme = "http";
HttpClient httpClient = HttpClient.from(tcpClient);
if (clientConfiguration.useSsl()) {
httpClient = httpClient.secure(sslConfig -> {
Optional<SSLContext> sslContext = clientConfiguration.getSslContext();
sslContext.ifPresent(it -> sslConfig.sslContext(new JdkSslContext(it, true, ClientAuth.NONE)));
});
scheme = "https";
}
ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
WebClientProvider provider = WebClientProvider.create(scheme, connector);
return provider.withDefaultHeaders(clientConfiguration.getDefaultHeaders());
}
代码示例来源:origin: spring-cloud/spring-cloud-gateway
@Before
public void setup() {
try {
SslContext sslContext = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
HttpClient httpClient = HttpClient.create().secure(ssl -> {
ssl.sslContext(sslContext);
});
ClientHttpConnector httpConnector = new ReactorClientHttpConnector(
httpClient);
baseUri = "https://localhost:" + port;
this.webClient = WebClient.builder().clientConnector(httpConnector)
.baseUrl(baseUri).build();
this.testClient = WebTestClient.bindToServer(httpConnector).baseUrl(baseUri).build();
}
catch (SSLException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: spring-cloud/spring-cloud-gateway
if (ssl.getTrustedX509CertificatesForTrustManager().length > 0
|| ssl.isUseInsecureTrustManager()) {
httpClient = httpClient.secure(sslContextSpec -> {
代码示例来源:origin: org.springframework.boot/spring-boot-actuator-autoconfigure
protected ReactorClientHttpConnector buildTrustAllSslConnector() {
HttpClient client = HttpClient.create().secure(
(sslContextSpec) -> sslContextSpec.sslContext(createSslContext()));
return new ReactorClientHttpConnector(client);
}
代码示例来源:origin: reactor/reactor-netty
@Override
protected HttpClient customizeClientOptions(HttpClient httpClient) {
try {
SslContext ctx = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
return httpClient.secure(ssl -> ssl.sslContext(ctx));
}
catch (SSLException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: org.springframework.vault/spring-vault-core
/**
* Create a {@link ClientHttpConnector} for the given {@link ClientOptions} and
* {@link SslConfiguration}.
*
* @param options must not be {@literal null}
* @param sslConfiguration must not be {@literal null}
* @return a new {@link ClientHttpConnector}.
*/
public static ClientHttpConnector create(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);
}
代码示例来源:origin: reactor/reactor-netty
.secure(ssl -> ssl.sslContext(sslClient))
.post()
.uri("/upload")
代码示例来源:origin: reactor/reactor-netty
@Test
public void sslExchangeRelativeGet() 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(Duration.ofMillis(200));
context.disposeNow();
assertThat(responseString).isEqualTo("hello /foo");
}
代码示例来源:origin: reactor/reactor-netty
client = HttpClient.create()
.port(serverPort)
.secure(ssl -> ssl.sslContext(sslClient));
代码示例来源: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
.secure(spec -> spec.sslContext(
SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)));
StepVerifier.create(
client.tcpConfiguration(tcpClient -> tcpClient.doOnConnected(c -> ch3.set(c.channel())))
.secure(spec -> spec.sslContext(
SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE))
代码示例来源:origin: reactor/reactor-netty
@Test
public void testIssue473() throws Exception {
SelfSignedCertificate cert = new SelfSignedCertificate();
SslContextBuilder serverSslContextBuilder =
SslContextBuilder.forServer(cert.certificate(), cert.privateKey());
DisposableServer server =
HttpServer.create()
.port(0)
.wiretap(true)
.secure(spec -> spec.sslContext(serverSslContextBuilder))
.bindNow();
StepVerifier.create(
HttpClient.create(ConnectionProvider.newConnection())
.secure()
.websocket()
.uri("wss://" + server.host() + ":" + server.port())
.handle((in, out) -> Mono.empty()))
.expectErrorMatches(t -> t.getCause() instanceof CertificateException)
.verify(Duration.ofSeconds(30));
server.disposeNow();
}
代码示例来源:origin: reactor/reactor-netty
HttpClient.create()
.port(server.port())
.secure(ssl -> ssl.sslContext(
SslContextBuilder.forClient()
.trustManager
代码示例来源:origin: reactor/reactor-netty
@Test
// @Ignore
public void testHttpToHttp2Ssl() throws Exception {
SelfSignedCertificate cert = new SelfSignedCertificate();
SslContextBuilder serverOptions = SslContextBuilder.forServer(cert.certificate(), cert.privateKey());
DisposableServer server =
HttpServer.create()
.secure(sslContextSpec -> sslContextSpec.sslContext(serverOptions)
.defaultConfiguration(SslProvider.DefaultConfigurationType.H2))
.handle((req, res) -> res.sendString(Mono.just("Hello")))
.wiretap(true)
.bindNow();
String response =
HttpClient.create()
.port(server.port())
.secure(ssl -> ssl.sslContext(
SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)))
.wiretap(true)
.get()
.uri("/")
.responseContent()
.aggregate()
.asString()
.block(Duration.ofSeconds(30));
server.disposeNow();
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void testExplicitEmptyBodyOnGetWorks() throws Exception {
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
.build();
SslContext sslClient = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();
DisposableServer server =
HttpServer.create()
.secure(ssl -> ssl.sslContext(sslServer))
.port(0)
.handle((req, res) -> res.send(req.receive().retain()))
.bindNow();
ConnectionProvider pool = ConnectionProvider.fixed("test", 1);
for (int i = 0; i < 4; i++) {
StepVerifier.create(createHttpClientForContextWithAddress(server, pool)
.secure(ssl -> ssl.sslContext(sslClient))
.request(HttpMethod.GET)
.uri("/")
.send((req, out) -> out.send(Flux.empty()))
.responseContent())
.expectComplete()
.verify(Duration.ofSeconds(30));
}
pool.dispose();
server.disposeNow();
}
内容来源于网络,如有侵权,请联系作者删除!