Java Code Examples for org.eclipse.jetty.server.ServerConnector#getPort()
The following examples show how to use
org.eclipse.jetty.server.ServerConnector#getPort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpServer2.java From hadoop-ozone with Apache License 2.0 | 6 votes |
/** * 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); } } }
Example 2
Source File: HttpServer2.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Open the main listener for the server * @throws Exception exception opening listener */ 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); } } }
Example 3
Source File: HttpServer2.java From knox with Apache License 2.0 | 6 votes |
/** * Open the main listener for the server * @throws Exception exception opening listener */ 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); } } }
Example 4
Source File: HttpServer2.java From knox with Apache License 2.0 | 6 votes |
/** * Open the main listener for the server * @throws Exception exception opening listener */ 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); } } }
Example 5
Source File: HttpServer2.java From hadoop-ozone with Apache License 2.0 | 5 votes |
/** * Create bind exception by wrapping the bind exception thrown. * @param listener * @param ex * @return */ private static BindException constructBindException(ServerConnector listener, IOException ex) { BindException be = new BindException("Port in use: " + listener.getHost() + ":" + listener.getPort()); if (ex != null) { be.initCause(ex); } return be; }
Example 6
Source File: HttpServer2.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Create bind exception by wrapping the bind exception thrown. * @param listener listener to check * @param ex exception to check * @return returns the exception */ 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; }
Example 7
Source File: HttpServer.java From hbase with Apache License 2.0 | 5 votes |
/** * Open the main listener for the server * @throws Exception if the listener cannot be opened or the appropriate port is already in use */ @VisibleForTesting void openListeners() throws Exception { for (ListenerInfo li : listeners) { ServerConnector listener = li.listener; if (!li.isManaged || (li.listener.getLocalPort() != -1 && li.listener.getLocalPort() != -2)) { // This listener is either started externally, or has not been opened, or has been closed continue; } int port = listener.getPort(); while (true) { // jetty has a bug where you can't reopen a listener that previously // failed to open w/o issuing a close first, even if the port is changed try { listener.close(); listener.open(); LOG.info("Jetty bound to port " + listener.getLocalPort()); break; } catch (IOException ex) { if(!(ex instanceof BindException) && !(ex.getCause() instanceof BindException)) { throw ex; } if (port == 0 || !findPort) { BindException be = new BindException("Port in use: " + listener.getHost() + ":" + listener.getPort()); be.initCause(ex); throw be; } } // try the next port number listener.setPort(++port); Thread.sleep(100); } } }
Example 8
Source File: HttpServer2.java From knox with Apache License 2.0 | 5 votes |
/** * Create bind exception by wrapping the bind exception thrown. * @param listener listener to check * @param ex exception to check * @return returns the exception */ 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; }
Example 9
Source File: HttpServer2.java From knox with Apache License 2.0 | 5 votes |
/** * Create bind exception by wrapping the bind exception thrown. * @param listener listener to check * @param ex exception to check * @return returns the exception */ 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; }
Example 10
Source File: JettyHTTPServerEngine.java From cxf with Apache License 2.0 | 5 votes |
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 } }
Example 11
Source File: JettyServer.java From localization_nifi with Apache License 2.0 | 4 votes |
private void dumpUrls() throws SocketException { final List<String> urls = new ArrayList<>(); for (Connector connector : server.getConnectors()) { if (connector instanceof ServerConnector) { final ServerConnector serverConnector = (ServerConnector) connector; Set<String> hosts = new HashSet<>(); // determine the hosts if (StringUtils.isNotBlank(serverConnector.getHost())) { hosts.add(serverConnector.getHost()); } else { Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); if (networkInterfaces != null) { for (NetworkInterface networkInterface : Collections.list(networkInterfaces)) { for (InetAddress inetAddress : Collections.list(networkInterface.getInetAddresses())) { hosts.add(inetAddress.getHostAddress()); } } } } // ensure some hosts were found if (!hosts.isEmpty()) { String scheme = "http"; if (props.getSslPort() != null && serverConnector.getPort() == props.getSslPort()) { scheme = "https"; } // dump each url for (String host : hosts) { urls.add(String.format("%s://%s:%s", scheme, host, serverConnector.getPort())); } } } } if (urls.isEmpty()) { logger.warn("NiFi has started, but the UI is not available on any hosts. Please verify the host properties."); } else { // log the ui location logger.info("NiFi has started. The UI is available at the following URLs:"); for (final String url : urls) { logger.info(String.format("%s/nifi", url)); } } }
Example 12
Source File: JettyServer.java From nifi-registry with Apache License 2.0 | 4 votes |
private void dumpUrls() throws SocketException { final List<String> urls = new ArrayList<>(); for (Connector connector : server.getConnectors()) { if (connector instanceof ServerConnector) { final ServerConnector serverConnector = (ServerConnector) connector; Set<String> hosts = new HashSet<>(); // determine the hosts if (StringUtils.isNotBlank(serverConnector.getHost())) { hosts.add(serverConnector.getHost()); } else { Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); if (networkInterfaces != null) { for (NetworkInterface networkInterface : Collections.list(networkInterfaces)) { for (InetAddress inetAddress : Collections.list(networkInterface.getInetAddresses())) { hosts.add(inetAddress.getHostAddress()); } } } } // ensure some hosts were found if (!hosts.isEmpty()) { String scheme = "http"; if (properties.getSslPort() != null && serverConnector.getPort() == properties.getSslPort()) { scheme = "https"; } // dump each url for (String host : hosts) { urls.add(String.format("%s://%s:%s", scheme, host, serverConnector.getPort())); } } } } if (urls.isEmpty()) { logger.warn("NiFi Registry has started, but the UI is not available on any hosts. Please verify the host properties."); } else { // log the ui location logger.info("NiFi Registry has started. The UI is available at the following URLs:"); for (final String url : urls) { logger.info(String.format("%s/nifi-registry", url)); } } }
Example 13
Source File: JettyServer.java From nifi with Apache License 2.0 | 4 votes |
private void dumpUrls() throws SocketException { final List<String> urls = new ArrayList<>(); for (Connector connector : server.getConnectors()) { if (connector instanceof ServerConnector) { final ServerConnector serverConnector = (ServerConnector) connector; Set<String> hosts = new HashSet<>(); // determine the hosts if (StringUtils.isNotBlank(serverConnector.getHost())) { hosts.add(serverConnector.getHost()); } else { Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); if (networkInterfaces != null) { for (NetworkInterface networkInterface : Collections.list(networkInterfaces)) { for (InetAddress inetAddress : Collections.list(networkInterface.getInetAddresses())) { hosts.add(inetAddress.getHostAddress()); } } } } // ensure some hosts were found if (!hosts.isEmpty()) { String scheme = "http"; if (props.getSslPort() != null && serverConnector.getPort() == props.getSslPort()) { scheme = "https"; } // dump each url for (String host : hosts) { urls.add(String.format("%s://%s:%s", scheme, host, serverConnector.getPort())); } } } } if (urls.isEmpty()) { logger.warn("NiFi has started, but the UI is not available on any hosts. Please verify the host properties."); } else { // log the ui location logger.info("NiFi has started. The UI is available at the following URLs:"); for (final String url : urls) { logger.info(String.format("%s/nifi", url)); } } }