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
This commit is contained in:
@@ -103,15 +103,16 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer {
|
||||
}
|
||||
}
|
||||
|
||||
private String getLocalPort(Connector connector) {
|
||||
private Integer getLocalPort(Connector connector) {
|
||||
try {
|
||||
// Jetty 9 internals are different, but the method name is the same
|
||||
return ((Integer) ReflectionUtils.invokeMethod(
|
||||
return (Integer) ReflectionUtils.invokeMethod(
|
||||
ReflectionUtils.findMethod(connector.getClass(), "getLocalPort"),
|
||||
connector)).toString();
|
||||
connector);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "could not determine port ( " + ex.getMessage() + ")";
|
||||
this.logger.info("could not determine port ( " + ex.getMessage() + ")");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +135,7 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer {
|
||||
Connector[] connectors = this.server.getConnectors();
|
||||
for (Connector connector : connectors) {
|
||||
// Probably only one...
|
||||
return connector.getLocalPort();
|
||||
return getLocalPort(connector);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user