Search in sources :

Example 1 with ReactorClientHttpConnector

use of org.springframework.http.client.reactive.ReactorClientHttpConnector in project pinpoint by naver.

the class SpringWebfluxPluginController method clientUnknown.

@GetMapping("/client/unknown")
public Mono<String> clientUnknown() {
    WebClient client = WebClient.builder().clientConnector(new ReactorClientHttpConnector()).baseUrl("http://falfjlajdflajflajlf").build();
    // WebClient client = WebClient.create("http://falfjlajdflajflajlf");
    WebClient.ResponseSpec response = client.method(HttpMethod.GET).uri("").retrieve();
    return response.bodyToMono(String.class);
}
Also used : WebClient(org.springframework.web.reactive.function.client.WebClient) ReactorClientHttpConnector(org.springframework.http.client.reactive.ReactorClientHttpConnector) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with ReactorClientHttpConnector

use of org.springframework.http.client.reactive.ReactorClientHttpConnector in project spring-boot by spring-projects.

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(org.springframework.boot.web.server.Ssl) WebClient(org.springframework.web.reactive.function.client.WebClient) ReactorClientHttpConnector(org.springframework.http.client.reactive.ReactorClientHttpConnector)

Example 3 with ReactorClientHttpConnector

use of org.springframework.http.client.reactive.ReactorClientHttpConnector in project spring-boot by spring-projects.

the class AbstractReactiveWebServerFactoryTests method testBasicSslWithKeyStore.

protected final void testBasicSslWithKeyStore(String keyStore, String keyPassword) {
    AbstractReactiveWebServerFactory factory = getFactory();
    Ssl ssl = new Ssl();
    ssl.setKeyStore(keyStore);
    ssl.setKeyPassword(keyPassword);
    ssl.setKeyStorePassword("secret");
    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);
    assertThat(result.block(Duration.ofSeconds(30))).isEqualTo("Hello World");
}
Also used : Ssl(org.springframework.boot.web.server.Ssl) WebClient(org.springframework.web.reactive.function.client.WebClient) ReactorClientHttpConnector(org.springframework.http.client.reactive.ReactorClientHttpConnector)

Example 4 with ReactorClientHttpConnector

use of org.springframework.http.client.reactive.ReactorClientHttpConnector in project spring-boot by spring-projects.

the class AbstractReactiveWebServerFactoryTests method buildTrustAllSslWithClientKeyConnector.

protected ReactorClientHttpConnector buildTrustAllSslWithClientKeyConnector() throws Exception {
    KeyStore clientKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    try (InputStream stream = new FileInputStream("src/test/resources/test.jks")) {
        clientKeyStore.load(stream, "secret".toCharArray());
    }
    KeyManagerFactory clientKeyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    clientKeyManagerFactory.init(clientKeyStore, "password".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(org.springframework.http.client.reactive.ReactorClientHttpConnector) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 5 with ReactorClientHttpConnector

use of org.springframework.http.client.reactive.ReactorClientHttpConnector in project spring-boot by spring-projects.

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(org.springframework.boot.web.server.Ssl) WebClient(org.springframework.web.reactive.function.client.WebClient) ReactorClientHttpConnector(org.springframework.http.client.reactive.ReactorClientHttpConnector) Test(org.junit.jupiter.api.Test)

Aggregations

ReactorClientHttpConnector (org.springframework.http.client.reactive.ReactorClientHttpConnector)9 WebClient (org.springframework.web.reactive.function.client.WebClient)5 Ssl (org.springframework.boot.web.server.Ssl)3 HttpClient (reactor.netty.http.client.HttpClient)3 Http11SslContextSpec (reactor.netty.http.Http11SslContextSpec)2 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)1 ReadTimeoutHandler (io.netty.handler.timeout.ReadTimeoutHandler)1 WriteTimeoutHandler (io.netty.handler.timeout.WriteTimeoutHandler)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 KeyStore (java.security.KeyStore)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1 Test (org.junit.jupiter.api.Test)1 Bean (org.springframework.context.annotation.Bean)1 ClientHttpConnector (org.springframework.http.client.reactive.ClientHttpConnector)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1