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
cfb1defb
Commit
cfb1defb
authored
Mar 24, 2017
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log the port used by Netty
Closes gh-8681
parent
f07d4f77
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
NettyWebServer.java
...ringframework/boot/web/embedded/netty/NettyWebServer.java
+28
-2
AbstractReactiveWebServerFactoryTests.java
...eactive/server/AbstractReactiveWebServerFactoryTests.java
+1
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java
View file @
cfb1defb
...
@@ -16,9 +16,12 @@
...
@@ -16,9 +16,12 @@
package
org
.
springframework
.
boot
.
web
.
embedded
.
netty
;
package
org
.
springframework
.
boot
.
web
.
embedded
.
netty
;
import
java.net.BindException
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.concurrent.atomic.AtomicReference
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
reactor.core.Loopback
;
import
reactor.core.Loopback
;
import
reactor.ipc.netty.NettyContext
;
import
reactor.ipc.netty.NettyContext
;
import
reactor.ipc.netty.http.server.HttpServer
;
import
reactor.ipc.netty.http.server.HttpServer
;
...
@@ -33,10 +36,13 @@ import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
...
@@ -33,10 +36,13 @@ import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
* directly.
* directly.
*
*
* @author Brian Clozel
* @author Brian Clozel
* @author Madhura Bhave
* @since 2.0.0
* @since 2.0.0
*/
*/
public
class
NettyWebServer
implements
WebServer
,
Loopback
{
public
class
NettyWebServer
implements
WebServer
,
Loopback
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
NettyWebServer
.
class
);
private
static
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
private
static
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
private
final
ReactorHttpHandlerAdapter
handlerAdapter
;
private
final
ReactorHttpHandlerAdapter
handlerAdapter
;
...
@@ -64,12 +70,32 @@ public class NettyWebServer implements WebServer, Loopback {
...
@@ -64,12 +70,32 @@ public class NettyWebServer implements WebServer, Loopback {
@Override
@Override
public
void
start
()
throws
WebServerException
{
public
void
start
()
throws
WebServerException
{
if
(
this
.
nettyContext
.
get
()
==
null
)
{
if
(
this
.
nettyContext
.
get
()
==
null
)
{
this
.
nettyContext
try
{
.
set
(
this
.
reactorServer
.
newHandler
(
this
.
handlerAdapter
).
block
());
this
.
nettyContext
.
set
(
this
.
reactorServer
.
newHandler
(
this
.
handlerAdapter
).
block
());
}
catch
(
Exception
ex
)
{
if
(
findBindException
(
ex
)
!=
null
)
{
// throw new PortInUseException();
}
throw
new
WebServerException
(
"Unable to start Netty"
,
ex
);
}
NettyWebServer
.
logger
.
info
(
"Netty started on port(s): "
+
getPort
());
startDaemonAwaitThread
();
startDaemonAwaitThread
();
}
}
}
}
private
BindException
findBindException
(
Exception
ex
)
{
Throwable
candidate
=
ex
;
while
(
candidate
!=
null
)
{
if
(
candidate
instanceof
BindException
)
{
return
(
BindException
)
candidate
;
}
candidate
=
candidate
.
getCause
();
}
return
null
;
}
private
void
startDaemonAwaitThread
()
{
private
void
startDaemonAwaitThread
()
{
Thread
awaitThread
=
new
Thread
(
"server"
)
{
Thread
awaitThread
=
new
Thread
(
"server"
)
{
...
...
spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java
View file @
cfb1defb
...
@@ -88,6 +88,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
...
@@ -88,6 +88,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
public
void
startStopServer
()
{
public
void
startStopServer
()
{
this
.
webServer
=
getFactory
().
getWebServer
(
new
EchoHandler
());
this
.
webServer
=
getFactory
().
getWebServer
(
new
EchoHandler
());
this
.
webServer
.
start
();
this
.
webServer
.
start
();
assertThat
(
this
.
output
.
toString
()).
contains
(
"started on port"
);
Mono
<
String
>
result
=
getWebClient
().
post
().
uri
(
"/test"
)
Mono
<
String
>
result
=
getWebClient
().
post
().
uri
(
"/test"
)
.
contentType
(
MediaType
.
TEXT_PLAIN
)
.
contentType
(
MediaType
.
TEXT_PLAIN
)
.
exchange
(
BodyInserters
.
fromObject
(
"Hello World"
))
.
exchange
(
BodyInserters
.
fromObject
(
"Hello World"
))
...
...
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