@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(); } }
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()); } }
/** * 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; }
/** * Open the main listener for the server * @throws Exception */ void openListeners() throws Exception { LOG.debug("opening listeners: {}", listeners); for (ServerConnector listener : listeners) { if (listener.getLocalPort() != -1 && listener.getLocalPort() != -2) { // This listener is either started externally or has been bound or was // closed continue; } int port = listener.getPort(); if (portRanges != null && port != 0) { bindForPortRange(listener, port); } else { bindForSinglePort(listener, port); } } }
private void logAdminConsolePorts() { // Log what ports the admin console is running on. String listening = LocaleUtils.getLocalizedString("admin.console.listening"); String hostname = getBindInterface() == null ? XMPPServer.getInstance().getServerInfo().getXMPPDomain() : getBindInterface(); boolean isPlainStarted = false; boolean isSecureStarted = false; for (Connector connector : adminServer.getConnectors()) { if (((ServerConnector) connector).getPort() == adminPort) { isPlainStarted = true; } else if (((ServerConnector) connector).getPort() == adminSecurePort) { isSecureStarted = true; } } if (isPlainStarted && isSecureStarted) { log(listening + ":" + System.getProperty("line.separator") + " http://" + hostname + ":" + adminPort + System.getProperty("line.separator") + " https://" + hostname + ":" + adminSecurePort); } else if (isSecureStarted) { log(listening + " https://" + hostname + ":" + adminSecurePort); } else if (isPlainStarted) { log(listening + " http://" + hostname + ":" + adminPort); } }
@Test public void testSetPortNoBindAddress() { final HttpService jetty = new HttpService(null, 8090, SSLConfigurationFactory .getSSLConfigForComponent(distributionConfig, SecurableCommunicationChannel.WEB)); assertThat(jetty).isNotNull(); assertThat(jetty.getHttpServer().getConnectors()[0]).isNotNull(); assertThat(((ServerConnector) jetty.getHttpServer().getConnectors()[0]).getPort()) .isEqualTo(8090); }
@Test public void testSetPortWithBindAddress() { final HttpService jetty = new HttpService("10.123.50.1", 10480, SSLConfigurationFactory .getSSLConfigForComponent(distributionConfig, SecurableCommunicationChannel.WEB)); assertThat(jetty).isNotNull(); assertThat(jetty.getHttpServer().getConnectors()[0]).isNotNull(); assertThat(((ServerConnector) jetty.getHttpServer().getConnectors()[0]).getPort()) .isEqualTo(10480); } }
@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)); }
@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)); }
private HttpServer checkBindAddress(String host, int port, boolean findPort) throws Exception { HttpServer server = createServer(host, port); try { // not bound, ephemeral should return requested port (0 for ephemeral) ServerConnector listener = server.getServerConnectors().get(0); assertEquals(port, listener.getPort()); // verify hostname is what was given server.openListeners(); assertEquals(host, server.getConnectorAddress(0).getHostName()); int boundPort = server.getConnectorAddress(0).getPort(); if (port == 0) { assertTrue(boundPort != 0); // ephemeral should now return bound port } else if (findPort) { assertTrue(boundPort > port); // allow a little wiggle room to prevent random test failures if // some consecutive ports are already in use assertTrue(boundPort - port < 8); } } catch (Exception e) { server.stop(); throw e; } return server; }
/** * Stop the {@link JettyFusekiWebapp} instance. */ public void stop() { String now = DateTimeUtils.nowAsString() ; serverLog.info(format("Stopped %s on port %d", now, serverConnector.getPort())) ; try { server.stop() ; } catch (Exception ex) { Fuseki.serverLog.warn("SPARQLServer: Exception while stopping server: " + ex.getMessage(), ex) ; } }
/** * Stop the {@link JettyFusekiWebapp} instance. */ public void stop() { String now = DateTimeUtils.nowAsString() ; serverLog.info(format("Stopped %s on port %d", now, serverConnector.getPort())) ; try { server.stop() ; } catch (Exception ex) { Fuseki.serverLog.warn("SPARQLServer: Exception while stopping server: " + ex.getMessage(), ex) ; } }
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 } }
private void createConnector(Properties properties) { final ServerConnector http = new ServerConnector(jetty); http.setPort(Integer.parseInt(properties.getProperty(PORT_KEY, "0"))); http.setHost(properties.getProperty(HOST_KEY, "localhost")); // Severely taxed or distant environments may have significant delays when executing. http.setIdleTimeout(30000L); jetty.addConnector(http); logger.info("Added an http connector on the host '{}' and port '{}'", new Object[]{http.getHost(), http.getPort()}); }
public Object getMonitorValue(String key) { switch (key) { case "port": return connector.getPort(); case "host": return connector.getHost(); case "contextPath": return getContextPath(); } return null; } }
@Test public void testSetPortNoBindAddress() throws Exception { final LogWriterI18n mockLogWriter = mockContext.mock(LogWriterI18n.class, "testSetPortWithBindAddress.LogWriterI18n"); mockContext.checking(new Expectations() {{ allowing(mockLogWriter); }}); final Server jetty = JettyHelper.initJetty(null, 8090, mockLogWriter); assertNotNull(jetty); assertNotNull(jetty.getConnectors()[0]); assertEquals(8090, ((ServerConnector) jetty.getConnectors()[0]).getPort()); }