/** * The port the HTTP server is listening on. Not available until {@link #start() } has run. * @return The port the HTTP server is listening on. Not available until {@link #start() } has run. */ public int getHttpServerPort() { assert httpServer.getConnectors().length == 1; return ((ServerConnector) (httpServer.getConnectors()[0])).getLocalPort(); }
/** * Return the local port of the first {@link ServerConnector} in the * provided {@link Server} instance. * * @param server Server instance to use * @return First local port of the server instance */ default int getLocalPort(Server server) { return ((ServerConnector) server.getConnectors()[0]).getLocalPort(); }
/** * Return the local port of the last {@link ServerConnector} in the * provided {@link Server} instance. This may be the same value as returned * by {@link #getLocalPort(Server)} if using the "simple" server configuration. * * @param server Server instance to use * @return Last local port or the server instance */ default int getAdminPort(Server server) { final Connector[] connectors = server.getConnectors(); return ((ServerConnector) connectors[connectors.length - 1]).getLocalPort(); } }
public int getAdminPort() { final Connector[] connectors = requireNonNull(jettyServer).getConnectors(); return ((ServerConnector) connectors[connectors.length - 1]).getLocalPort(); }
public int getLocalPort() { return ((ServerConnector) requireNonNull(jettyServer).getConnectors()[0]).getLocalPort(); }
public int getPort(int connectorIndex) { return ((ServerConnector) requireNonNull(jettyServer).getConnectors()[connectorIndex]).getLocalPort(); }
/** * Shuts down the web server. */ public void stop() throws Exception { // close all connectors and release all binding ports for (Connector connector : mServer.getConnectors()) { connector.stop(); } mServer.stop(); }
/** * Get the port that the server is on * @return the port */ @Deprecated public int getPort() { return ((ServerConnector)webServer.getConnectors()[0]).getLocalPort(); }
public int getPort() { return ((ServerConnector)(webServer.getConnectors()[0])).getLocalPort(); }
public int getPort() { return ((ServerConnector) this.server.getConnectors()[0]).getLocalPort(); } }
@Override protected void startInternal() throws Exception { this.jettyServer.start(); setPort(((ServerConnector) this.jettyServer.getConnectors()[0]).getLocalPort()); }
@Override public void start() throws Exception { this.jettyServer.start(); this.contextHandler.start(); Connector[] connectors = jettyServer.getConnectors(); NetworkConnector connector = (NetworkConnector) connectors[0]; this.port = connector.getLocalPort(); }
private int getLocalPort( Server server ) { return ((ServerConnector) (server.getConnectors()[0])).getLocalPort(); }
private List<SocketConnector> getSocketConnectors( WebServer wServer ) { List<SocketConnector> sConnectors = new ArrayList<SocketConnector>(); Connector[] connectors = wServer.getServer().getConnectors(); for ( Connector cn : connectors ) { if ( cn instanceof SocketConnector ) { sConnectors.add( (SocketConnector) cn ); } } return sConnectors; }
public String getServerAddress() { if (server == null) { throw new IllegalStateException("Not started"); } final int localPort = ((NetworkTrafficServerConnector) server.getConnectors()[0]) .getLocalPort(); return "http://localhost:"+ localPort; }
@BeforeClass public static void startJettyServer() throws Exception { // Let server pick its own random, available port. jettyServer = new Server(0); ServletContextHandler handler = new ServletContextHandler(); MultipartConfigElement multipartConfig = new MultipartConfigElement(""); ServletHolder holder = new ServletHolder(partsServlet); holder.getRegistration().setMultipartConfig(multipartConfig); handler.addServlet(holder, "/parts"); holder = new ServletHolder(partListServlet); holder.getRegistration().setMultipartConfig(multipartConfig); handler.addServlet(holder, "/partlist"); jettyServer.setHandler(handler); jettyServer.start(); Connector[] connectors = jettyServer.getConnectors(); NetworkConnector connector = (NetworkConnector) connectors[0]; baseUrl = "http://localhost:" + connector.getLocalPort(); }
@BeforeClass public static void startServer() throws Exception { // Let server pick its own random, available port. server = new Server(0); ServletContextHandler handler = new ServletContextHandler(); handler.setContextPath("/"); Class<?> config = CommonsMultipartResolverTestConfig.class; ServletHolder commonsResolverServlet = new ServletHolder(DispatcherServlet.class); commonsResolverServlet.setInitParameter("contextConfigLocation", config.getName()); commonsResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName()); handler.addServlet(commonsResolverServlet, "/commons-resolver/*"); config = StandardMultipartResolverTestConfig.class; ServletHolder standardResolverServlet = new ServletHolder(DispatcherServlet.class); standardResolverServlet.setInitParameter("contextConfigLocation", config.getName()); standardResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName()); standardResolverServlet.getRegistration().setMultipartConfig(new MultipartConfigElement("")); handler.addServlet(standardResolverServlet, "/standard-resolver/*"); server.setHandler(handler); server.start(); Connector[] connectors = server.getConnectors(); NetworkConnector connector = (NetworkConnector) connectors[0]; baseUrl = "http://localhost:" + connector.getLocalPort(); }
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()); } }
@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); }
@Signature public Memory connectors() { Connector[] connectors = server.getConnectors(); ArrayMemory arrayMemory = ArrayMemory.createListed(connectors.length); for (Connector connector : connectors) { arrayMemory.add(connector.getName()); } return arrayMemory.toImmutable(); }