use of cn.taketoday.http.client.reactive.ReactorClientHttpConnector in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method getWebClient.
protected WebClient.Builder getWebClient(HttpClient client, int port) {
InetSocketAddress address = new InetSocketAddress(port);
String baseUrl = "http://" + address.getHostString() + ":" + address.getPort();
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(client)).baseUrl(baseUrl);
}
use of cn.taketoday.http.client.reactive.ReactorClientHttpConnector in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method sslWithValidAlias.
@Test
void sslWithValidAlias() {
String keyStore = "classpath:test.jks";
String keyPassword = "password";
AbstractReactiveWebServerFactory factory = getFactory();
Ssl ssl = new Ssl();
ssl.setKeyStore(keyStore);
ssl.setKeyStorePassword("secret");
ssl.setKeyPassword(keyPassword);
ssl.setKeyAlias("test-alias");
factory.setSsl(ssl);
this.webServer = factory.getWebServer(new EchoHandler());
this.webServer.start();
ReactorClientHttpConnector connector = buildTrustAllSslConnector();
WebClient client = WebClient.builder().baseUrl("https://localhost:" + this.webServer.getPort()).clientConnector(connector).build();
Mono<String> result = client.post().uri("/test").contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromValue("Hello World")).retrieve().bodyToMono(String.class);
StepVerifier.setDefaultTimeout(Duration.ofSeconds(30));
StepVerifier.create(result).expectNext("Hello World").verifyComplete();
}
use of cn.taketoday.http.client.reactive.ReactorClientHttpConnector in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method buildTrustAllSslWithClientKeyConnector.
protected ReactorClientHttpConnector buildTrustAllSslWithClientKeyConnector(String keyStoreFile, String keyStorePassword) throws Exception {
KeyStore clientKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream stream = new FileInputStream("src/test/resources/" + keyStoreFile)) {
clientKeyStore.load(stream, "secret".toCharArray());
}
KeyManagerFactory clientKeyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
clientKeyManagerFactory.init(clientKeyStore, keyStorePassword.toCharArray());
Http11SslContextSpec sslContextSpec = Http11SslContextSpec.forClient().configure((builder) -> builder.sslProvider(SslProvider.JDK).trustManager(InsecureTrustManagerFactory.INSTANCE).keyManager(clientKeyManagerFactory));
HttpClient client = HttpClient.create().wiretap(true).secure((spec) -> spec.sslContext(sslContextSpec));
return new ReactorClientHttpConnector(client);
}
use of cn.taketoday.http.client.reactive.ReactorClientHttpConnector in project today-infrastructure by TAKETODAY.
the class NettyReactiveWebServerFactoryTests method testSslWithAlias.
protected Mono<String> testSslWithAlias(String alias) {
String keyStore = "classpath:test.jks";
String keyPassword = "password";
NettyReactiveWebServerFactory factory = getFactory();
Ssl ssl = new Ssl();
ssl.setKeyStore(keyStore);
ssl.setKeyPassword(keyPassword);
ssl.setKeyAlias(alias);
factory.setSsl(ssl);
this.webServer = factory.getWebServer(new EchoHandler());
this.webServer.start();
ReactorClientHttpConnector connector = buildTrustAllSslConnector();
WebClient client = WebClient.builder().baseUrl("https://localhost:" + this.webServer.getPort()).clientConnector(connector).build();
return client.post().uri("/test").contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromValue("Hello World")).retrieve().bodyToMono(String.class);
}
use of cn.taketoday.http.client.reactive.ReactorClientHttpConnector in project today-framework by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method buildTrustAllSslWithClientKeyConnector.
protected ReactorClientHttpConnector buildTrustAllSslWithClientKeyConnector(String keyStoreFile, String keyStorePassword) throws Exception {
KeyStore clientKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream stream = new FileInputStream("src/test/resources/" + keyStoreFile)) {
clientKeyStore.load(stream, "secret".toCharArray());
}
KeyManagerFactory clientKeyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
clientKeyManagerFactory.init(clientKeyStore, keyStorePassword.toCharArray());
Http11SslContextSpec sslContextSpec = Http11SslContextSpec.forClient().configure((builder) -> builder.sslProvider(SslProvider.JDK).trustManager(InsecureTrustManagerFactory.INSTANCE).keyManager(clientKeyManagerFactory));
HttpClient client = HttpClient.create().wiretap(true).secure((spec) -> spec.sslContext(sslContextSpec));
return new ReactorClientHttpConnector(client);
}
Aggregations