connector.setName("httpd:" + httpPort); connector.setIdleTimeout(20000); // timout in ms when no bytes send / received connector.start(); LoklakServer.server.addConnector(connector);
@Bean public JettyCustomizer jettyCustomizer(EmbeddedWebApplicationContext context) { return new JettyCustomizer( (JettyEmbeddedServletContainer) context.getEmbeddedServletContainer()); } static class JettyCustomizer implements ApplicationListener<ApplicationReadyEvent> { private final JettyEmbeddedServletContainer container; JettyCustomizer(JettyEmbeddedServletContainer container) { this.container = container; } @Override public void onApplicationEvent(ApplicationReadyEvent event) { Server server = this.container.getServer(); ServerConnector connector = new ServerConnector(server); connector.setPort(8081); server.addConnector(connector); try { connector.start(); } catch (Exception ex) { throw new IllegalStateException("Failed to start connector", ex); } } }
@Override public int bindPort(int port) { try { ServerConnector http = new ServerConnector(server); http.setHost("0.0.0.0"); http.setPort(port); http.setIdleTimeout(30000); server.addConnector(http); if (server.isStarted()) { http.start(); } return http.getLocalPort(); } catch (Exception e) { throw new RuntimeException(e); } }
public void resume() { if (httpConnector != null && httpConnector.isStopped()) { try { httpConnector.start(); } catch (Exception e) { monitor.exception("Error resuming HTTP connector", e); } } if (sslConnector != null && sslConnector.isStopped()) { try { sslConnector.start(); } catch (Exception e) { monitor.exception("Error resuming SSL connector", e); } } }
public void resume() { if (httpConnector != null && httpConnector.isStopped()) { try { httpConnector.start(); } catch (Exception e) { monitor.exception("Error resuming HTTP connector", e); } } if (sslConnector != null && sslConnector.isStopped()) { try { sslConnector.start(); } catch (Exception e) { monitor.exception("Error resuming SSL connector", e); } } }
/** Create a port based connector. * This methods adds a port connector to the server * @return A URL to access the server via the connector. * @throws Exception */ public String createConnector(boolean localhost) throws Exception { ServerConnector connector = new ServerConnector(_server); if (localhost) connector.setHost("127.0.0.1"); _server.addConnector(connector); if (_server.isStarted()) connector.start(); else connector.open(); return "http://"+(localhost?"127.0.0.1": InetAddress.getLocalHost().getHostAddress() )+":"+connector.getLocalPort(); }
Server server = new Server(); HttpConfiguration http_config = new HttpConfiguration(); http_config.setSecureScheme("https"); http_config.setSecurePort(8443); http_config.setOutputBufferSize(32768); HttpConfiguration https_config = new HttpConfiguration(); https_config.addCustomizer(new SecureRequestCustomizer()); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config)); http.setPort(8080); http.setIdleTimeout(30000); SslContextFactory contextFactory = new SslContextFactory(); contextFactory.setKeyStorePath("keystore.jks"); contextFactory.setKeyStorePassword("changeit"); SslConnectionFactory connectionFactory = new SslConnectionFactory(contextFactory, org.eclipse.jetty.http.HttpVersion.HTTP_1_1.toString()); ServerConnector https = new ServerConnector(server, connectionFactory, new HttpConnectionFactory(https_config)); https.setPort(8443); https.setIdleTimeout(50000); server.setConnectors(new Connector[]{http, https}); ServletContextHandler servletCH = new ServletContextHandler(); servletCH.setContextPath("/"); servletCH.addServlet(ScheduleWebSocketServlet.class, "/schedule"); server.setHandler(servletCH); server.start(); http.start(); https.start(); server.join();
/** Create a port based connector. * This methods adds a port connector to the server * @return A URL to access the server via the connector. * @throws Exception */ public String createConnector(boolean localhost) throws Exception { ServerConnector connector = new ServerConnector(_server); if (localhost) connector.setHost("127.0.0.1"); _server.addConnector(connector); if (_server.isStarted()) connector.start(); else connector.open(); return "http://"+(localhost?"127.0.0.1": InetAddress.getLocalHost().getHostAddress() )+":"+connector.getLocalPort(); }
/** Create a port based connector. * This methods adds a port connector to the server * @return A URL to access the server via the connector. * @throws Exception */ public String createConnector(boolean localhost) throws Exception { ServerConnector connector = new ServerConnector(_server); if (localhost) connector.setHost("127.0.0.1"); _server.addConnector(connector); if (_server.isStarted()) connector.start(); else connector.open(); return "http://"+(localhost?"127.0.0.1": InetAddress.getLocalHost().getHostAddress() )+":"+connector.getLocalPort(); }
@Override public void childAdded(final ConfiguredObject<?> object, final ConfiguredObject<?> child) { if (child instanceof HttpPort) { final HttpPort<?> port = (HttpPort<?>) child; Server server = _server; if (server != null) { ServerConnector connector = null; try { connector = createConnector(port, server); connector.addBean(new ConnectionTrackingListener()); server.addConnector(connector); connector.start(); _portConnectorMap.put(port, connector); logOperationalListenMessages(port, connector.getLocalPort()); } catch (Exception e) { if (connector != null) { server.removeConnector(connector); } LOGGER.warn("HTTP management connector creation failed for http port {}", port, e); } } } }
protected void replaceConnector(ServerConnector newConnector, Server jetty) { // get current connector and shut him down jettyServerConnector.shutdown(); try { jettyServerConnector.stop(); } catch (Exception e) { throw new ClientDriverInternalException("Error shutting down jetty connector during replacement", e); } jetty.removeConnector(jettyServerConnector); // add new and start him up jetty.addConnector(newConnector); try { newConnector.start(); } catch (Exception e) { throw new ClientDriverInternalException("Error starting new jetty connector during replacement", e); } }
protected void replaceConnector(ServerConnector newConnector, Server jetty) { // get current connector and shut him down jettyServerConnector.shutdown(); try { jettyServerConnector.stop(); } catch (Exception e) { throw new ClientDriverInternalException("Error shutting down jetty connector during replacement", e); } jetty.removeConnector(jettyServerConnector); // add new and start him up jetty.addConnector(newConnector); try { newConnector.start(); } catch (Exception e) { throw new ClientDriverInternalException("Error starting new jetty connector during replacement", e); } }
server.addConnector(serverConnector); try { serverConnector.start();
server.addConnector(serverConnector); try { serverConnector.start();