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
7d4e558f
Commit
7d4e558f
authored
Jan 25, 2018
by
Huang YunKun
Committed by
Stephane Nicoll
Jan 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use PropertyMapper to configure WebServerFactory
See gh-11773
parent
584985c7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
70 deletions
+77
-70
DefaultReactiveWebServerFactoryCustomizer.java
...b/reactive/DefaultReactiveWebServerFactoryCustomizer.java
+17
-27
DefaultServletWebServerFactoryCustomizer.java
...web/servlet/DefaultServletWebServerFactoryCustomizer.java
+26
-43
DefaultReactiveWebServerFactoryCustomizerTests.java
...ctive/DefaultReactiveWebServerFactoryCustomizerTests.java
+12
-0
DefaultServletWebServerFactoryCustomizerTests.java
...ervlet/DefaultServletWebServerFactoryCustomizerTests.java
+22
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/DefaultReactiveWebServerFactoryCustomizer.java
View file @
7d4e558f
...
...
@@ -20,6 +20,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
import
org.springframework.boot.autoconfigure.web.embedded.jetty.JettyCustomizer
;
import
org.springframework.boot.autoconfigure.web.embedded.tomcat.TomcatCustomizer
;
import
org.springframework.boot.autoconfigure.web.embedded.undertow.UndertowCustomizer
;
import
org.springframework.boot.context.properties.PropertyMapper
;
import
org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory
;
import
org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory
;
import
org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory
;
...
...
@@ -33,6 +34,7 @@ import org.springframework.core.env.Environment;
* Default {@link WebServerFactoryCustomizer} for reactive servers.
*
* @author Brian Clozel
* @author Yunkun Huang
* @since 2.0.0
*/
public
class
DefaultReactiveWebServerFactoryCustomizer
...
...
@@ -59,33 +61,21 @@ public class DefaultReactiveWebServerFactoryCustomizer
@Override
public
void
customize
(
ConfigurableReactiveWebServerFactory
factory
)
{
if
(
this
.
serverProperties
.
getPort
()
!=
null
)
{
factory
.
setPort
(
this
.
serverProperties
.
getPort
());
}
if
(
this
.
serverProperties
.
getAddress
()
!=
null
)
{
factory
.
setAddress
(
this
.
serverProperties
.
getAddress
());
}
if
(
this
.
serverProperties
.
getSsl
()
!=
null
)
{
factory
.
setSsl
(
this
.
serverProperties
.
getSsl
());
}
if
(
this
.
serverProperties
.
getCompression
()
!=
null
)
{
factory
.
setCompression
(
this
.
serverProperties
.
getCompression
());
}
if
(
this
.
serverProperties
.
getHttp2
()
!=
null
)
{
factory
.
setHttp2
(
this
.
serverProperties
.
getHttp2
());
}
if
(
factory
instanceof
TomcatReactiveWebServerFactory
)
{
TomcatCustomizer
.
customizeTomcat
(
this
.
serverProperties
,
this
.
environment
,
(
TomcatReactiveWebServerFactory
)
factory
);
}
if
(
factory
instanceof
JettyReactiveWebServerFactory
)
{
JettyCustomizer
.
customizeJetty
(
this
.
serverProperties
,
this
.
environment
,
(
JettyReactiveWebServerFactory
)
factory
);
}
if
(
factory
instanceof
UndertowReactiveWebServerFactory
)
{
UndertowCustomizer
.
customizeUndertow
(
this
.
serverProperties
,
this
.
environment
,
(
UndertowReactiveWebServerFactory
)
factory
);
}
PropertyMapper
map
=
PropertyMapper
.
get
();
map
.
from
(
this
.
serverProperties
::
getPort
).
whenNonNull
().
to
(
factory:
:
setPort
);
map
.
from
(
this
.
serverProperties
::
getAddress
).
whenNonNull
().
to
(
factory:
:
setAddress
);
map
.
from
(
this
.
serverProperties
::
getSsl
).
whenNonNull
().
to
(
factory:
:
setSsl
);
map
.
from
(
this
.
serverProperties
::
getCompression
).
whenNonNull
().
to
(
factory:
:
setCompression
);
map
.
from
(
this
.
serverProperties
::
getHttp2
).
whenNonNull
().
to
(
factory:
:
setHttp2
);
map
.
from
(()
->
factory
).
when
(
configurableReactiveWebServerFactory
->
factory
instanceof
TomcatReactiveWebServerFactory
)
.
to
(
configurableReactiveWebServerFactory
->
TomcatCustomizer
.
customizeTomcat
(
this
.
serverProperties
,
this
.
environment
,
(
TomcatReactiveWebServerFactory
)
factory
));
map
.
from
(()
->
factory
).
when
(
configurableReactiveWebServerFactory
->
factory
instanceof
JettyReactiveWebServerFactory
)
.
to
(
configurableReactiveWebServerFactory
->
JettyCustomizer
.
customizeJetty
(
this
.
serverProperties
,
this
.
environment
,
(
JettyReactiveWebServerFactory
)
factory
));
map
.
from
(()
->
factory
).
when
(
configurableReactiveWebServerFactory
->
factory
instanceof
UndertowReactiveWebServerFactory
)
.
to
(
configurableReactiveWebServerFactory
->
UndertowCustomizer
.
customizeUndertow
(
this
.
serverProperties
,
this
.
environment
,
(
UndertowReactiveWebServerFactory
)
factory
));
}
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DefaultServletWebServerFactoryCustomizer.java
View file @
7d4e558f
...
...
@@ -20,6 +20,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
import
org.springframework.boot.autoconfigure.web.embedded.jetty.JettyCustomizer
;
import
org.springframework.boot.autoconfigure.web.embedded.tomcat.TomcatCustomizer
;
import
org.springframework.boot.autoconfigure.web.embedded.undertow.UndertowCustomizer
;
import
org.springframework.boot.context.properties.PropertyMapper
;
import
org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory
;
import
org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory
;
import
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
;
...
...
@@ -37,6 +38,7 @@ import org.springframework.util.ObjectUtils;
* @author Brian Clozel
* @author Stephane Nicoll
* @author Olivier Lamy
* @author Yunkun Huang
* @since 2.0.0
*/
public
class
DefaultServletWebServerFactoryCustomizer
...
...
@@ -67,49 +69,30 @@ public class DefaultServletWebServerFactoryCustomizer
@Override
public
void
customize
(
ConfigurableServletWebServerFactory
factory
)
{
if
(
this
.
serverProperties
.
getPort
()
!=
null
)
{
factory
.
setPort
(
this
.
serverProperties
.
getPort
());
}
if
(
this
.
serverProperties
.
getAddress
()
!=
null
)
{
factory
.
setAddress
(
this
.
serverProperties
.
getAddress
());
}
if
(
this
.
serverProperties
.
getServlet
().
getContextPath
()
!=
null
)
{
factory
.
setContextPath
(
this
.
serverProperties
.
getServlet
().
getContextPath
());
}
if
(
this
.
serverProperties
.
getDisplayName
()
!=
null
)
{
factory
.
setDisplayName
(
this
.
serverProperties
.
getDisplayName
());
}
factory
.
setSession
(
this
.
serverProperties
.
getServlet
().
getSession
());
if
(
this
.
serverProperties
.
getSsl
()
!=
null
)
{
factory
.
setSsl
(
this
.
serverProperties
.
getSsl
());
}
if
(
this
.
serverProperties
.
getServlet
()
!=
null
)
{
factory
.
setJsp
(
this
.
serverProperties
.
getServlet
().
getJsp
());
}
if
(
this
.
serverProperties
.
getCompression
()
!=
null
)
{
factory
.
setCompression
(
this
.
serverProperties
.
getCompression
());
}
if
(
this
.
serverProperties
.
getHttp2
()
!=
null
)
{
factory
.
setHttp2
(
this
.
serverProperties
.
getHttp2
());
}
factory
.
setServerHeader
(
this
.
serverProperties
.
getServerHeader
());
if
(
factory
instanceof
TomcatServletWebServerFactory
)
{
TomcatServletWebServerFactory
tomcatFactory
=
(
TomcatServletWebServerFactory
)
factory
;
TomcatCustomizer
.
customizeTomcat
(
this
.
serverProperties
,
this
.
environment
,
tomcatFactory
);
TomcatServletCustomizer
.
customizeTomcat
(
this
.
serverProperties
,
this
.
environment
,
tomcatFactory
);
}
if
(
factory
instanceof
JettyServletWebServerFactory
)
{
JettyCustomizer
.
customizeJetty
(
this
.
serverProperties
,
this
.
environment
,
(
JettyServletWebServerFactory
)
factory
);
}
if
(
factory
instanceof
UndertowServletWebServerFactory
)
{
UndertowCustomizer
.
customizeUndertow
(
this
.
serverProperties
,
this
.
environment
,
(
UndertowServletWebServerFactory
)
factory
);
}
factory
.
setInitParameters
(
this
.
serverProperties
.
getServlet
().
getContextParameters
());
PropertyMapper
map
=
PropertyMapper
.
get
();
map
.
from
(
this
.
serverProperties
::
getPort
).
whenNonNull
().
to
(
factory:
:
setPort
);
map
.
from
(
this
.
serverProperties
::
getAddress
).
whenNonNull
().
to
(
factory:
:
setAddress
);
map
.
from
(
this
.
serverProperties
.
getServlet
()::
getContextPath
).
whenNonNull
().
to
(
factory:
:
setContextPath
);
map
.
from
(
this
.
serverProperties
::
getDisplayName
).
whenNonNull
().
to
(
factory:
:
setDisplayName
);
map
.
from
(
this
.
serverProperties
.
getServlet
()::
getSession
).
to
(
factory:
:
setSession
);
map
.
from
(
this
.
serverProperties
::
getSsl
).
whenNonNull
().
to
(
factory:
:
setSsl
);
map
.
from
(
this
.
serverProperties
::
getServlet
).
whenNonNull
().
as
(
ServerProperties
.
Servlet
::
getJsp
).
to
(
factory:
:
setJsp
);
map
.
from
(
this
.
serverProperties
::
getCompression
).
whenNonNull
().
to
(
factory:
:
setCompression
);
map
.
from
(
this
.
serverProperties
::
getHttp2
).
whenNonNull
().
to
(
factory:
:
setHttp2
);
map
.
from
(
this
.
serverProperties
::
getServerHeader
).
to
(
factory:
:
setServerHeader
);
map
.
from
(()
->
factory
).
when
(
configurableServletWebServerFactory
->
factory
instanceof
TomcatServletWebServerFactory
)
.
to
(
configurableServletWebServerFactory
->
{
TomcatServletWebServerFactory
tomcatFactory
=
(
TomcatServletWebServerFactory
)
factory
;
TomcatCustomizer
.
customizeTomcat
(
this
.
serverProperties
,
this
.
environment
,
tomcatFactory
);
TomcatServletCustomizer
.
customizeTomcat
(
this
.
serverProperties
,
this
.
environment
,
tomcatFactory
);
});
map
.
from
(()
->
factory
).
when
(
configurableServletWebServerFactory
->
factory
instanceof
JettyServletWebServerFactory
)
.
to
(
configurableServletWebServerFactory
->
JettyCustomizer
.
customizeJetty
(
this
.
serverProperties
,
this
.
environment
,
(
JettyServletWebServerFactory
)
factory
));
map
.
from
(()
->
factory
).
when
(
configurableServletWebServerFactory
->
factory
instanceof
UndertowServletWebServerFactory
)
.
to
(
configurableServletWebServerFactory
->
UndertowCustomizer
.
customizeUndertow
(
this
.
serverProperties
,
this
.
environment
,
(
UndertowServletWebServerFactory
)
factory
));
map
.
from
(
this
.
serverProperties
.
getServlet
()::
getContextParameters
).
to
(
factory:
:
setInitParameters
);
}
private
static
class
TomcatServletCustomizer
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/DefaultReactiveWebServerFactoryCustomizerTests.java
View file @
7d4e558f
...
...
@@ -46,6 +46,7 @@ import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFacto
import
org.springframework.boot.web.embedded.tomcat.TomcatWebServer
;
import
org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory
;
import
org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory
;
import
org.springframework.boot.web.server.Ssl
;
import
org.springframework.http.server.reactive.HttpHandler
;
import
org.springframework.mock.env.MockEnvironment
;
...
...
@@ -60,6 +61,7 @@ import static org.mockito.Mockito.verify;
* Tests for {@link DefaultReactiveWebServerFactoryCustomizer}.
*
* @author Brian Clozel
* @author Yunkun Huang
*/
public
class
DefaultReactiveWebServerFactoryCustomizerTests
{
...
...
@@ -91,6 +93,16 @@ public class DefaultReactiveWebServerFactoryCustomizerTests {
verify
(
factory
).
setAddress
(
address
);
}
@Test
public
void
testCustomizeServerSsl
()
{
ConfigurableReactiveWebServerFactory
factory
=
mock
(
ConfigurableReactiveWebServerFactory
.
class
);
Ssl
ssl
=
mock
(
Ssl
.
class
);
this
.
properties
.
setSsl
(
ssl
);
this
.
customizer
.
customize
(
factory
);
verify
(
factory
).
setSsl
(
ssl
);
}
@Test
public
void
tomcatAccessLogIsDisabledByDefault
()
{
TomcatReactiveWebServerFactory
factory
=
new
TomcatReactiveWebServerFactory
();
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DefaultServletWebServerFactoryCustomizerTests.java
View file @
7d4e558f
...
...
@@ -49,13 +49,16 @@ import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
import
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
;
import
org.springframework.boot.web.embedded.tomcat.TomcatWebServer
;
import
org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory
;
import
org.springframework.boot.web.server.Ssl
;
import
org.springframework.boot.web.servlet.ServletContextInitializer
;
import
org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory
;
import
org.springframework.boot.web.servlet.server.Jsp
;
import
org.springframework.boot.web.servlet.server.Session
;
import
org.springframework.boot.web.servlet.server.Session.Cookie
;
import
org.springframework.mock.env.MockEnvironment
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyBoolean
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
...
...
@@ -66,6 +69,7 @@ import static org.mockito.Mockito.verify;
* Tests for {@link DefaultServletWebServerFactoryCustomizer}.
*
* @author Brian Clozel
* @author Yunkun Huang
*/
public
class
DefaultServletWebServerFactoryCustomizerTests
{
...
...
@@ -203,6 +207,24 @@ public class DefaultServletWebServerFactoryCustomizerTests {
verify
(
factory
).
setDisplayName
(
"TestName"
);
}
@Test
public
void
testCustomizeSsl
()
{
ConfigurableServletWebServerFactory
factory
=
mock
(
ConfigurableServletWebServerFactory
.
class
);
Ssl
ssl
=
mock
(
Ssl
.
class
);
this
.
properties
.
setSsl
(
ssl
);
this
.
customizer
.
customize
(
factory
);
verify
(
factory
).
setSsl
(
ssl
);
}
@Test
public
void
testCustomizeJsp
()
{
ConfigurableServletWebServerFactory
factory
=
mock
(
ConfigurableServletWebServerFactory
.
class
);
this
.
customizer
.
customize
(
factory
);
verify
(
factory
).
setJsp
(
any
(
Jsp
.
class
));
}
@Test
public
void
customizeSessionProperties
()
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
...
...
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