Skip to content

Commit

Permalink
chore: Fix PostProcessorRegistrationDelegate warning caused by routin…
Browse files Browse the repository at this point in the history
…gFilterHandler (#3769)
  • Loading branch information
pj892031 authored Sep 17, 2024
1 parent 5c7d16c commit 9fe9b0b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions api-catalog-services/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ logging:

# New Config
org.apache: WARN #org.apache.catalina, org.apache.coyote, org.apache.tomcat
org.apache.tomcat.util.net.SSLUtilBase: ERROR
org.eclipse.jetty: WARN
org.apache.http.conn.ssl.DefaultHostnameVerifier: DEBUG #logs only SSLException
javax.net.ssl: ERROR
Expand Down
1 change: 1 addition & 0 deletions discovery-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ logging:
org.eclipse.jetty: WARN
org.apache.http.conn.ssl.DefaultHostnameVerifier: DEBUG #logs only SSLException
javax.net.ssl: ERROR
org.apache.tomcat.util.net.SSLUtilBase: ERROR
# com.netflix.eureka.resources: WARN

apiml:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,13 @@ public HttpsFactory factory() {
}

/**
* This bean processor is used to override bean routingFilter defined at
* org.springframework.cloud.gateway.config.GatewayAutoConfiguration.NettyConfiguration#routingFilter(HttpClient, ObjectProvider, HttpClientProperties)
* <p>
* There is no simple way how to override this specific bean, but bean processing could handle that.
*
* @param httpClient default http client
* @param headersFiltersProvider header filter for spring gateway router
* @param properties client HTTP properties
* @return bean processor to replace NettyRoutingFilter by NettyRoutingFilterApiml
* @return instance of NettyRoutingFilterApiml
*/
@Bean
public BeanPostProcessor routingFilterHandler(HttpClient httpClient, ObjectProvider<List<HttpHeadersFilter>> headersFiltersProvider, HttpClientProperties properties) {
public NettyRoutingFilterApiml createNettyRoutingFilterApiml(HttpClient httpClient, ObjectProvider<List<HttpHeadersFilter>> headersFiltersProvider, HttpClientProperties properties) {
// obtain SSL contexts (one with keystore to support client cert sign and truststore, second just with truststore)
SslContext justTruststore = sslContext(false);
SslContext withKeystore = sslContext(true);
Expand All @@ -199,13 +194,27 @@ public BeanPostProcessor routingFilterHandler(HttpClient httpClient, ObjectProvi
// construct http clients with different SSL configuration - with / without client certs
var httpClientNoCert = httpClient.secure(builderJustTruststore.build());
var httpClientClientCert = httpClient.secure(builderWithKeystore.build());

return new NettyRoutingFilterApiml(httpClientNoCert, httpClientClientCert, headersFiltersProvider, properties);
}

/**
* This bean processor is used to override bean routingFilter defined at
* org.springframework.cloud.gateway.config.GatewayAutoConfiguration.NettyConfiguration#routingFilter(HttpClient, ObjectProvider, HttpClientProperties)
* <p>
* There is no simple way how to override this specific bean, but bean processing could handle that.
*
* @return bean processor to replace NettyRoutingFilter by NettyRoutingFilterApiml
*/
@Bean
public static BeanPostProcessor routingFilterHandler(ApplicationContext context) {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if ("routingFilter".equals(beanName)) {
log.debug("Updating routing bean {}", NettyRoutingFilterApiml.class);
// once is creating original bean by autoconfiguration replace it with custom implementation
return new NettyRoutingFilterApiml(httpClientNoCert, httpClientClientCert, headersFiltersProvider, properties);
return context.getBean(NettyRoutingFilterApiml.class);
}
// do not touch any other bean
return bean;
Expand Down
4 changes: 4 additions & 0 deletions mock-services/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
logging:
level:
ROOT: INFO
org.apache.tomcat.util.net.SSLUtilBase: ERROR
spring:
application:
name: Mock services
Expand Down

0 comments on commit 9fe9b0b

Please sign in to comment.