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
9b9c3edf
Commit
9b9c3edf
authored
Jan 05, 2021
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Return -1 port for non-listening WebServers"
See gh-24606
parent
5c61df31
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
23 deletions
+30
-23
JettyWebServer.java
...ringframework/boot/web/embedded/jetty/JettyWebServer.java
+25
-18
NettyWebServer.java
...ringframework/boot/web/embedded/netty/NettyWebServer.java
+1
-1
TomcatWebServer.java
...ngframework/boot/web/embedded/tomcat/TomcatWebServer.java
+1
-1
UndertowWebServer.java
...amework/boot/web/embedded/undertow/UndertowWebServer.java
+1
-1
AbstractReactiveWebServerFactoryTests.java
...eactive/server/AbstractReactiveWebServerFactoryTests.java
+1
-1
AbstractServletWebServerFactoryTests.java
.../servlet/server/AbstractServletWebServerFactoryTests.java
+1
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyWebServer.java
View file @
9b9c3edf
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -207,18 +207,6 @@ public class JettyWebServer implements WebServer {
return
ports
.
toString
();
}
private
Integer
getLocalPort
(
Connector
connector
)
{
try
{
// Jetty 9 internals are different, but the method name is the same
return
(
Integer
)
ReflectionUtils
.
invokeMethod
(
ReflectionUtils
.
findMethod
(
connector
.
getClass
(),
"getLocalPort"
),
connector
);
}
catch
(
Exception
ex
)
{
logger
.
info
(
"could not determine port ( "
+
ex
.
getMessage
()
+
")"
);
return
0
;
}
}
private
String
getProtocols
(
Connector
connector
)
{
List
<
String
>
protocols
=
connector
.
getProtocols
();
return
" ("
+
StringUtils
.
collectionToDelimitedString
(
protocols
,
", "
)
+
")"
;
...
...
@@ -275,13 +263,32 @@ public class JettyWebServer implements WebServer {
@Override
public
int
getPort
()
{
Connector
[]
connectors
=
this
.
server
.
getConnectors
();
Integer
localPort
=
-
1
;
for
(
Connector
connector
:
connectors
)
{
// Probably only one...
localPort
=
getLocalPort
(
connector
);
break
;
Integer
localPort
=
getLocalPort
(
connector
);
if
(
localPort
!=
null
&&
localPort
>
0
)
{
return
localPort
;
}
return
(
localPort
>
0
)
?
localPort
:
-
1
;
}
return
-
1
;
}
private
Integer
getLocalPort
(
Connector
connector
)
{
try
{
if
(
connector
instanceof
NetworkConnector
)
{
return
((
NetworkConnector
)
connector
).
getLocalPort
();
}
}
catch
(
Exception
ex
)
{
}
try
{
// Jetty 9 internals are different, but the method name is the same
return
(
Integer
)
ReflectionUtils
.
invokeMethod
(
ReflectionUtils
.
findMethod
(
connector
.
getClass
(),
"getLocalPort"
),
connector
);
}
catch
(
Exception
ex
)
{
logger
.
info
(
"could not determine port ( "
+
ex
.
getMessage
()
+
")"
);
}
return
0
;
}
@Override
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java
View file @
9b9c3edf
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatWebServer.java
View file @
9b9c3edf
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java
View file @
9b9c3edf
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java
View file @
9b9c3edf
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java
View file @
9b9c3edf
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
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