Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
dd4377e6
Commit
dd4377e6
authored
Nov 07, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
Closes gh-18912
parents
93b7baf1
d1ead884
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
113 additions
and
54 deletions
+113
-54
ServletComponentHandler.java
...ngframework/boot/web/servlet/ServletComponentHandler.java
+3
-3
ServletComponentRegisteringPostProcessor.java
...web/servlet/ServletComponentRegisteringPostProcessor.java
+3
-3
WebFilterHandler.java
...rg/springframework/boot/web/servlet/WebFilterHandler.java
+2
-2
WebListenerHandler.java
.../springframework/boot/web/servlet/WebListenerHandler.java
+2
-2
WebServletHandler.java
...g/springframework/boot/web/servlet/WebServletHandler.java
+3
-3
ServletComponentScanIntegrationTests.java
...oot/web/servlet/ServletComponentScanIntegrationTests.java
+40
-0
WebFilterHandlerTests.java
...ringframework/boot/web/servlet/WebFilterHandlerTests.java
+26
-19
WebListenerHandlerTests.java
...ngframework/boot/web/servlet/WebListenerHandlerTests.java
+9
-4
WebServletHandlerTests.java
...ingframework/boot/web/servlet/WebServletHandlerTests.java
+24
-17
checkstyle.xml
src/checkstyle/checkstyle.xml
+1
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentHandler.java
View file @
dd4377e6
...
@@ -20,8 +20,8 @@ import java.lang.annotation.Annotation;
...
@@ -20,8 +20,8 @@ import java.lang.annotation.Annotation;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.context.annotation.ScannedGenericBeanDefinition
;
import
org.springframework.core.annotation.AnnotationAttributes
;
import
org.springframework.core.annotation.AnnotationAttributes
;
import
org.springframework.core.type.filter.AnnotationTypeFilter
;
import
org.springframework.core.type.filter.AnnotationTypeFilter
;
import
org.springframework.core.type.filter.TypeFilter
;
import
org.springframework.core.type.filter.TypeFilter
;
...
@@ -68,7 +68,7 @@ abstract class ServletComponentHandler {
...
@@ -68,7 +68,7 @@ abstract class ServletComponentHandler {
return
initParameters
;
return
initParameters
;
}
}
void
handle
(
ScannedGeneric
BeanDefinition
beanDefinition
,
BeanDefinitionRegistry
registry
)
{
void
handle
(
Annotated
BeanDefinition
beanDefinition
,
BeanDefinitionRegistry
registry
)
{
Map
<
String
,
Object
>
attributes
=
beanDefinition
.
getMetadata
()
Map
<
String
,
Object
>
attributes
=
beanDefinition
.
getMetadata
()
.
getAnnotationAttributes
(
this
.
annotationType
.
getName
());
.
getAnnotationAttributes
(
this
.
annotationType
.
getName
());
if
(
attributes
!=
null
)
{
if
(
attributes
!=
null
)
{
...
@@ -76,7 +76,7 @@ abstract class ServletComponentHandler {
...
@@ -76,7 +76,7 @@ abstract class ServletComponentHandler {
}
}
}
}
protected
abstract
void
doHandle
(
Map
<
String
,
Object
>
attributes
,
ScannedGeneric
BeanDefinition
beanDefinition
,
protected
abstract
void
doHandle
(
Map
<
String
,
Object
>
attributes
,
Annotated
BeanDefinition
beanDefinition
,
BeanDefinitionRegistry
registry
);
BeanDefinitionRegistry
registry
);
}
}
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentRegisteringPostProcessor.java
View file @
dd4377e6
...
@@ -22,6 +22,7 @@ import java.util.List;
...
@@ -22,6 +22,7 @@ import java.util.List;
import
java.util.Set
;
import
java.util.Set
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanFactoryPostProcessor
;
import
org.springframework.beans.factory.config.BeanFactoryPostProcessor
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
...
@@ -29,7 +30,6 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
...
@@ -29,7 +30,6 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
;
import
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
;
import
org.springframework.context.annotation.ScannedGenericBeanDefinition
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.WebApplicationContext
;
/**
/**
...
@@ -72,9 +72,9 @@ class ServletComponentRegisteringPostProcessor implements BeanFactoryPostProcess
...
@@ -72,9 +72,9 @@ class ServletComponentRegisteringPostProcessor implements BeanFactoryPostProcess
private
void
scanPackage
(
ClassPathScanningCandidateComponentProvider
componentProvider
,
String
packageToScan
)
{
private
void
scanPackage
(
ClassPathScanningCandidateComponentProvider
componentProvider
,
String
packageToScan
)
{
for
(
BeanDefinition
candidate
:
componentProvider
.
findCandidateComponents
(
packageToScan
))
{
for
(
BeanDefinition
candidate
:
componentProvider
.
findCandidateComponents
(
packageToScan
))
{
if
(
candidate
instanceof
ScannedGeneric
BeanDefinition
)
{
if
(
candidate
instanceof
Annotated
BeanDefinition
)
{
for
(
ServletComponentHandler
handler
:
HANDLERS
)
{
for
(
ServletComponentHandler
handler
:
HANDLERS
)
{
handler
.
handle
(((
ScannedGeneric
BeanDefinition
)
candidate
),
handler
.
handle
(((
Annotated
BeanDefinition
)
candidate
),
(
BeanDefinitionRegistry
)
this
.
applicationContext
);
(
BeanDefinitionRegistry
)
this
.
applicationContext
);
}
}
}
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/WebFilterHandler.java
View file @
dd4377e6
...
@@ -23,10 +23,10 @@ import java.util.Map;
...
@@ -23,10 +23,10 @@ import java.util.Map;
import
javax.servlet.DispatcherType
;
import
javax.servlet.DispatcherType
;
import
javax.servlet.annotation.WebFilter
;
import
javax.servlet.annotation.WebFilter
;
import
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.support.BeanDefinitionBuilder
;
import
org.springframework.beans.factory.support.BeanDefinitionBuilder
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.context.annotation.ScannedGenericBeanDefinition
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
/**
/**
...
@@ -41,7 +41,7 @@ class WebFilterHandler extends ServletComponentHandler {
...
@@ -41,7 +41,7 @@ class WebFilterHandler extends ServletComponentHandler {
}
}
@Override
@Override
public
void
doHandle
(
Map
<
String
,
Object
>
attributes
,
ScannedGeneric
BeanDefinition
beanDefinition
,
public
void
doHandle
(
Map
<
String
,
Object
>
attributes
,
Annotated
BeanDefinition
beanDefinition
,
BeanDefinitionRegistry
registry
)
{
BeanDefinitionRegistry
registry
)
{
BeanDefinitionBuilder
builder
=
BeanDefinitionBuilder
.
rootBeanDefinition
(
FilterRegistrationBean
.
class
);
BeanDefinitionBuilder
builder
=
BeanDefinitionBuilder
.
rootBeanDefinition
(
FilterRegistrationBean
.
class
);
builder
.
addPropertyValue
(
"asyncSupported"
,
attributes
.
get
(
"asyncSupported"
));
builder
.
addPropertyValue
(
"asyncSupported"
,
attributes
.
get
(
"asyncSupported"
));
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/WebListenerHandler.java
View file @
dd4377e6
...
@@ -20,9 +20,9 @@ import java.util.Map;
...
@@ -20,9 +20,9 @@ import java.util.Map;
import
javax.servlet.annotation.WebListener
;
import
javax.servlet.annotation.WebListener
;
import
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
;
import
org.springframework.beans.factory.support.BeanDefinitionBuilder
;
import
org.springframework.beans.factory.support.BeanDefinitionBuilder
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.context.annotation.ScannedGenericBeanDefinition
;
/**
/**
* Handler for {@link WebListener @WebListener}-annotated classes.
* Handler for {@link WebListener @WebListener}-annotated classes.
...
@@ -36,7 +36,7 @@ class WebListenerHandler extends ServletComponentHandler {
...
@@ -36,7 +36,7 @@ class WebListenerHandler extends ServletComponentHandler {
}
}
@Override
@Override
protected
void
doHandle
(
Map
<
String
,
Object
>
attributes
,
ScannedGeneric
BeanDefinition
beanDefinition
,
protected
void
doHandle
(
Map
<
String
,
Object
>
attributes
,
Annotated
BeanDefinition
beanDefinition
,
BeanDefinitionRegistry
registry
)
{
BeanDefinitionRegistry
registry
)
{
BeanDefinitionBuilder
builder
=
BeanDefinitionBuilder
.
rootBeanDefinition
(
ServletListenerRegistrationBean
.
class
);
BeanDefinitionBuilder
builder
=
BeanDefinitionBuilder
.
rootBeanDefinition
(
ServletListenerRegistrationBean
.
class
);
builder
.
addPropertyValue
(
"listener"
,
beanDefinition
);
builder
.
addPropertyValue
(
"listener"
,
beanDefinition
);
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/WebServletHandler.java
View file @
dd4377e6
...
@@ -22,10 +22,10 @@ import javax.servlet.MultipartConfigElement;
...
@@ -22,10 +22,10 @@ import javax.servlet.MultipartConfigElement;
import
javax.servlet.annotation.MultipartConfig
;
import
javax.servlet.annotation.MultipartConfig
;
import
javax.servlet.annotation.WebServlet
;
import
javax.servlet.annotation.WebServlet
;
import
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.support.BeanDefinitionBuilder
;
import
org.springframework.beans.factory.support.BeanDefinitionBuilder
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.context.annotation.ScannedGenericBeanDefinition
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
/**
/**
...
@@ -40,7 +40,7 @@ class WebServletHandler extends ServletComponentHandler {
...
@@ -40,7 +40,7 @@ class WebServletHandler extends ServletComponentHandler {
}
}
@Override
@Override
public
void
doHandle
(
Map
<
String
,
Object
>
attributes
,
ScannedGeneric
BeanDefinition
beanDefinition
,
public
void
doHandle
(
Map
<
String
,
Object
>
attributes
,
Annotated
BeanDefinition
beanDefinition
,
BeanDefinitionRegistry
registry
)
{
BeanDefinitionRegistry
registry
)
{
BeanDefinitionBuilder
builder
=
BeanDefinitionBuilder
.
rootBeanDefinition
(
ServletRegistrationBean
.
class
);
BeanDefinitionBuilder
builder
=
BeanDefinitionBuilder
.
rootBeanDefinition
(
ServletRegistrationBean
.
class
);
builder
.
addPropertyValue
(
"asyncSupported"
,
attributes
.
get
(
"asyncSupported"
));
builder
.
addPropertyValue
(
"asyncSupported"
,
attributes
.
get
(
"asyncSupported"
));
...
@@ -59,7 +59,7 @@ class WebServletHandler extends ServletComponentHandler {
...
@@ -59,7 +59,7 @@ class WebServletHandler extends ServletComponentHandler {
:
beanDefinition
.
getBeanClassName
());
:
beanDefinition
.
getBeanClassName
());
}
}
private
MultipartConfigElement
determineMultipartConfig
(
ScannedGeneric
BeanDefinition
beanDefinition
)
{
private
MultipartConfigElement
determineMultipartConfig
(
Annotated
BeanDefinition
beanDefinition
)
{
Map
<
String
,
Object
>
attributes
=
beanDefinition
.
getMetadata
()
Map
<
String
,
Object
>
attributes
=
beanDefinition
.
getMetadata
()
.
getAnnotationAttributes
(
MultipartConfig
.
class
.
getName
());
.
getAnnotationAttributes
(
MultipartConfig
.
class
.
getName
());
if
(
attributes
==
null
)
{
if
(
attributes
==
null
)
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletComponentScanIntegrationTests.java
View file @
dd4377e6
...
@@ -16,12 +16,22 @@
...
@@ -16,12 +16,22 @@
package
org
.
springframework
.
boot
.
web
.
servlet
;
package
org
.
springframework
.
boot
.
web
.
servlet
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Properties
;
import
javax.servlet.MultipartConfigElement
;
import
javax.servlet.MultipartConfigElement
;
import
javax.servlet.annotation.WebFilter
;
import
javax.servlet.annotation.WebListener
;
import
javax.servlet.annotation.WebServlet
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
;
import
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
;
import
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
;
import
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
;
...
@@ -60,6 +70,22 @@ class ServletComponentScanIntegrationTests {
...
@@ -60,6 +70,22 @@ class ServletComponentScanIntegrationTests {
assertThat
(
response
).
isEqualTo
(
"alpha bravo"
);
assertThat
(
response
).
isEqualTo
(
"alpha bravo"
);
}
}
@Test
void
indexedComponentsAreRegistered
(
@TempDir
File
temp
)
throws
IOException
{
writeIndex
(
temp
);
this
.
context
=
new
AnnotationConfigServletWebServerApplicationContext
();
try
(
URLClassLoader
classLoader
=
new
URLClassLoader
(
new
URL
[]
{
temp
.
toURI
().
toURL
()
},
getClass
().
getClassLoader
()))
{
this
.
context
.
setClassLoader
(
classLoader
);
this
.
context
.
register
(
TestConfiguration
.
class
);
new
ServerPortInfoApplicationContextInitializer
().
initialize
(
this
.
context
);
this
.
context
.
refresh
();
String
port
=
this
.
context
.
getEnvironment
().
getProperty
(
"local.server.port"
);
String
response
=
new
RestTemplate
().
getForObject
(
"http://localhost:"
+
port
+
"/test"
,
String
.
class
);
assertThat
(
response
).
isEqualTo
(
"alpha bravo"
);
}
}
@Test
@Test
void
multipartConfigIsHonoured
()
{
void
multipartConfigIsHonoured
()
{
this
.
context
=
new
AnnotationConfigServletWebServerApplicationContext
();
this
.
context
=
new
AnnotationConfigServletWebServerApplicationContext
();
...
@@ -78,6 +104,20 @@ class ServletComponentScanIntegrationTests {
...
@@ -78,6 +104,20 @@ class ServletComponentScanIntegrationTests {
assertThat
(
multipartConfig
.
getFileSizeThreshold
()).
isEqualTo
(
512
);
assertThat
(
multipartConfig
.
getFileSizeThreshold
()).
isEqualTo
(
512
);
}
}
private
void
writeIndex
(
File
temp
)
throws
IOException
{
File
metaInf
=
new
File
(
temp
,
"META-INF"
);
metaInf
.
mkdirs
();
Properties
index
=
new
Properties
();
index
.
setProperty
(
"org.springframework.boot.web.servlet.testcomponents.TestFilter"
,
WebFilter
.
class
.
getName
());
index
.
setProperty
(
"org.springframework.boot.web.servlet.testcomponents.TestListener"
,
WebListener
.
class
.
getName
());
index
.
setProperty
(
"org.springframework.boot.web.servlet.testcomponents.TestServlet"
,
WebServlet
.
class
.
getName
());
try
(
FileWriter
writer
=
new
FileWriter
(
new
File
(
metaInf
,
"spring.components"
)))
{
index
.
store
(
writer
,
null
);
}
}
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
@ServletComponentScan
(
basePackages
=
"org.springframework.boot.web.servlet.testcomponents"
)
@ServletComponentScan
(
basePackages
=
"org.springframework.boot.web.servlet.testcomponents"
)
static
class
TestConfiguration
{
static
class
TestConfiguration
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/WebFilterHandlerTests.java
View file @
dd4377e6
...
@@ -33,13 +33,15 @@ import javax.servlet.annotation.WebInitParam;
...
@@ -33,13 +33,15 @@ import javax.servlet.annotation.WebInitParam;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry
;
import
org.springframework.context.annotation.ScannedGenericBeanDefinition
;
import
org.springframework.core.type.classreading.SimpleMetadataReaderFactory
;
import
org.springframework.core.type.classreading.SimpleMetadataReaderFactory
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalStateException
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalStateException
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
/**
* Tests for {@link WebFilterHandler}
* Tests for {@link WebFilterHandler}
...
@@ -55,9 +57,8 @@ class WebFilterHandlerTests {
...
@@ -55,9 +57,8 @@ class WebFilterHandlerTests {
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@Test
@Test
void
defaultFilterConfiguration
()
throws
IOException
{
void
defaultFilterConfiguration
()
throws
IOException
{
ScannedGenericBeanDefinition
scanned
=
new
ScannedGenericBeanDefinition
(
AnnotatedBeanDefinition
definition
=
createBeanDefinition
(
DefaultConfigurationFilter
.
class
);
new
SimpleMetadataReaderFactory
().
getMetadataReader
(
DefaultConfigurationFilter
.
class
.
getName
()));
this
.
handler
.
handle
(
definition
,
this
.
registry
);
this
.
handler
.
handle
(
scanned
,
this
.
registry
);
BeanDefinition
filterRegistrationBean
=
this
.
registry
BeanDefinition
filterRegistrationBean
=
this
.
registry
.
getBeanDefinition
(
DefaultConfigurationFilter
.
class
.
getName
());
.
getBeanDefinition
(
DefaultConfigurationFilter
.
class
.
getName
());
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
...
@@ -68,14 +69,13 @@ class WebFilterHandlerTests {
...
@@ -68,14 +69,13 @@ class WebFilterHandlerTests {
assertThat
((
String
[])
propertyValues
.
get
(
"servletNames"
)).
isEmpty
();
assertThat
((
String
[])
propertyValues
.
get
(
"servletNames"
)).
isEmpty
();
assertThat
((
String
[])
propertyValues
.
get
(
"urlPatterns"
)).
isEmpty
();
assertThat
((
String
[])
propertyValues
.
get
(
"urlPatterns"
)).
isEmpty
();
assertThat
(
propertyValues
.
get
(
"name"
)).
isEqualTo
(
DefaultConfigurationFilter
.
class
.
getName
());
assertThat
(
propertyValues
.
get
(
"name"
)).
isEqualTo
(
DefaultConfigurationFilter
.
class
.
getName
());
assertThat
(
propertyValues
.
get
(
"filter"
)).
isEqualTo
(
scanned
);
assertThat
(
propertyValues
.
get
(
"filter"
)).
isEqualTo
(
definition
);
}
}
@Test
@Test
void
filterWithCustomName
()
throws
IOException
{
void
filterWithCustomName
()
throws
IOException
{
ScannedGenericBeanDefinition
scanned
=
new
ScannedGenericBeanDefinition
(
AnnotatedBeanDefinition
definition
=
createBeanDefinition
(
CustomNameFilter
.
class
);
new
SimpleMetadataReaderFactory
().
getMetadataReader
(
CustomNameFilter
.
class
.
getName
()));
this
.
handler
.
handle
(
definition
,
this
.
registry
);
this
.
handler
.
handle
(
scanned
,
this
.
registry
);
BeanDefinition
filterRegistrationBean
=
this
.
registry
.
getBeanDefinition
(
"custom"
);
BeanDefinition
filterRegistrationBean
=
this
.
registry
.
getBeanDefinition
(
"custom"
);
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
assertThat
(
propertyValues
.
get
(
"name"
)).
isEqualTo
(
"custom"
);
assertThat
(
propertyValues
.
get
(
"name"
)).
isEqualTo
(
"custom"
);
...
@@ -83,7 +83,7 @@ class WebFilterHandlerTests {
...
@@ -83,7 +83,7 @@ class WebFilterHandlerTests {
@Test
@Test
void
asyncSupported
()
throws
IOException
{
void
asyncSupported
()
throws
IOException
{
BeanDefinition
filterRegistrationBean
=
getBeanDefinition
(
AsyncSupportedFilter
.
class
);
BeanDefinition
filterRegistrationBean
=
handleBeanDefinitionForClass
(
AsyncSupportedFilter
.
class
);
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
assertThat
(
propertyValues
.
get
(
"asyncSupported"
)).
isEqualTo
(
true
);
assertThat
(
propertyValues
.
get
(
"asyncSupported"
)).
isEqualTo
(
true
);
}
}
...
@@ -91,7 +91,7 @@ class WebFilterHandlerTests {
...
@@ -91,7 +91,7 @@ class WebFilterHandlerTests {
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
void
dispatcherTypes
()
throws
IOException
{
void
dispatcherTypes
()
throws
IOException
{
BeanDefinition
filterRegistrationBean
=
getBeanDefinition
(
DispatcherTypesFilter
.
class
);
BeanDefinition
filterRegistrationBean
=
handleBeanDefinitionForClass
(
DispatcherTypesFilter
.
class
);
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
assertThat
((
Set
<
DispatcherType
>)
propertyValues
.
get
(
"dispatcherTypes"
)).
containsExactly
(
DispatcherType
.
FORWARD
,
assertThat
((
Set
<
DispatcherType
>)
propertyValues
.
get
(
"dispatcherTypes"
)).
containsExactly
(
DispatcherType
.
FORWARD
,
DispatcherType
.
INCLUDE
,
DispatcherType
.
REQUEST
);
DispatcherType
.
INCLUDE
,
DispatcherType
.
REQUEST
);
...
@@ -100,7 +100,7 @@ class WebFilterHandlerTests {
...
@@ -100,7 +100,7 @@ class WebFilterHandlerTests {
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@Test
@Test
void
initParameters
()
throws
IOException
{
void
initParameters
()
throws
IOException
{
BeanDefinition
filterRegistrationBean
=
getBeanDefinition
(
InitParametersFilter
.
class
);
BeanDefinition
filterRegistrationBean
=
handleBeanDefinitionForClass
(
InitParametersFilter
.
class
);
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
assertThat
((
Map
<
String
,
String
>)
propertyValues
.
get
(
"initParameters"
)).
containsEntry
(
"a"
,
"alpha"
)
assertThat
((
Map
<
String
,
String
>)
propertyValues
.
get
(
"initParameters"
)).
containsEntry
(
"a"
,
"alpha"
)
.
containsEntry
(
"b"
,
"bravo"
);
.
containsEntry
(
"b"
,
"bravo"
);
...
@@ -108,35 +108,42 @@ class WebFilterHandlerTests {
...
@@ -108,35 +108,42 @@ class WebFilterHandlerTests {
@Test
@Test
void
servletNames
()
throws
IOException
{
void
servletNames
()
throws
IOException
{
BeanDefinition
filterRegistrationBean
=
getBeanDefinition
(
ServletNamesFilter
.
class
);
BeanDefinition
filterRegistrationBean
=
handleBeanDefinitionForClass
(
ServletNamesFilter
.
class
);
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
assertThat
((
String
[])
propertyValues
.
get
(
"servletNames"
)).
contains
(
"alpha"
,
"bravo"
);
assertThat
((
String
[])
propertyValues
.
get
(
"servletNames"
)).
contains
(
"alpha"
,
"bravo"
);
}
}
@Test
@Test
void
urlPatterns
()
throws
IOException
{
void
urlPatterns
()
throws
IOException
{
BeanDefinition
filterRegistrationBean
=
getBeanDefinition
(
UrlPatternsFilter
.
class
);
BeanDefinition
filterRegistrationBean
=
handleBeanDefinitionForClass
(
UrlPatternsFilter
.
class
);
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
assertThat
((
String
[])
propertyValues
.
get
(
"urlPatterns"
)).
contains
(
"alpha"
,
"bravo"
);
assertThat
((
String
[])
propertyValues
.
get
(
"urlPatterns"
)).
contains
(
"alpha"
,
"bravo"
);
}
}
@Test
@Test
void
urlPatternsFromValue
()
throws
IOException
{
void
urlPatternsFromValue
()
throws
IOException
{
BeanDefinition
filterRegistrationBean
=
getBeanDefinition
(
UrlPatternsFromValueFilter
.
class
);
BeanDefinition
filterRegistrationBean
=
handleBeanDefinitionForClass
(
UrlPatternsFromValueFilter
.
class
);
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
filterRegistrationBean
.
getPropertyValues
();
assertThat
((
String
[])
propertyValues
.
get
(
"urlPatterns"
)).
contains
(
"alpha"
,
"bravo"
);
assertThat
((
String
[])
propertyValues
.
get
(
"urlPatterns"
)).
contains
(
"alpha"
,
"bravo"
);
}
}
@Test
@Test
void
urlPatternsDeclaredTwice
()
throws
IOException
{
void
urlPatternsDeclaredTwice
()
throws
IOException
{
assertThatIllegalStateException
().
isThrownBy
(()
->
getBeanDefinition
(
UrlPatternsDeclaredTwiceFilter
.
class
))
assertThatIllegalStateException
()
.
isThrownBy
(()
->
handleBeanDefinitionForClass
(
UrlPatternsDeclaredTwiceFilter
.
class
))
.
withMessageContaining
(
"The urlPatterns and value attributes are mutually exclusive."
);
.
withMessageContaining
(
"The urlPatterns and value attributes are mutually exclusive."
);
}
}
BeanDefinition
getBeanDefinition
(
Class
<?>
filterClass
)
throws
IOException
{
private
AnnotatedBeanDefinition
createBeanDefinition
(
Class
<?>
filterClass
)
throws
IOException
{
ScannedGenericBeanDefinition
scanned
=
new
ScannedGenericBeanDefinition
(
AnnotatedBeanDefinition
definition
=
mock
(
AnnotatedBeanDefinition
.
class
);
new
SimpleMetadataReaderFactory
().
getMetadataReader
(
filterClass
.
getName
()));
given
(
definition
.
getBeanClassName
()).
willReturn
(
filterClass
.
getName
());
this
.
handler
.
handle
(
scanned
,
this
.
registry
);
given
(
definition
.
getMetadata
()).
willReturn
(
new
SimpleMetadataReaderFactory
().
getMetadataReader
(
filterClass
.
getName
()).
getAnnotationMetadata
());
return
definition
;
}
private
BeanDefinition
handleBeanDefinitionForClass
(
Class
<?>
filterClass
)
throws
IOException
{
this
.
handler
.
handle
(
createBeanDefinition
(
filterClass
),
this
.
registry
);
return
this
.
registry
.
getBeanDefinition
(
filterClass
.
getName
());
return
this
.
registry
.
getBeanDefinition
(
filterClass
.
getName
());
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/WebListenerHandlerTests.java
View file @
dd4377e6
...
@@ -24,10 +24,13 @@ import javax.servlet.annotation.WebListener;
...
@@ -24,10 +24,13 @@ import javax.servlet.annotation.WebListener;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
;
import
org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry
;
import
org.springframework.context.annotation.ScannedGenericBeanDefinition
;
import
org.springframework.core.type.classreading.SimpleMetadataReaderFactory
;
import
org.springframework.core.type.classreading.SimpleMetadataReaderFactory
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
/**
* Tests for {@link WebListenerHandler}.
* Tests for {@link WebListenerHandler}.
*
*
...
@@ -41,9 +44,11 @@ class WebListenerHandlerTests {
...
@@ -41,9 +44,11 @@ class WebListenerHandlerTests {
@Test
@Test
void
listener
()
throws
IOException
{
void
listener
()
throws
IOException
{
ScannedGenericBeanDefinition
scanned
=
new
ScannedGenericBeanDefinition
(
AnnotatedBeanDefinition
definition
=
mock
(
AnnotatedBeanDefinition
.
class
);
new
SimpleMetadataReaderFactory
().
getMetadataReader
(
TestListener
.
class
.
getName
()));
given
(
definition
.
getBeanClassName
()).
willReturn
(
TestListener
.
class
.
getName
());
this
.
handler
.
handle
(
scanned
,
this
.
registry
);
given
(
definition
.
getMetadata
()).
willReturn
(
new
SimpleMetadataReaderFactory
()
.
getMetadataReader
(
TestListener
.
class
.
getName
()).
getAnnotationMetadata
());
this
.
handler
.
handle
(
definition
,
this
.
registry
);
this
.
registry
.
getBeanDefinition
(
TestListener
.
class
.
getName
());
this
.
registry
.
getBeanDefinition
(
TestListener
.
class
.
getName
());
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/WebServletHandlerTests.java
View file @
dd4377e6
...
@@ -26,13 +26,15 @@ import javax.servlet.http.HttpServlet;
...
@@ -26,13 +26,15 @@ import javax.servlet.http.HttpServlet;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry
;
import
org.springframework.context.annotation.ScannedGenericBeanDefinition
;
import
org.springframework.core.type.classreading.SimpleMetadataReaderFactory
;
import
org.springframework.core.type.classreading.SimpleMetadataReaderFactory
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalStateException
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalStateException
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
/**
* Tests for {@link WebServletHandler}.
* Tests for {@link WebServletHandler}.
...
@@ -48,9 +50,8 @@ class WebServletHandlerTests {
...
@@ -48,9 +50,8 @@ class WebServletHandlerTests {
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@Test
@Test
void
defaultServletConfiguration
()
throws
IOException
{
void
defaultServletConfiguration
()
throws
IOException
{
ScannedGenericBeanDefinition
scanned
=
new
ScannedGenericBeanDefinition
(
AnnotatedBeanDefinition
servletdefinition
=
createBeanDefinition
(
DefaultConfigurationServlet
.
class
);
new
SimpleMetadataReaderFactory
().
getMetadataReader
(
DefaultConfigurationServlet
.
class
.
getName
()));
this
.
handler
.
handle
(
servletdefinition
,
this
.
registry
);
this
.
handler
.
handle
(
scanned
,
this
.
registry
);
BeanDefinition
servletRegistrationBean
=
this
.
registry
BeanDefinition
servletRegistrationBean
=
this
.
registry
.
getBeanDefinition
(
DefaultConfigurationServlet
.
class
.
getName
());
.
getBeanDefinition
(
DefaultConfigurationServlet
.
class
.
getName
());
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
...
@@ -59,14 +60,13 @@ class WebServletHandlerTests {
...
@@ -59,14 +60,13 @@ class WebServletHandlerTests {
assertThat
((
Integer
)
propertyValues
.
get
(
"loadOnStartup"
)).
isEqualTo
(-
1
);
assertThat
((
Integer
)
propertyValues
.
get
(
"loadOnStartup"
)).
isEqualTo
(-
1
);
assertThat
(
propertyValues
.
get
(
"name"
)).
isEqualTo
(
DefaultConfigurationServlet
.
class
.
getName
());
assertThat
(
propertyValues
.
get
(
"name"
)).
isEqualTo
(
DefaultConfigurationServlet
.
class
.
getName
());
assertThat
((
String
[])
propertyValues
.
get
(
"urlMappings"
)).
isEmpty
();
assertThat
((
String
[])
propertyValues
.
get
(
"urlMappings"
)).
isEmpty
();
assertThat
(
propertyValues
.
get
(
"servlet"
)).
isEqualTo
(
s
canned
);
assertThat
(
propertyValues
.
get
(
"servlet"
)).
isEqualTo
(
s
ervletdefinition
);
}
}
@Test
@Test
void
servletWithCustomName
()
throws
IOException
{
void
servletWithCustomName
()
throws
IOException
{
ScannedGenericBeanDefinition
scanned
=
new
ScannedGenericBeanDefinition
(
AnnotatedBeanDefinition
definition
=
createBeanDefinition
(
CustomNameServlet
.
class
);
new
SimpleMetadataReaderFactory
().
getMetadataReader
(
CustomNameServlet
.
class
.
getName
()));
this
.
handler
.
handle
(
definition
,
this
.
registry
);
this
.
handler
.
handle
(
scanned
,
this
.
registry
);
BeanDefinition
servletRegistrationBean
=
this
.
registry
.
getBeanDefinition
(
"custom"
);
BeanDefinition
servletRegistrationBean
=
this
.
registry
.
getBeanDefinition
(
"custom"
);
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
assertThat
(
propertyValues
.
get
(
"name"
)).
isEqualTo
(
"custom"
);
assertThat
(
propertyValues
.
get
(
"name"
)).
isEqualTo
(
"custom"
);
...
@@ -74,7 +74,7 @@ class WebServletHandlerTests {
...
@@ -74,7 +74,7 @@ class WebServletHandlerTests {
@Test
@Test
void
asyncSupported
()
throws
IOException
{
void
asyncSupported
()
throws
IOException
{
BeanDefinition
servletRegistrationBean
=
getBeanDefinition
(
AsyncSupportedServlet
.
class
);
BeanDefinition
servletRegistrationBean
=
handleBeanDefinitionForClass
(
AsyncSupportedServlet
.
class
);
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
assertThat
(
propertyValues
.
get
(
"asyncSupported"
)).
isEqualTo
(
true
);
assertThat
(
propertyValues
.
get
(
"asyncSupported"
)).
isEqualTo
(
true
);
}
}
...
@@ -82,7 +82,7 @@ class WebServletHandlerTests {
...
@@ -82,7 +82,7 @@ class WebServletHandlerTests {
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@Test
@Test
void
initParameters
()
throws
IOException
{
void
initParameters
()
throws
IOException
{
BeanDefinition
servletRegistrationBean
=
getBeanDefinition
(
InitParametersServlet
.
class
);
BeanDefinition
servletRegistrationBean
=
handleBeanDefinitionForClass
(
InitParametersServlet
.
class
);
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
assertThat
((
Map
<
String
,
String
>)
propertyValues
.
get
(
"initParameters"
)).
containsEntry
(
"a"
,
"alpha"
)
assertThat
((
Map
<
String
,
String
>)
propertyValues
.
get
(
"initParameters"
)).
containsEntry
(
"a"
,
"alpha"
)
.
containsEntry
(
"b"
,
"bravo"
);
.
containsEntry
(
"b"
,
"bravo"
);
...
@@ -90,28 +90,35 @@ class WebServletHandlerTests {
...
@@ -90,28 +90,35 @@ class WebServletHandlerTests {
@Test
@Test
void
urlMappings
()
throws
IOException
{
void
urlMappings
()
throws
IOException
{
BeanDefinition
servletRegistrationBean
=
getBeanDefinition
(
UrlPatternsServlet
.
class
);
BeanDefinition
servletRegistrationBean
=
handleBeanDefinitionForClass
(
UrlPatternsServlet
.
class
);
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
assertThat
((
String
[])
propertyValues
.
get
(
"urlMappings"
)).
contains
(
"alpha"
,
"bravo"
);
assertThat
((
String
[])
propertyValues
.
get
(
"urlMappings"
)).
contains
(
"alpha"
,
"bravo"
);
}
}
@Test
@Test
void
urlMappingsFromValue
()
throws
IOException
{
void
urlMappingsFromValue
()
throws
IOException
{
BeanDefinition
servletRegistrationBean
=
getBeanDefinition
(
UrlPatternsFromValueServlet
.
class
);
BeanDefinition
servletRegistrationBean
=
handleBeanDefinitionForClass
(
UrlPatternsFromValueServlet
.
class
);
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
MutablePropertyValues
propertyValues
=
servletRegistrationBean
.
getPropertyValues
();
assertThat
((
String
[])
propertyValues
.
get
(
"urlMappings"
)).
contains
(
"alpha"
,
"bravo"
);
assertThat
((
String
[])
propertyValues
.
get
(
"urlMappings"
)).
contains
(
"alpha"
,
"bravo"
);
}
}
@Test
@Test
void
urlPatternsDeclaredTwice
()
throws
IOException
{
void
urlPatternsDeclaredTwice
()
throws
IOException
{
assertThatIllegalStateException
().
isThrownBy
(()
->
getBeanDefinition
(
UrlPatternsDeclaredTwiceServlet
.
class
))
assertThatIllegalStateException
()
.
isThrownBy
(()
->
handleBeanDefinitionForClass
(
UrlPatternsDeclaredTwiceServlet
.
class
))
.
withMessageContaining
(
"The urlPatterns and value attributes are mutually exclusive."
);
.
withMessageContaining
(
"The urlPatterns and value attributes are mutually exclusive."
);
}
}
private
BeanDefinition
getBeanDefinition
(
Class
<?>
filterClass
)
throws
IOException
{
private
AnnotatedBeanDefinition
createBeanDefinition
(
Class
<?>
servletClass
)
throws
IOException
{
ScannedGenericBeanDefinition
scanned
=
new
ScannedGenericBeanDefinition
(
AnnotatedBeanDefinition
definition
=
mock
(
AnnotatedBeanDefinition
.
class
);
new
SimpleMetadataReaderFactory
().
getMetadataReader
(
filterClass
.
getName
()));
given
(
definition
.
getBeanClassName
()).
willReturn
(
servletClass
.
getName
());
this
.
handler
.
handle
(
scanned
,
this
.
registry
);
given
(
definition
.
getMetadata
()).
willReturn
(
new
SimpleMetadataReaderFactory
().
getMetadataReader
(
servletClass
.
getName
()).
getAnnotationMetadata
());
return
definition
;
}
private
BeanDefinition
handleBeanDefinitionForClass
(
Class
<?>
filterClass
)
throws
IOException
{
this
.
handler
.
handle
(
createBeanDefinition
(
filterClass
),
this
.
registry
);
return
this
.
registry
.
getBeanDefinition
(
filterClass
.
getName
());
return
this
.
registry
.
getBeanDefinition
(
filterClass
.
getName
());
}
}
...
...
src/checkstyle/checkstyle.xml
View file @
dd4377e6
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<property
name=
"illegalPkgs"
<property
name=
"illegalPkgs"
value=
"^sun.*, ^org\.apache\.commons\.(?!compress|dbcp2|lang|lang3|logging|pool2).*, ^com\.google\.common.*, ^io\.micrometer\.shaded.*, ^org\.flywaydb\.core\.internal.*, ^org\.testcontainers\.shaded.*"
/>
value=
"^sun.*, ^org\.apache\.commons\.(?!compress|dbcp2|lang|lang3|logging|pool2).*, ^com\.google\.common.*, ^io\.micrometer\.shaded.*, ^org\.flywaydb\.core\.internal.*, ^org\.testcontainers\.shaded.*"
/>
<property
name=
"illegalClasses"
<property
name=
"illegalClasses"
value=
"^com\.hazelcast\.util\.Base64, ^org\.junit\.rules\.ExpectedException, ^org\.mockito\.InjectMocks, ^org\.slf4j\.LoggerFactory, ^reactor\.core\.support\.Assert"
/>
value=
"^com\.hazelcast\.util\.Base64, ^org\.junit\.rules\.ExpectedException, ^org\.mockito\.InjectMocks, ^org\.slf4j\.LoggerFactory, ^
org.springframework.context.annotation.ScannedGenericBeanDefinition, ^
reactor\.core\.support\.Assert"
/>
</module>
</module>
<module
<module
name=
"com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck"
>
name=
"com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment