|
21 | 21 | import java.util.Collections;
|
22 | 22 | import java.util.List;
|
23 | 23 |
|
24 |
| -import org.apache.commons.logging.Log; |
25 |
| -import org.apache.commons.logging.LogFactory; |
26 |
| - |
27 | 24 | import org.springframework.beans.BeansException;
|
28 | 25 | import org.springframework.beans.factory.BeanFactory;
|
29 | 26 | import org.springframework.beans.factory.BeanFactoryAware;
|
30 | 27 | import org.springframework.beans.factory.ListableBeanFactory;
|
31 | 28 | import org.springframework.beans.factory.config.BeanPostProcessor;
|
32 |
| -import org.springframework.core.ResolvableType; |
| 29 | +import org.springframework.boot.util.LambdaSafe; |
33 | 30 | import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
34 | 31 | import org.springframework.util.Assert;
|
35 | 32 |
|
|
45 | 42 | public class WebServerFactoryCustomizerBeanPostProcessor
|
46 | 43 | implements BeanPostProcessor, BeanFactoryAware {
|
47 | 44 |
|
48 |
| - private static final Log logger = LogFactory |
49 |
| - .getLog(WebServerFactoryCustomizerBeanPostProcessor.class); |
50 |
| - |
51 | 45 | private ListableBeanFactory beanFactory;
|
52 | 46 |
|
53 | 47 | private List<WebServerFactoryCustomizer<?>> customizers;
|
@@ -75,45 +69,13 @@ public Object postProcessAfterInitialization(Object bean, String beanName)
|
75 | 69 | return bean;
|
76 | 70 | }
|
77 | 71 |
|
78 |
| - private void postProcessBeforeInitialization(WebServerFactory bean) { |
79 |
| - for (WebServerFactoryCustomizer<?> customizer : getCustomizers()) { |
80 |
| - Class<?> type = ResolvableType |
81 |
| - .forClass(WebServerFactoryCustomizer.class, customizer.getClass()) |
82 |
| - .getGeneric().resolve(WebServerFactory.class); |
83 |
| - if (type.isInstance(bean)) { |
84 |
| - invokeCustomizer(customizer, bean); |
85 |
| - } |
86 |
| - } |
87 |
| - } |
88 |
| - |
89 |
| - @SuppressWarnings({ "rawtypes", "unchecked" }) |
90 |
| - private void invokeCustomizer(WebServerFactoryCustomizer customizer, |
91 |
| - WebServerFactory webServerFactory) { |
92 |
| - try { |
93 |
| - customizer.customize(webServerFactory); |
94 |
| - } |
95 |
| - catch (ClassCastException ex) { |
96 |
| - String msg = ex.getMessage(); |
97 |
| - if (msg == null || msg.startsWith(webServerFactory.getClass().getName())) { |
98 |
| - // Possibly a lambda-defined WebServerFactoryCustomizer which we could not |
99 |
| - // resolve the |
100 |
| - // generic WebServerFactory type for |
101 |
| - logLambdaDebug(customizer, ex); |
102 |
| - } |
103 |
| - else { |
104 |
| - throw ex; |
105 |
| - } |
106 |
| - } |
107 |
| - } |
108 |
| - |
109 |
| - private void logLambdaDebug(WebServerFactoryCustomizer<?> customizer, |
110 |
| - ClassCastException ex) { |
111 |
| - if (logger.isDebugEnabled()) { |
112 |
| - logger.debug( |
113 |
| - "Non-matching WebServerFactory type for WebServerFactoryCustomizer: " |
114 |
| - + customizer, |
115 |
| - ex); |
116 |
| - } |
| 72 | + @SuppressWarnings("unchecked") |
| 73 | + private void postProcessBeforeInitialization(WebServerFactory webServerFactory) { |
| 74 | + LambdaSafe |
| 75 | + .callbacks(WebServerFactoryCustomizer.class, getCustomizers(), |
| 76 | + webServerFactory) |
| 77 | + .withLogger(WebServerFactoryCustomizerBeanPostProcessor.class) |
| 78 | + .invoke((customizer) -> customizer.customize(webServerFactory)); |
117 | 79 | }
|
118 | 80 |
|
119 | 81 | private Collection<WebServerFactoryCustomizer<?>> getCustomizers() {
|
|
0 commit comments