/** * Gets the actual bind hostname. * * @return the bind host */ public String getBindHost() { String bindHost = mServerConnector.getHost(); return bindHost == null ? "0.0.0.0" : bindHost; }
private static InetSocketAddress getAddress( String name, ServerConnector connector ) { if ( connector == null ) { throw new IllegalStateException( name + " connector is not configured" ); } return new InetSocketAddress( connector.getHost(), connector.getLocalPort() ); }
@Override public String toString() { Preconditions.checkState(!listeners.isEmpty()); StringBuilder sb = new StringBuilder("HttpServer (") .append(isAlive() ? STATE_DESCRIPTION_ALIVE : STATE_DESCRIPTION_NOT_LIVE) .append("), listening at:"); for (ServerConnector l : listeners) { sb.append(l.getHost()).append(":").append(l.getPort()).append("/,"); } return sb.toString(); }
/** * Return the host and port of the HttpServer, if live * @return the classname and any HTTP URL */ @Override public String toString() { if (listeners.isEmpty()) { return "Inactive HttpServer"; } else { StringBuilder sb = new StringBuilder("HttpServer (") .append(isAlive() ? STATE_DESCRIPTION_ALIVE : STATE_DESCRIPTION_NOT_LIVE).append("), listening at:"); for (ListenerInfo li : listeners) { ServerConnector l = li.listener; sb.append(l.getHost()).append(":").append(l.getPort()).append("/,"); } return sb.toString(); } }
/** * Get the address that corresponds to a particular connector. * * @return the corresponding address for the connector, or null if there's no * such connector or the connector is not bounded or was closed. */ public InetSocketAddress getConnectorAddress(int index) { Preconditions.checkArgument(index >= 0); if (index > webServer.getConnectors().length) return null; ServerConnector c = (ServerConnector)webServer.getConnectors()[index]; if (c.getLocalPort() == -1 || c.getLocalPort() == -2) { // The connector is not bounded or was closed return null; } return new InetSocketAddress(c.getHost(), c.getLocalPort()); }
private URI getServerUri(ServerConnector connector) throws URISyntaxException { String scheme = "http"; for (ConnectionFactory connectFactory : connector .getConnectionFactories()) { if (connectFactory.getProtocol().startsWith("SSL-http")) { scheme = "https"; } } String host = connector.getHost(); if (host == null) { try{ host = InetAddress.getLocalHost().getHostName(); }catch(Exception ex){} } if (host == null){ host = "localhost"; } int myport = connector.getLocalPort(); serverURI = new URI(String.format("%s://%s:%d", scheme, host, myport)); System.out.println(new Date() + " Server URI: " + serverURI + this.contextPath); return serverURI; }
private void tryToSetHostAndPortFromJetty() { // do best attempt at fetching port jetty will start with Connector[] connectors = jetty.getConnectors(); if (connectors != null && connectors.length > 0 && connectors[0] instanceof ServerConnector) { ServerConnector connector = (ServerConnector)connectors[0]; host(connector.getHost()); port(connector.getPort()); } }
/** * Get the address that corresponds to a particular connector. * * @return the corresponding address for the connector, or null if there's no * such connector or the connector is not bounded. */ public InetSocketAddress getConnectorAddress(int index) { Preconditions.checkArgument(index >= 0); if (index > webServer.getConnectors().length) return null; ServerConnector c = (ServerConnector)webServer.getConnectors()[index]; if (c.getLocalPort() == -1 || c.getLocalPort() == -2) { // -1 if the connector has not been opened // -2 if it has been closed return null; } return new InetSocketAddress(c.getHost(), c.getLocalPort()); }
/** * Create bind exception by wrapping the bind exception thrown. * @param listener * @param ex * @return */ private static BindException constructBindException(ServerConnector listener, BindException ex) { BindException be = new BindException("Port in use: " + listener.getHost() + ":" + listener.getPort()); if (ex != null) { be.initCause(ex); } return be; }
@Test public void shouldCreateAServerConnectorWithConfiguredPortAndBuffersize() throws Exception { assertThat(connector.getPort(), is(1234)); assertThat(connector.getHost(), is("foo")); assertThat(connector.getIdleTimeout(), is(200l)); assertThat(configuration.getOutputBufferSize(), is(100)); }
if (port == 0 || !findPort) { BindException be = new BindException("Port in use: " + listener.getHost() + ":" + listener.getPort()); be.initCause(ex); throw be;
@Test public void shouldCreateSslConnectorWithRelevantPortAndTimeout() { assertThat(sslSocketConnector.getConnector() instanceof ServerConnector, is(true)); ServerConnector connector = (ServerConnector) sslSocketConnector.getConnector(); assertThat(connector.getPort(), is(1234)); assertThat(connector.getHost(), is("foo")); assertThat(connector.getIdleTimeout(), is(200l)); }
/** Gets the host on which the static HTTP static server is listen on * */ String getHost() { String host = connector.getHost(); if (host == null) { // this means that server is listening on all the available interfaces try { // get a valid address that cna be used to build valid URLs return InetAddress.getLocalHost().getHostName(); } catch (Exception exception) { throw new RuntimeException("Error get local host name."); } } // return the host name the HTTP static server is bind to return host; }
private static void logConnector(ServerConnector connector) { try { String h = connector.getHost(); int port = connector.getPort(); LOG.finer("connector.host: " + h == null ? "null" : "\"" + h + "\""); LOG.finer("connector.port: " + port); } catch (Throwable t) { //ignore } }
private static void logConnector(ServerConnector connector) { try { String h = connector.getHost(); int port = connector.getPort(); LOG.finer("connector.host: " + h == null ? "null" : "\"" + h + "\""); LOG.finer("connector.port: " + port); } catch (Throwable t) { //ignore } }
/** * Returns the socket the WebSocket server is listening on. */ public SocketAddress getWebSocketAddress() { if (httpServer == null) { return null; } else { ServerConnector c = (ServerConnector)httpServer.getConnectors()[0]; return new InetSocketAddress(c.getHost(), c.getLocalPort()); } }
private RpcMetadataResponse createRpcServerMetadata(ServerConnector connector) throws UnknownHostException { String host = connector.getHost(); if (null == host) { // "null" means binding to all interfaces, we need to pick one so the client gets a real // address and not "0.0.0.0" or similar. host = InetAddress.getLocalHost().getHostName(); } final int port = connector.getLocalPort(); return new RpcMetadataResponse( String.format(Locale.ROOT, "%s:%d", host, port)); }
public Object getMonitorValue(String key) { switch (key) { case "port": return connector.getPort(); case "host": return connector.getHost(); case "contextPath": return getContextPath(); } return null; } }
private URI toServerURI(ServerConnector connector) throws URISyntaxException { String host = connector.getHost(); if (host == null) { host = DEFAULT_HOST; } int port = connector.getLocalPort(); return new URI(String.format("http://%s:%d", host, port)); }