public int getPort(Environment environment) { int defaultPort = 9090; MutableServletContextHandler h = environment.getApplicationContext(); if (h == null) { return defaultPort; } Server s = h.getServer(); if (s == null) { return defaultPort; } Connector[] c = s.getConnectors(); if (c != null && c.length > 0) { AbstractNetworkConnector anc = (AbstractNetworkConnector) c[0]; if (anc != null) { return anc.getLocalPort(); } } return defaultPort; }
/** * Checks {@link org.apache.ignite.IgniteSystemProperties#IGNITE_JETTY_PORT} system property * and overrides default connector port if it present. * Then initializes {@code port} with the found value. * * @param con Jetty connector. */ private void override(AbstractNetworkConnector con) { String host = System.getProperty(IGNITE_JETTY_HOST); if (!F.isEmpty(host)) con.setHost(host); int currPort = con.getPort(); Integer overridePort = Integer.getInteger(IGNITE_JETTY_PORT); if (overridePort != null && overridePort != 0) currPort = overridePort; con.setPort(currPort); port = currPort; }
/** * Returns the socket the WebSocket server is listening on. */ public SocketAddress getWebSocketAddress() { if (httpServer == null) { return null; } else { AbstractNetworkConnector c = (AbstractNetworkConnector)httpServer.getConnectors()[0]; return new InetSocketAddress(c.getHost(), c.getLocalPort()); } }
protected static int getPortFromJetty(Service sparkService) { Service inspectedService = sparkService; try { if (inspectedService == null) { inspectedService = getSparkService(); } EmbeddedJettyServer embeddedJettyServer = getEmbeddedJettyServer(inspectedService); AbstractNetworkConnector connector = getConnector(embeddedJettyServer); return connector.getPort(); } catch (Exception e) { LOGGER.error("Error while reading Jetty server port.", e); } return 0; }
private static AbstractNetworkConnector getConnector(EmbeddedJettyServer embeddedJettyServer) throws NoSuchFieldException, IllegalAccessException { Field serverField = embeddedJettyServer.getClass().getDeclaredField("server"); serverField.setAccessible(true); Server server = (Server) serverField.get(embeddedJettyServer); return (AbstractNetworkConnector) server.getConnectors()[0]; }
/** * Checks that the only connector configured for the current jetty instance * and returns it. * * @return Connector instance. * @throws IgniteCheckedException If no or more than one connectors found. */ private AbstractNetworkConnector getJettyConnector() throws IgniteCheckedException { if (httpSrv.getConnectors().length == 1) { Connector connector = httpSrv.getConnectors()[0]; if (!(connector instanceof AbstractNetworkConnector)) throw new IgniteCheckedException("Error in jetty configuration. Jetty connector should extend " + "AbstractNetworkConnector class." ); return (AbstractNetworkConnector)connector; } else throw new IgniteCheckedException("Error in jetty configuration [connectorsFound=" + httpSrv.getConnectors().length + "connectorsExpected=1]"); }
/** * @return the actual port in use (eg, if it was an ephemeral 0) */ public final int getControllerServerPort() { return ((AbstractNetworkConnector) controllerServer.getConnectors()[0]).getLocalPort(); }
public int getJettyPort() { return ((AbstractNetworkConnector) jettyServer.getConnectors()[0]).getLocalPort(); }
public int getJettyPort(){ return ((AbstractNetworkConnector)jettyServer.getConnectors()[0]).getLocalPort(); }
public int getPort() { return ((AbstractNetworkConnector) environment.getApplicationContext() .getServer() .getConnectors()[0]).getLocalPort(); }