Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add http-exchange.channels[].ssl.bundle configuration #76

Merged
merged 8 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading