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
b60150b0
Commit
b60150b0
authored
Dec 02, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Tomcat Access Log's buffering configurable via the environment
Closes gh-7456
parent
b546fd10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
+57
-0
ServerProperties.java
...ingframework/boot/autoconfigure/web/ServerProperties.java
+14
-0
ServerPropertiesTests.java
...amework/boot/autoconfigure/web/ServerPropertiesTests.java
+43
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java
View file @
b60150b0
...
...
@@ -1005,6 +1005,7 @@ public class ServerProperties
valve
.
setRequestAttributesEnabled
(
this
.
accesslog
.
isRequestAttributesEnabled
());
valve
.
setRotatable
(
this
.
accesslog
.
isRotate
());
valve
.
setBuffered
(
this
.
accesslog
.
isBuffered
());
factory
.
addEngineValves
(
valve
);
}
...
...
@@ -1065,6 +1066,11 @@ public class ServerProperties
*/
private
boolean
requestAttributesEnabled
;
/**
* Buffer output such that it is only flushed periodically.
*/
private
boolean
buffered
=
true
;
public
boolean
isEnabled
()
{
return
this
.
enabled
;
}
...
...
@@ -1129,6 +1135,14 @@ public class ServerProperties
this
.
requestAttributesEnabled
=
requestAttributesEnabled
;
}
public
boolean
isBuffered
()
{
return
this
.
buffered
;
}
public
void
setBuffered
(
boolean
buffered
)
{
this
.
buffered
=
buffered
;
}
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java
View file @
b60150b0
...
...
@@ -31,6 +31,7 @@ import javax.servlet.SessionTrackingMode;
import
org.apache.catalina.Context
;
import
org.apache.catalina.Valve
;
import
org.apache.catalina.valves.AccessLogValve
;
import
org.apache.catalina.valves.RemoteIpValve
;
import
org.apache.coyote.AbstractProtocol
;
import
org.junit.Before
;
...
...
@@ -140,6 +141,48 @@ public class ServerPropertiesTests {
assertThat
(
this
.
properties
.
getServletPrefix
()).
isEqualTo
(
"/foo"
);
}
@Test
public
void
tomcatAccessLogIsDisabledByDefault
()
{
TomcatEmbeddedServletContainerFactory
tomcatContainer
=
new
TomcatEmbeddedServletContainerFactory
();
this
.
properties
.
customize
(
tomcatContainer
);
assertThat
(
tomcatContainer
.
getEngineValves
()).
isEmpty
();
}
@Test
public
void
tomcatAccessLogCanBeEnabled
()
{
TomcatEmbeddedServletContainerFactory
tomcatContainer
=
new
TomcatEmbeddedServletContainerFactory
();
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"server.tomcat.accesslog.enabled"
,
"true"
);
bindProperties
(
map
);
this
.
properties
.
customize
(
tomcatContainer
);
assertThat
(
tomcatContainer
.
getEngineValves
()).
hasSize
(
1
);
assertThat
(
tomcatContainer
.
getEngineValves
()).
first
()
.
isInstanceOf
(
AccessLogValve
.
class
);
}
@Test
public
void
tomcatAccessLogIsBufferedByDefault
()
{
TomcatEmbeddedServletContainerFactory
tomcatContainer
=
new
TomcatEmbeddedServletContainerFactory
();
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"server.tomcat.accesslog.enabled"
,
"true"
);
bindProperties
(
map
);
this
.
properties
.
customize
(
tomcatContainer
);
assertThat
(((
AccessLogValve
)
tomcatContainer
.
getEngineValves
().
iterator
().
next
())
.
isBuffered
()).
isTrue
();
}
@Test
public
void
tomcatAccessLogBufferingCanBeDisabled
()
{
TomcatEmbeddedServletContainerFactory
tomcatContainer
=
new
TomcatEmbeddedServletContainerFactory
();
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"server.tomcat.accesslog.enabled"
,
"true"
);
map
.
put
(
"server.tomcat.accesslog.buffered"
,
"false"
);
bindProperties
(
map
);
this
.
properties
.
customize
(
tomcatContainer
);
assertThat
(((
AccessLogValve
)
tomcatContainer
.
getEngineValves
().
iterator
().
next
())
.
isBuffered
()).
isFalse
();
}
@Test
public
void
testTomcatBinding
()
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
...
...
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