Skip to content

Commit 8295e82

Browse files
author
Dave Syer
committed
Extend use of reflection for port in Jetty 9
There was already a reflection hack in place for logging the local port in Jetty 8/9. It wasn't being used for the getPort() method for some reason, so that needed to be fixed. Fixes gh-635
1 parent bd1691f commit 8295e82

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,16 @@ public void start() throws EmbeddedServletContainerException {
103103
}
104104
}
105105

106-
private String getLocalPort(Connector connector) {
106+
private Integer getLocalPort(Connector connector) {
107107
try {
108108
// Jetty 9 internals are different, but the method name is the same
109-
return ((Integer) ReflectionUtils.invokeMethod(
109+
return (Integer) ReflectionUtils.invokeMethod(
110110
ReflectionUtils.findMethod(connector.getClass(), "getLocalPort"),
111-
connector)).toString();
111+
connector);
112112
}
113113
catch (Exception ex) {
114-
return "could not determine port ( " + ex.getMessage() + ")";
114+
this.logger.info("could not determine port ( " + ex.getMessage() + ")");
115+
return 0;
115116
}
116117
}
117118

@@ -134,7 +135,7 @@ public int getPort() {
134135
Connector[] connectors = this.server.getConnectors();
135136
for (Connector connector : connectors) {
136137
// Probably only one...
137-
return connector.getLocalPort();
138+
return getLocalPort(connector);
138139
}
139140
return 0;
140141
}

0 commit comments

Comments
 (0)