Skip to content

Commit

Permalink
Add http-exchange.channels[].ssl.bundle configuration (#76)
Browse files Browse the repository at this point in the history
* Add http-exchange.channels[].ssl.bundle configuration

* Add mtls example

* feat: update example MER-2475

* update tag since 3.4.1

* rm mtls example

* update bundle docs

* update bundle/ssl docs
  • Loading branch information
DanielLiu1123 authored Dec 22, 2024
1 parent c3f54ea commit 71b936c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.boot.autoconfigure.web.client.RestClientBuilderConfigurer;
import org.springframework.boot.autoconfigure.web.client.RestTemplateBuilderConfigurer;
import org.springframework.boot.ssl.SslBundle;
import org.springframework.boot.ssl.SslBundles;
import org.springframework.boot.web.client.ClientHttpRequestFactories;
import org.springframework.boot.web.client.ClientHttpRequestFactorySettings;
import org.springframework.boot.web.client.RestTemplateBuilder;
Expand Down Expand Up @@ -286,6 +287,9 @@ private WebClient buildWebClient(HttpExchangeProperties.Channel channelConfig) {
header.getKey(), header.getValues().toArray(String[]::new)));
}

// ClientHttpConnectorFactory is not public, we can't create http client with custom Bundle here,
// so http-exchange.channels[].ssl.bundle is not supported for WebClient

var readTimeout = getReadTimeout(channelConfig);
if (readTimeout != null) {
builder.filter((request, next) -> next.exchange(request).timeout(readTimeout));
Expand Down Expand Up @@ -435,6 +439,15 @@ private org.springframework.boot.http.client.ClientHttpRequestFactorySettings ge
if (channelConfig.getReadTimeout() != null) {
settings = settings.withReadTimeout(Duration.ofMillis(channelConfig.getReadTimeout()));
}
if (channelConfig.getSsl() != null) {
var sslBundles = beanFactory.getBeanProvider(SslBundles.class).getIfUnique();
if (sslBundles != null) {
var bundle = sslBundles.getBundle(channelConfig.getSsl().getBundle());
if (bundle != null) {
settings = settings.withSslBundle(bundle);
}
}
}
return settings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.http.client.HttpClientProperties;
import org.springframework.boot.autoconfigure.ssl.SslProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
import org.springframework.boot.context.properties.PropertyMapper;
Expand Down Expand Up @@ -227,6 +228,7 @@ HttpExchangeProperties.Channel defaultClient() {
readTimeout,
loadbalancerEnabled,
httpClientReuseEnabled,
null,
List.of(),
List.of());
}
Expand Down Expand Up @@ -288,6 +290,13 @@ public static class Channel {
* @since 3.2.2
*/
private Boolean httpClientReuseEnabled;
/**
* SSL configuration, use {@code spring.http.client.ssl} if not set.
*
* @since 3.4.1
* @see HttpClientProperties#getSsl()
*/
private Ssl ssl;
/**
* Exchange Clients to apply this channel.
*
Expand Down Expand Up @@ -327,6 +336,23 @@ public static class Refresh {
private boolean enabled = false;
}

/**
* @see HttpClientProperties.Ssl
*/
@Data
public static class Ssl {
/**
* SSL bundle to use, use {@code spring.http.client.ssl.bundle} if not set.
*
* <p> Bundle name is configured under {@code spring.ssl} properties.
*
* <p> See configuration properties under {@code spring.ssl}.
*
* @see SslProperties#getBundle()
*/
private String bundle;
}

public enum ClientType {
/**
* @see RestClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
spring:
http:
client:
read-timeout: 10s
connect-timeout: 1s
ssl:
bundle: bundle1
http-exchange:
base-packages: [com.example.api]
base-url: http://api-gateway
bean-to-query-enabled: false
request-mapping-support-enabled: false
connect-timeout: 1000
read-timeout: 10000
headers:
- key: X-App-Name
values: ${spring.application.name}
Expand All @@ -15,6 +20,8 @@ http-exchange:
loadbalancer-enabled: true
channels:
- base-url: http://order
ssl:
bundle: bundle2
headers:
- key: X-Key
values: [value1, value2]
Expand Down

0 comments on commit 71b936c

Please sign in to comment.