Search in sources :

Example 1 with ReactorClientHttpConnector

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);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ReactorClientHttpConnector(cn.taketoday.http.client.reactive.ReactorClientHttpConnector)

Example 2 with ReactorClientHttpConnector

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();
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl) WebClient(cn.taketoday.web.reactive.function.client.WebClient) ReactorClientHttpConnector(cn.taketoday.http.client.reactive.ReactorClientHttpConnector) Test(org.junit.jupiter.api.Test)

Example 3 with ReactorClientHttpConnector

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HttpClient(reactor.netty.http.client.HttpClient) Http11SslContextSpec(reactor.netty.http.Http11SslContextSpec) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) ReactorClientHttpConnector(cn.taketoday.http.client.reactive.ReactorClientHttpConnector) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 4 with ReactorClientHttpConnector

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);
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl) WebClient(cn.taketoday.web.reactive.function.client.WebClient) ReactorClientHttpConnector(cn.taketoday.http.client.reactive.ReactorClientHttpConnector)

Example 5 with ReactorClientHttpConnector

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HttpClient(reactor.netty.http.client.HttpClient) Http11SslContextSpec(reactor.netty.http.Http11SslContextSpec) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) ReactorClientHttpConnector(cn.taketoday.http.client.reactive.ReactorClientHttpConnector) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Aggregations

ReactorClientHttpConnector (cn.taketoday.http.client.reactive.ReactorClientHttpConnector)12 Ssl (cn.taketoday.framework.web.server.Ssl)6 WebClient (cn.taketoday.web.reactive.function.client.WebClient)6 Http11SslContextSpec (reactor.netty.http.Http11SslContextSpec)4 HttpClient (reactor.netty.http.client.HttpClient)4 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 InetSocketAddress (java.net.InetSocketAddress)2 KeyStore (java.security.KeyStore)2 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)2 Test (org.junit.jupiter.api.Test)2