Equivalent of org.eclipse.jetty.server.Connector.getLocalPort() in Jetty 9.x

In Jetty 8.1.17.v20150415 I am using the org.eclipse.jetty.server.Connector.getLocalPort() method to determine which random HTTP port my Jetty is listening on, using the following line of code:

int port = server.getConnectors()[0].getLocalPort();

However, when I upgrade to a Jetty 9.x (9.3.3.v20150827), I find the getLocalPort() method doesn't exist any more. What is the replacement?

Jon Skeet
people
quotationmark

It looks like that's now in NetworkConnector (which extends Connector) - presumably because some connectors don't run over a network.

If you know that your server will be using a NetworkConnector, you could presumably use:

NetworkConnector networkConnector = (NetworkConnector) server.getConnectors()[0];
int port = networkConnector.getLocalPort();

people

See more on this question at Stackoverflow