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
b4c94f42
Commit
b4c94f42
authored
Sep 23, 2014
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.1.x'
parents
5d1a114a
c420249f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
6 deletions
+86
-6
TomcatEmbeddedServletContainer.java
...ntext/embedded/tomcat/TomcatEmbeddedServletContainer.java
+12
-6
TomcatEmbeddedServletContainerFactoryTests.java
...ed/tomcat/TomcatEmbeddedServletContainerFactoryTests.java
+74
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java
View file @
b4c94f42
...
...
@@ -90,11 +90,6 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
// Unlike Jetty, all Tomcat threads are daemon threads. We create a
// blocking non-daemon to stop immediate shutdown
startDaemonAwaitThread
();
if
(
LifecycleState
.
FAILED
.
equals
(
this
.
tomcat
.
getConnector
().
getState
()))
{
this
.
tomcat
.
stop
();
throw
new
IllegalStateException
(
"Tomcat connector in failed state"
);
}
}
catch
(
Exception
ex
)
{
throw
new
EmbeddedServletContainerException
(
...
...
@@ -151,13 +146,24 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
if
(
connector
!=
null
&&
this
.
autoStart
)
{
startConnector
(
connector
);
}
// Ensure process isn't left running if it actually failed to start
if
(
LifecycleState
.
FAILED
.
equals
(
this
.
tomcat
.
getConnector
().
getState
()))
{
if
(
connectorsHaveFailedToStart
())
{
stopSilently
();
throw
new
IllegalStateException
(
"Tomcat connector in failed state"
);
}
}
private
boolean
connectorsHaveFailedToStart
()
{
for
(
Connector
connector
:
this
.
tomcat
.
getService
().
findConnectors
())
{
if
(
LifecycleState
.
FAILED
.
equals
(
connector
.
getState
()))
{
return
true
;
}
}
return
false
;
}
private
void
stopSilently
()
{
try
{
this
.
tomcat
.
stop
();
...
...
spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java
View file @
b4c94f42
...
...
@@ -16,6 +16,10 @@
package
org
.
springframework
.
boot
.
context
.
embedded
.
tomcat
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
import
java.net.ServerSocket
;
import
java.net.UnknownHostException
;
import
java.util.Arrays
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -39,6 +43,7 @@ import static org.hamcrest.Matchers.equalTo;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
...
...
@@ -248,6 +253,63 @@ public class TomcatEmbeddedServletContainerFactoryTests extends
assertThat
(
jsseProtocol
.
getCiphers
(),
equalTo
(
"ALPHA,BRAVO,CHARLIE"
));
}
@Test
public
void
primaryConnectorPortClashThrowsIllegalStateException
()
throws
InterruptedException
,
UnknownHostException
,
IOException
{
final
int
port
=
SocketUtils
.
findAvailableTcpPort
(
40000
);
doWithBlockedPort
(
port
,
new
Runnable
()
{
@Override
public
void
run
()
{
TomcatEmbeddedServletContainerFactory
factory
=
getFactory
();
factory
.
setPort
(
port
);
try
{
TomcatEmbeddedServletContainerFactoryTests
.
this
.
container
=
factory
.
getEmbeddedServletContainer
();
TomcatEmbeddedServletContainerFactoryTests
.
this
.
container
.
start
();
fail
();
}
catch
(
IllegalStateException
ex
)
{
}
}
});
}
@Test
public
void
additionalConnectorPortClashThrowsIllegalStateException
()
throws
InterruptedException
,
UnknownHostException
,
IOException
{
final
int
port
=
SocketUtils
.
findAvailableTcpPort
(
40000
);
doWithBlockedPort
(
port
,
new
Runnable
()
{
@Override
public
void
run
()
{
TomcatEmbeddedServletContainerFactory
factory
=
getFactory
();
Connector
connector
=
new
Connector
(
"org.apache.coyote.http11.Http11NioProtocol"
);
connector
.
setPort
(
port
);
factory
.
addAdditionalTomcatConnectors
(
connector
);
try
{
TomcatEmbeddedServletContainerFactoryTests
.
this
.
container
=
factory
.
getEmbeddedServletContainer
();
TomcatEmbeddedServletContainerFactoryTests
.
this
.
container
.
start
();
fail
();
}
catch
(
IllegalStateException
ex
)
{
}
}
});
}
private
void
assertTimeout
(
TomcatEmbeddedServletContainerFactory
factory
,
int
expected
)
{
Tomcat
tomcat
=
getTomcat
(
factory
);
Context
context
=
(
Context
)
tomcat
.
getHost
().
findChildren
()[
0
];
...
...
@@ -259,4 +321,16 @@ public class TomcatEmbeddedServletContainerFactoryTests extends
return
((
TomcatEmbeddedServletContainer
)
this
.
container
).
getTomcat
();
}
private
void
doWithBlockedPort
(
final
int
port
,
Runnable
action
)
throws
IOException
{
ServerSocket
serverSocket
=
new
ServerSocket
();
serverSocket
.
bind
(
new
InetSocketAddress
(
port
));
try
{
action
.
run
();
}
finally
{
serverSocket
.
close
();
}
}
}
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