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
489e9736
Commit
489e9736
authored
Mar 25, 2014
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #542 from snicoll/gh-540
* gh-540: Support Tomcat uri encoding (with UTF-8 default)
parents
75548c12
87321edf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
2 deletions
+72
-2
ServerProperties.java
...ingframework/boot/autoconfigure/web/ServerProperties.java
+14
-0
ServerPropertiesTests.java
...amework/boot/autoconfigure/web/ServerPropertiesTests.java
+10
-0
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+1
-0
TomcatEmbeddedServletContainerFactory.java
...mbedded/tomcat/TomcatEmbeddedServletContainerFactory.java
+25
-0
TomcatEmbeddedServletContainerFactoryTests.java
...ed/tomcat/TomcatEmbeddedServletContainerFactoryTests.java
+22
-2
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java
View file @
489e9736
...
@@ -43,6 +43,7 @@ import org.springframework.util.StringUtils;
...
@@ -43,6 +43,7 @@ import org.springframework.util.StringUtils;
* {@link EmbeddedServletContainerCustomizerBeanPostProcessor} is active.
* {@link EmbeddedServletContainerCustomizerBeanPostProcessor} is active.
*
*
* @author Dave Syer
* @author Dave Syer
* @author Stephane Nicoll
*/
*/
@ConfigurationProperties
(
prefix
=
"server"
,
ignoreUnknownFields
=
false
)
@ConfigurationProperties
(
prefix
=
"server"
,
ignoreUnknownFields
=
false
)
public
class
ServerProperties
implements
EmbeddedServletContainerCustomizer
{
public
class
ServerProperties
implements
EmbeddedServletContainerCustomizer
{
...
@@ -144,6 +145,8 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
...
@@ -144,6 +145,8 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
private
int
maxThreads
=
0
;
// Number of threads in protocol handler
private
int
maxThreads
=
0
;
// Number of threads in protocol handler
private
String
uriEncoding
;
public
int
getMaxThreads
()
{
public
int
getMaxThreads
()
{
return
this
.
maxThreads
;
return
this
.
maxThreads
;
}
}
...
@@ -200,6 +203,14 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
...
@@ -200,6 +203,14 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
this
.
remoteIpHeader
=
remoteIpHeader
;
this
.
remoteIpHeader
=
remoteIpHeader
;
}
}
public
String
getUriEncoding
()
{
return
this
.
uriEncoding
;
}
public
void
setUriEncoding
(
String
uriEncoding
)
{
this
.
uriEncoding
=
uriEncoding
;
}
void
customizeTomcat
(
TomcatEmbeddedServletContainerFactory
factory
)
{
void
customizeTomcat
(
TomcatEmbeddedServletContainerFactory
factory
)
{
if
(
getBasedir
()
!=
null
)
{
if
(
getBasedir
()
!=
null
)
{
factory
.
setBaseDirectory
(
getBasedir
());
factory
.
setBaseDirectory
(
getBasedir
());
...
@@ -247,6 +258,9 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
...
@@ -247,6 +258,9 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
valve
.
setSuffix
(
".log"
);
valve
.
setSuffix
(
".log"
);
factory
.
addContextValves
(
valve
);
factory
.
addContextValves
(
valve
);
}
}
if
(
getUriEncoding
()
!=
null
)
{
factory
.
setUriEncoding
(
getUriEncoding
());
}
}
}
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java
View file @
489e9736
...
@@ -36,6 +36,7 @@ import static org.mockito.Mockito.verify;
...
@@ -36,6 +36,7 @@ import static org.mockito.Mockito.verify;
* Tests for {@link ServerProperties}.
* Tests for {@link ServerProperties}.
*
*
* @author Dave Syer
* @author Dave Syer
* @author Stephane Nicoll
*/
*/
public
class
ServerPropertiesTests
{
public
class
ServerPropertiesTests
{
...
@@ -87,4 +88,13 @@ public class ServerPropertiesTests {
...
@@ -87,4 +88,13 @@ public class ServerPropertiesTests {
verify
(
factory
).
setPort
(
8080
);
verify
(
factory
).
setPort
(
8080
);
}
}
@Test
public
void
testCustomizeUriEncoding
()
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"server.tomcat.uriEncoding"
,
"US-ASCII"
);
new
RelaxedDataBinder
(
this
.
properties
,
"server"
).
bind
(
new
MutablePropertyValues
(
map
));
assertEquals
(
"US-ASCII"
,
this
.
properties
.
getTomcat
().
getUriEncoding
());
}
}
}
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
489e9736
...
@@ -61,6 +61,7 @@ server.tomcat.remote-ip-header=x-forwarded-for
...
@@ -61,6 +61,7 @@ server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp)
server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp)
server.tomcat.background-processor-delay=30; # in seconds
server.tomcat.background-processor-delay=30; # in seconds
server.tomcat.max-threads = 0 # number of threads in protocol handler
server.tomcat.max-threads = 0 # number of threads in protocol handler
server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding
# SPRING MVC ({sc-spring-boot-autoconfigure}/web/HttpMapperProperties.{sc-ext}[HttpMapperProperties])
# SPRING MVC ({sc-spring-boot-autoconfigure}/web/HttpMapperProperties.{sc-ext}[HttpMapperProperties])
http.mappers.json-pretty-print=false # pretty print JSON
http.mappers.json-pretty-print=false # pretty print JSON
...
...
spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java
View file @
489e9736
...
@@ -66,6 +66,7 @@ import org.springframework.util.StreamUtils;
...
@@ -66,6 +66,7 @@ import org.springframework.util.StreamUtils;
* @author Phillip Webb
* @author Phillip Webb
* @author Dave Syer
* @author Dave Syer
* @author Brock Mills
* @author Brock Mills
* @author Stephane Nicoll
* @see #setPort(int)
* @see #setPort(int)
* @see #setContextLifecycleListeners(Collection)
* @see #setContextLifecycleListeners(Collection)
* @see TomcatEmbeddedServletContainer
* @see TomcatEmbeddedServletContainer
...
@@ -93,6 +94,8 @@ public class TomcatEmbeddedServletContainerFactory extends
...
@@ -93,6 +94,8 @@ public class TomcatEmbeddedServletContainerFactory extends
private
String
tldSkip
;
private
String
tldSkip
;
private
String
uriEncoding
=
"UTF-8"
;
/**
/**
* Create a new {@link TomcatEmbeddedServletContainerFactory} instance.
* Create a new {@link TomcatEmbeddedServletContainerFactory} instance.
*/
*/
...
@@ -206,6 +209,10 @@ public class TomcatEmbeddedServletContainerFactory extends
...
@@ -206,6 +209,10 @@ public class TomcatEmbeddedServletContainerFactory extends
.
setAddress
(
getAddress
());
.
setAddress
(
getAddress
());
}
}
}
}
if
(
getUriEncoding
()
!=
null
)
{
connector
.
setURIEncoding
(
getUriEncoding
());
}
// If ApplicationContext is slow to start we want Tomcat not to bind to the socket
// If ApplicationContext is slow to start we want Tomcat not to bind to the socket
// prematurely...
// prematurely...
connector
.
setProperty
(
"bindOnInit"
,
"false"
);
connector
.
setProperty
(
"bindOnInit"
,
"false"
);
...
@@ -455,10 +462,28 @@ public class TomcatEmbeddedServletContainerFactory extends
...
@@ -455,10 +462,28 @@ public class TomcatEmbeddedServletContainerFactory extends
return
this
.
additionalTomcatConnectors
;
return
this
.
additionalTomcatConnectors
;
}
}
/**
* Set the character encoding to use for URL decoding. If not specified 'UTF-8' will
* be used.
* @param uriEncoding the uri encoding to set
*/
public
void
setUriEncoding
(
String
uriEncoding
)
{
this
.
uriEncoding
=
uriEncoding
;
}
/**
* Returns the character encoding to use for URL decoding.
*/
public
String
getUriEncoding
()
{
return
this
.
uriEncoding
;
}
private
static
class
TomcatErrorPage
{
private
static
class
TomcatErrorPage
{
private
final
String
location
;
private
final
String
location
;
private
final
String
exceptionType
;
private
final
String
exceptionType
;
private
final
int
errorCode
;
private
final
int
errorCode
;
private
final
Object
nativePage
;
private
final
Object
nativePage
;
...
...
spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java
View file @
489e9736
...
@@ -44,6 +44,7 @@ import static org.mockito.Mockito.verify;
...
@@ -44,6 +44,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Dave Syer
* @author Dave Syer
* @author Stephane Nicoll
*/
*/
public
class
TomcatEmbeddedServletContainerFactoryTests
extends
public
class
TomcatEmbeddedServletContainerFactoryTests
extends
AbstractEmbeddedServletContainerFactoryTests
{
AbstractEmbeddedServletContainerFactoryTests
{
...
@@ -190,11 +191,30 @@ public class TomcatEmbeddedServletContainerFactoryTests extends
...
@@ -190,11 +191,30 @@ public class TomcatEmbeddedServletContainerFactoryTests extends
factory
.
addConnectorCustomizers
((
TomcatConnectorCustomizer
[])
null
);
factory
.
addConnectorCustomizers
((
TomcatConnectorCustomizer
[])
null
);
}
}
@Test
public
void
uriEncoding
()
throws
Exception
{
TomcatEmbeddedServletContainerFactory
factory
=
getFactory
();
factory
.
setUriEncoding
(
"US-ASCII"
);
Tomcat
tomcat
=
getTomcat
(
factory
);
assertEquals
(
"US-ASCII"
,
tomcat
.
getConnector
().
getURIEncoding
());
}
@Test
public
void
defaultUriEncoding
()
throws
Exception
{
TomcatEmbeddedServletContainerFactory
factory
=
getFactory
();
Tomcat
tomcat
=
getTomcat
(
factory
);
assertEquals
(
"UTF-8"
,
tomcat
.
getConnector
().
getURIEncoding
());
}
private
void
assertTimeout
(
TomcatEmbeddedServletContainerFactory
factory
,
int
expected
)
{
private
void
assertTimeout
(
TomcatEmbeddedServletContainerFactory
factory
,
int
expected
)
{
this
.
container
=
factory
.
getEmbeddedServletContainer
();
Tomcat
tomcat
=
getTomcat
(
factory
);
Tomcat
tomcat
=
((
TomcatEmbeddedServletContainer
)
this
.
container
).
getTomcat
();
Context
context
=
(
Context
)
tomcat
.
getHost
().
findChildren
()[
0
];
Context
context
=
(
Context
)
tomcat
.
getHost
().
findChildren
()[
0
];
assertThat
(
context
.
getSessionTimeout
(),
equalTo
(
expected
));
assertThat
(
context
.
getSessionTimeout
(),
equalTo
(
expected
));
}
}
private
Tomcat
getTomcat
(
TomcatEmbeddedServletContainerFactory
factory
)
{
this
.
container
=
factory
.
getEmbeddedServletContainer
();
return
((
TomcatEmbeddedServletContainer
)
this
.
container
).
getTomcat
();
}
}
}
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