|
|
@ -20,7 +20,6 @@ import java.util.AbstractCollection;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
|
|
|
import java.util.EventListener;
|
|
|
|
import java.util.EventListener;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Iterator;
|
|
|
@ -94,7 +93,7 @@ public class ServletContextInitializerBeans
|
|
|
|
.sorted(AnnotationAwareOrderComparator.INSTANCE))
|
|
|
|
.sorted(AnnotationAwareOrderComparator.INSTANCE))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
this.sortedList = Collections.unmodifiableList(sortedInitializers);
|
|
|
|
this.sortedList = Collections.unmodifiableList(sortedInitializers);
|
|
|
|
logBeansInformation(this.initializers);
|
|
|
|
logMappings(this.initializers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void addServletContextInitializerBeans(ListableBeanFactory beanFactory) {
|
|
|
|
private void addServletContextInitializerBeans(ListableBeanFactory beanFactory) {
|
|
|
@ -145,12 +144,12 @@ public class ServletContextInitializerBeans
|
|
|
|
// Mark the underlying source as seen in case it wraps an existing bean
|
|
|
|
// Mark the underlying source as seen in case it wraps an existing bean
|
|
|
|
this.seen.add(source);
|
|
|
|
this.seen.add(source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ServletContextInitializerBeans.logger.isTraceEnabled()) {
|
|
|
|
if (logger.isTraceEnabled()) {
|
|
|
|
String resourceDescription = getResourceDescription(beanName, beanFactory);
|
|
|
|
String resourceDescription = getResourceDescription(beanName, beanFactory);
|
|
|
|
int order = getOrder(initializer);
|
|
|
|
int order = getOrder(initializer);
|
|
|
|
ServletContextInitializerBeans.logger.trace("Added existing "
|
|
|
|
logger.trace("Added existing " + type.getSimpleName() + " initializer bean '"
|
|
|
|
+ type.getSimpleName() + " initializer bean '" + beanName
|
|
|
|
+ beanName + "'; order=" + order + ", resource="
|
|
|
|
+ "'; order=" + order + ", resource=" + resourceDescription);
|
|
|
|
+ resourceDescription);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -191,19 +190,20 @@ public class ServletContextInitializerBeans
|
|
|
|
|
|
|
|
|
|
|
|
private <T, B extends T> void addAsRegistrationBean(ListableBeanFactory beanFactory,
|
|
|
|
private <T, B extends T> void addAsRegistrationBean(ListableBeanFactory beanFactory,
|
|
|
|
Class<T> type, Class<B> beanType, RegistrationBeanAdapter<T> adapter) {
|
|
|
|
Class<T> type, Class<B> beanType, RegistrationBeanAdapter<T> adapter) {
|
|
|
|
List<Map.Entry<String, B>> beans = getOrderedBeansOfType(beanFactory, beanType,
|
|
|
|
List<Map.Entry<String, B>> entries = getOrderedBeansOfType(beanFactory, beanType,
|
|
|
|
this.seen);
|
|
|
|
this.seen);
|
|
|
|
for (Entry<String, B> bean : beans) {
|
|
|
|
for (Entry<String, B> entry : entries) {
|
|
|
|
if (this.seen.add(bean.getValue())) {
|
|
|
|
String beanName = entry.getKey();
|
|
|
|
int order = getOrder(bean.getValue());
|
|
|
|
B bean = entry.getValue();
|
|
|
|
String beanName = bean.getKey();
|
|
|
|
if (this.seen.add(bean)) {
|
|
|
|
// One that we haven't already seen
|
|
|
|
// One that we haven't already seen
|
|
|
|
RegistrationBean registration = adapter.createRegistrationBean(beanName,
|
|
|
|
RegistrationBean registration = adapter.createRegistrationBean(beanName,
|
|
|
|
bean.getValue(), beans.size());
|
|
|
|
bean, entries.size());
|
|
|
|
|
|
|
|
int order = getOrder(bean);
|
|
|
|
registration.setOrder(order);
|
|
|
|
registration.setOrder(order);
|
|
|
|
this.initializers.add(type, registration);
|
|
|
|
this.initializers.add(type, registration);
|
|
|
|
if (ServletContextInitializerBeans.logger.isTraceEnabled()) {
|
|
|
|
if (logger.isTraceEnabled()) {
|
|
|
|
ServletContextInitializerBeans.logger.trace(
|
|
|
|
logger.trace(
|
|
|
|
"Created " + type.getSimpleName() + " initializer for bean '"
|
|
|
|
"Created " + type.getSimpleName() + " initializer for bean '"
|
|
|
|
+ beanName + "'; order=" + order + ", resource="
|
|
|
|
+ beanName + "'; order=" + order + ", resource="
|
|
|
|
+ getResourceDescription(beanName, beanFactory));
|
|
|
|
+ getResourceDescription(beanName, beanFactory));
|
|
|
@ -228,9 +228,6 @@ public class ServletContextInitializerBeans
|
|
|
|
|
|
|
|
|
|
|
|
private <T> List<Entry<String, T>> getOrderedBeansOfType(
|
|
|
|
private <T> List<Entry<String, T>> getOrderedBeansOfType(
|
|
|
|
ListableBeanFactory beanFactory, Class<T> type, Set<?> excludes) {
|
|
|
|
ListableBeanFactory beanFactory, Class<T> type, Set<?> excludes) {
|
|
|
|
Comparator<Entry<String, T>> comparator = (o1,
|
|
|
|
|
|
|
|
o2) -> AnnotationAwareOrderComparator.INSTANCE.compare(o1.getValue(),
|
|
|
|
|
|
|
|
o2.getValue());
|
|
|
|
|
|
|
|
String[] names = beanFactory.getBeanNamesForType(type, true, false);
|
|
|
|
String[] names = beanFactory.getBeanNamesForType(type, true, false);
|
|
|
|
Map<String, T> map = new LinkedHashMap<>();
|
|
|
|
Map<String, T> map = new LinkedHashMap<>();
|
|
|
|
for (String name : names) {
|
|
|
|
for (String name : names) {
|
|
|
@ -243,40 +240,33 @@ public class ServletContextInitializerBeans
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Entry<String, T>> beans = new ArrayList<>();
|
|
|
|
List<Entry<String, T>> beans = new ArrayList<>();
|
|
|
|
beans.addAll(map.entrySet());
|
|
|
|
beans.addAll(map.entrySet());
|
|
|
|
beans.sort(comparator);
|
|
|
|
beans.sort((o1, o2) -> AnnotationAwareOrderComparator.INSTANCE
|
|
|
|
|
|
|
|
.compare(o1.getValue(), o2.getValue()));
|
|
|
|
return beans;
|
|
|
|
return beans;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void logBeansInformation(
|
|
|
|
private void logMappings(
|
|
|
|
MultiValueMap<Class<?>, ServletContextInitializer> initializers) {
|
|
|
|
MultiValueMap<Class<?>, ServletContextInitializer> initializers) {
|
|
|
|
if (ServletContextInitializerBeans.logger.isDebugEnabled()) {
|
|
|
|
if (logger.isDebugEnabled()) {
|
|
|
|
List<ServletContextInitializer> filterRegistrations = new ArrayList<>();
|
|
|
|
logMappings("filters", initializers, Filter.class,
|
|
|
|
filterRegistrations.addAll(initializers
|
|
|
|
FilterRegistrationBean.class);
|
|
|
|
.getOrDefault(FilterRegistrationBean.class, Collections.emptyList()));
|
|
|
|
logMappings("servlets", initializers, Servlet.class,
|
|
|
|
filterRegistrations.addAll(
|
|
|
|
ServletRegistrationBean.class);
|
|
|
|
initializers.getOrDefault(Filter.class, Collections.emptyList()));
|
|
|
|
|
|
|
|
String filtersInfo = filterRegistrations.stream()
|
|
|
|
|
|
|
|
.map(AbstractFilterRegistrationBean.class::cast)
|
|
|
|
|
|
|
|
.map(AbstractFilterRegistrationBean::toString)
|
|
|
|
|
|
|
|
.collect(Collectors.joining(", "));
|
|
|
|
|
|
|
|
ServletContextInitializerBeans.logger
|
|
|
|
|
|
|
|
.debug("Mapping filters: " + filtersInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ServletContextInitializer> servletRegistrations = new ArrayList<>();
|
|
|
|
|
|
|
|
servletRegistrations.addAll(initializers.getOrDefault(
|
|
|
|
|
|
|
|
ServletRegistrationBean.class, Collections.emptyList()));
|
|
|
|
|
|
|
|
servletRegistrations.addAll(
|
|
|
|
|
|
|
|
initializers.getOrDefault(Servlet.class, Collections.emptyList()));
|
|
|
|
|
|
|
|
String servletsInfo = servletRegistrations.stream()
|
|
|
|
|
|
|
|
.map(ServletRegistrationBean.class::cast)
|
|
|
|
|
|
|
|
.map((servlet) -> servlet.getServletName() + " "
|
|
|
|
|
|
|
|
+ servlet.getUrlMappings())
|
|
|
|
|
|
|
|
.collect(Collectors.joining(", "));
|
|
|
|
|
|
|
|
ServletContextInitializerBeans.logger
|
|
|
|
|
|
|
|
.debug("Mapping servlets: " + servletsInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void logMappings(String name,
|
|
|
|
|
|
|
|
MultiValueMap<Class<?>, ServletContextInitializer> initializers,
|
|
|
|
|
|
|
|
Class<?> type, Class<? extends RegistrationBean> registrationType) {
|
|
|
|
|
|
|
|
List<ServletContextInitializer> registrations = new ArrayList<>();
|
|
|
|
|
|
|
|
registrations.addAll(
|
|
|
|
|
|
|
|
initializers.getOrDefault(registrationType, Collections.emptyList()));
|
|
|
|
|
|
|
|
registrations.addAll(initializers.getOrDefault(type, Collections.emptyList()));
|
|
|
|
|
|
|
|
String info = registrations.stream().map(Object::toString)
|
|
|
|
|
|
|
|
.collect(Collectors.joining(", "));
|
|
|
|
|
|
|
|
logger.debug("Mapping " + name + ": " + info);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Iterator<ServletContextInitializer> iterator() {
|
|
|
|
public Iterator<ServletContextInitializer> iterator() {
|
|
|
|
return this.sortedList.iterator();
|
|
|
|
return this.sortedList.iterator();
|
|
|
|