Add SSL bundle support to WebClient auto-configuration
Introduce `WebClientSsl` interface and auto-configuration to allow a WebClient builder to have custom SSL configuration applied. The previous `ClientHttpConnectorConfiguration` has been been changed to now create `ClientHttpConnectorFactory` instances which can be used directly or by `AutoConfiguredWebClientSsl`. Closes gh-18556pull/35111/head
parent
c59c8cc674
commit
6ea2547de4
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive.function.client;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.boot.ssl.SslBundles;
|
||||
import org.springframework.http.client.reactive.ClientHttpConnector;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
/**
|
||||
* An auto-configured {@link WebClientSsl} implementation.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class AutoConfiguredWebClientSsl implements WebClientSsl {
|
||||
|
||||
private final ClientHttpConnectorFactory<?> clientHttpConnectorFactory;
|
||||
|
||||
private final SslBundles sslBundles;
|
||||
|
||||
AutoConfiguredWebClientSsl(ClientHttpConnectorFactory<?> clientHttpConnectorFactory, SslBundles sslBundles) {
|
||||
this.clientHttpConnectorFactory = clientHttpConnectorFactory;
|
||||
this.sslBundles = sslBundles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Consumer<WebClient.Builder> fromBundle(String bundleName) {
|
||||
return fromBundle(this.sslBundles.getBundle(bundleName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Consumer<WebClient.Builder> fromBundle(SslBundle bundle) {
|
||||
return (builder) -> {
|
||||
ClientHttpConnector connector = this.clientHttpConnectorFactory.createClientHttpConnector(bundle);
|
||||
builder.clientConnector(connector);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive.function.client;
|
||||
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.http.client.reactive.ClientHttpConnector;
|
||||
|
||||
/**
|
||||
* Internal factory used to create {@link ClientHttpConnector} instances.
|
||||
*
|
||||
* @param <T> the {@link ClientHttpConnector} type
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface ClientHttpConnectorFactory<T extends ClientHttpConnector> {
|
||||
|
||||
default T createClientHttpConnector() {
|
||||
return createClientHttpConnector(null);
|
||||
}
|
||||
|
||||
T createClientHttpConnector(SslBundle sslBundle);
|
||||
|
||||
}
|
53
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorConfiguration.java → spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorFactoryConfiguration.java
53
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorConfiguration.java → spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorFactoryConfiguration.java
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive.function.client;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
import javax.net.ssl.SSLException;
|
||||
|
||||
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
|
||||
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
|
||||
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
|
||||
import org.apache.hc.client5.http.nio.AsyncClientConnectionManager;
|
||||
import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy;
|
||||
import org.apache.hc.core5.net.NamedEndpoint;
|
||||
import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
|
||||
import org.apache.hc.core5.reactor.ssl.TlsDetails;
|
||||
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.boot.ssl.SslOptions;
|
||||
import org.springframework.http.client.reactive.HttpComponentsClientHttpConnector;
|
||||
|
||||
/**
|
||||
* {@link ClientHttpConnectorFactory} for {@link HttpComponentsClientHttpConnector}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class HttpComponentsClientHttpConnectorFactory
|
||||
implements ClientHttpConnectorFactory<HttpComponentsClientHttpConnector> {
|
||||
|
||||
@Override
|
||||
public HttpComponentsClientHttpConnector createClientHttpConnector(SslBundle sslBundle) {
|
||||
HttpAsyncClientBuilder builder = HttpAsyncClients.custom();
|
||||
if (sslBundle != null) {
|
||||
SslOptions options = sslBundle.getOptions();
|
||||
SSLContext sslContext = sslBundle.createSslContext();
|
||||
SSLSessionVerifier sessionVerifier = new SSLSessionVerifier() {
|
||||
|
||||
@Override
|
||||
public TlsDetails verify(NamedEndpoint endpoint, SSLEngine sslEngine) throws SSLException {
|
||||
if (options.getCiphers() != null) {
|
||||
sslEngine.setEnabledCipherSuites(options.getCiphers().toArray(String[]::new));
|
||||
}
|
||||
if (options.getEnabledProtocols() != null) {
|
||||
sslEngine.setEnabledProtocols(options.getEnabledProtocols().toArray(String[]::new));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
BasicClientTlsStrategy tlsStrategy = new BasicClientTlsStrategy(sslContext, sessionVerifier);
|
||||
AsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder.create()
|
||||
.setTlsStrategy(tlsStrategy)
|
||||
.build();
|
||||
builder.setConnectionManager(connectionManager);
|
||||
}
|
||||
return new HttpComponentsClientHttpConnector(builder.build());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive.function.client;
|
||||
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpClient.Builder;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.http.client.reactive.JdkClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.JettyClientHttpConnector;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* {@link ClientHttpConnectorFactory} for {@link JettyClientHttpConnector}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class JdkClientHttpConnectorFactory implements ClientHttpConnectorFactory<JdkClientHttpConnector> {
|
||||
|
||||
@Override
|
||||
public JdkClientHttpConnector createClientHttpConnector(SslBundle sslBundle) {
|
||||
Builder builder = HttpClient.newBuilder();
|
||||
if (sslBundle != null) {
|
||||
builder.sslContext(sslBundle.createSslContext());
|
||||
SSLParameters parameters = new SSLParameters();
|
||||
parameters.setCipherSuites(asArray(sslBundle.getOptions().getCiphers()));
|
||||
parameters.setProtocols(asArray(sslBundle.getOptions().getEnabledProtocols()));
|
||||
builder.sslParameters(parameters);
|
||||
}
|
||||
return new JdkClientHttpConnector(builder.build());
|
||||
}
|
||||
|
||||
private String[] asArray(Set<String> set) {
|
||||
return (CollectionUtils.isEmpty(set)) ? null : set.toArray(String[]::new);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive.function.client;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP;
|
||||
import org.eclipse.jetty.io.ClientConnector;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.boot.ssl.SslOptions;
|
||||
import org.springframework.http.client.reactive.JdkClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.JettyClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.JettyResourceFactory;
|
||||
|
||||
/**
|
||||
* {@link ClientHttpConnectorFactory} for {@link JdkClientHttpConnector}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class JettyClientHttpConnectorFactory implements ClientHttpConnectorFactory<JettyClientHttpConnector> {
|
||||
|
||||
private final JettyResourceFactory jettyResourceFactory;
|
||||
|
||||
JettyClientHttpConnectorFactory(JettyResourceFactory jettyResourceFactory) {
|
||||
this.jettyResourceFactory = jettyResourceFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JettyClientHttpConnector createClientHttpConnector(SslBundle sslBundle) {
|
||||
SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
|
||||
if (sslBundle != null) {
|
||||
SslOptions options = sslBundle.getOptions();
|
||||
if (options.getCiphers() != null) {
|
||||
sslContextFactory.setIncludeCipherSuites(options.getCiphers().toArray(String[]::new));
|
||||
sslContextFactory.setExcludeCipherSuites();
|
||||
}
|
||||
if (options.getEnabledProtocols() != null) {
|
||||
sslContextFactory.setIncludeProtocols(options.getEnabledProtocols().toArray(String[]::new));
|
||||
sslContextFactory.setExcludeProtocols();
|
||||
}
|
||||
sslContextFactory.setSslContext(sslBundle.createSslContext());
|
||||
}
|
||||
ClientConnector connector = new ClientConnector();
|
||||
connector.setSslContextFactory(sslContextFactory);
|
||||
HttpClientTransportOverHTTP transport = new HttpClientTransportOverHTTP(connector);
|
||||
HttpClient httpClient = new HttpClient(transport);
|
||||
return new JettyClientHttpConnector(httpClient, this.jettyResourceFactory);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive.function.client;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.net.ssl.SSLException;
|
||||
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
import reactor.netty.tcp.SslProvider.SslContextSpec;
|
||||
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.boot.ssl.SslManagerBundle;
|
||||
import org.springframework.boot.ssl.SslOptions;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.ReactorResourceFactory;
|
||||
import org.springframework.util.function.ThrowingConsumer;
|
||||
|
||||
/**
|
||||
* {@link ClientHttpConnectorFactory} for {@link ReactorClientHttpConnectorFactory}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class ReactorClientHttpConnectorFactory implements ClientHttpConnectorFactory<ReactorClientHttpConnector> {
|
||||
|
||||
private final ReactorResourceFactory reactorResourceFactory;
|
||||
|
||||
private final Supplier<Stream<ReactorNettyHttpClientMapper>> mappers;
|
||||
|
||||
ReactorClientHttpConnectorFactory(ReactorResourceFactory reactorResourceFactory) {
|
||||
this(reactorResourceFactory, Stream::empty);
|
||||
}
|
||||
|
||||
ReactorClientHttpConnectorFactory(ReactorResourceFactory reactorResourceFactory,
|
||||
Supplier<Stream<ReactorNettyHttpClientMapper>> mappers) {
|
||||
this.reactorResourceFactory = reactorResourceFactory;
|
||||
this.mappers = mappers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactorClientHttpConnector createClientHttpConnector(SslBundle sslBundle) {
|
||||
ReactorNettyHttpClientMapper mapper = this.mappers.get()
|
||||
.reduce((before, after) -> (client) -> after.configure(before.configure(client)))
|
||||
.orElse((client) -> client);
|
||||
if (sslBundle != null) {
|
||||
mapper = new SslConfigurer(sslBundle)::configure;
|
||||
}
|
||||
return new ReactorClientHttpConnector(this.reactorResourceFactory, mapper::configure);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the Netty {@link HttpClient} with SSL.
|
||||
*/
|
||||
private static class SslConfigurer {
|
||||
|
||||
private final SslBundle sslBundle;
|
||||
|
||||
SslConfigurer(SslBundle sslBundle) {
|
||||
this.sslBundle = sslBundle;
|
||||
}
|
||||
|
||||
HttpClient configure(HttpClient httpClient) {
|
||||
return httpClient.secure(ThrowingConsumer.of(this::customizeSsl).throwing(IllegalStateException::new));
|
||||
}
|
||||
|
||||
private void customizeSsl(SslContextSpec spec) throws SSLException {
|
||||
SslOptions options = this.sslBundle.getOptions();
|
||||
SslManagerBundle managers = this.sslBundle.getManagers();
|
||||
SslContextBuilder builder = SslContextBuilder.forClient()
|
||||
.keyManager(managers.getKeyManagerFactory())
|
||||
.trustManager(managers.getTrustManagerFactory())
|
||||
.ciphers(options.getCiphers())
|
||||
.protocols(options.getEnabledProtocols());
|
||||
spec.sslContext(builder.build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive.function.client;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.boot.ssl.NoSuchSslBundleException;
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.http.client.reactive.ClientHttpConnector;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
/**
|
||||
* Interface that can be used to {@link WebClient.Builder#apply apply} SSL configuration
|
||||
* to a {@link org.springframework.web.reactive.function.client.WebClient.Builder
|
||||
* WebClient.Builder}.
|
||||
* <p>
|
||||
* Typically used as follows: <pre class="code">
|
||||
* @Bean
|
||||
* public MyBean myBean(WebClient.Builder webClientBuilder, WebClientSsl ssl) {
|
||||
* WebClient webClient = webClientBuilder.apply(ssl.forBundle("mybundle")).build();
|
||||
* return new MyBean(webClient);
|
||||
* }
|
||||
* </pre> NOTE: Apply SSL configuration will replace any previously
|
||||
* {@link WebClient.Builder#clientConnector configured} {@link ClientHttpConnector}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public interface WebClientSsl {
|
||||
|
||||
/**
|
||||
* Return a {@link Consumer} that will apply SSL configuration for the named
|
||||
* {@link SslBundle} to a
|
||||
* {@link org.springframework.web.reactive.function.client.WebClient.Builder
|
||||
* WebClient.Builder}.
|
||||
* @param bundleName the name of the SSL bundle to apply
|
||||
* @return a {@link Consumer} to apply the configuration
|
||||
* @throws NoSuchSslBundleException if a bundle with the provided name does not exist
|
||||
*/
|
||||
Consumer<WebClient.Builder> fromBundle(String bundleName) throws NoSuchSslBundleException;
|
||||
|
||||
/**
|
||||
* Return a {@link Consumer} that will apply SSL configuration for the
|
||||
* {@link SslBundle} to a
|
||||
* {@link org.springframework.web.reactive.function.client.WebClient.Builder
|
||||
* WebClient.Builder}.
|
||||
* @param bundle the SSL bundle to apply
|
||||
* @return a {@link Consumer} to apply the configuration
|
||||
*/
|
||||
Consumer<WebClient.Builder> fromBundle(SslBundle bundle);
|
||||
|
||||
}
|
21
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorConfigurationTests.java → spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorFactoryConfigurationTests.java
21
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorConfigurationTests.java → spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorFactoryConfigurationTests.java
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive.function.client;
|
||||
|
||||
/**
|
||||
* Tests for {@link HttpComponentsClientHttpConnectorFactory}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class HttpComponentsClientHttpConnectorFactoryTests extends AbstractClientHttpConnectorFactoryTests {
|
||||
|
||||
@Override
|
||||
protected ClientHttpConnectorFactory<?> getFactory() {
|
||||
return new HttpComponentsClientHttpConnectorFactory();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive.function.client;
|
||||
|
||||
/**
|
||||
* Tests for {@link JdkClientHttpConnectorFactory}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class JdkClientHttpConnectorFactoryTests extends AbstractClientHttpConnectorFactoryTests {
|
||||
|
||||
@Override
|
||||
protected ClientHttpConnectorFactory<?> getFactory() {
|
||||
return new JdkClientHttpConnectorFactory();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive.function.client;
|
||||
|
||||
import org.springframework.http.client.reactive.JettyResourceFactory;
|
||||
|
||||
/**
|
||||
* Tests for {@link JettyClientHttpConnectorFactory}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class JettyClientHttpConnectorFactoryTests extends AbstractClientHttpConnectorFactoryTests {
|
||||
|
||||
@Override
|
||||
protected ClientHttpConnectorFactory<?> getFactory() {
|
||||
JettyResourceFactory resourceFactory = new JettyResourceFactory();
|
||||
return new JettyClientHttpConnectorFactory(resourceFactory);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive.function.client;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
import org.springframework.http.client.reactive.ReactorResourceFactory;
|
||||
|
||||
/**
|
||||
* Tests for {@link ReactorClientHttpConnectorFactory}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class ReactorClientHttpConnectorFactoryTests extends AbstractClientHttpConnectorFactoryTests {
|
||||
|
||||
private ReactorResourceFactory resourceFactory;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.resourceFactory = new ReactorResourceFactory();
|
||||
this.resourceFactory.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void teardown() {
|
||||
this.resourceFactory.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClientHttpConnectorFactory<?> getFactory() {
|
||||
return new ReactorClientHttpConnectorFactory(this.resourceFactory);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.io.restclient.webclient.ssl;
|
||||
|
||||
import org.neo4j.cypherdsl.core.Relationship.Details;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientSsl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
@Service
|
||||
public class MyService {
|
||||
|
||||
private final WebClient webClient;
|
||||
|
||||
public MyService(WebClient.Builder webClientBuilder, WebClientSsl ssl) {
|
||||
this.webClient = webClientBuilder.baseUrl("https://example.org").apply(ssl.fromBundle("mybundle")).build();
|
||||
}
|
||||
|
||||
public Mono<Details> someRestCall(String name) {
|
||||
return this.webClient.get().uri("/{name}/details", name).retrieve().bodyToMono(Details.class);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.io.restclient.webclient.ssl
|
||||
|
||||
import org.neo4j.cypherdsl.core.Relationship
|
||||
import org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientSsl
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.web.reactive.function.client.WebClient
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Service
|
||||
class MyService(webClientBuilder: WebClient.Builder, ssl: WebClientSsl) {
|
||||
|
||||
private val webClient: WebClient
|
||||
|
||||
init {
|
||||
webClient = webClientBuilder.baseUrl("https://example.org").apply(ssl.fromBundle("mybundle")).build()
|
||||
}
|
||||
|
||||
fun someRestCall(name: String?): Mono<Relationship.Details> {
|
||||
return webClient.get().uri("/{name}/details", name).retrieve().bodyToMono(
|
||||
Relationship.Details::class.java
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue