Java Code Examples for org.eclipse.jetty.server.ServerConnector#setIdleTimeout()
The following examples show how to use
org.eclipse.jetty.server.ServerConnector#setIdleTimeout() .
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: WebServer.java From hop with Apache License 2.0 | 6 votes |
/** * Set up jetty options to the connector * * @param connector */ protected void setupJettyOptions( ServerConnector connector ) { LowResourceMonitor lowResourceMonitor = new LowResourceMonitor( server ); if ( validProperty( Const.HOP_SERVER_JETTY_ACCEPTORS ) ) { server.addBean( new ConnectionLimit( Integer.parseInt( System.getProperty( Const.HOP_SERVER_JETTY_ACCEPTORS ) ) ) ); log.logBasic( BaseMessages.getString( PKG, "WebServer.Log.ConfigOptions", "acceptors", connector.getAcceptors() ) ); } if ( validProperty( Const.HOP_SERVER_JETTY_ACCEPT_QUEUE_SIZE ) ) { connector .setAcceptQueueSize( Integer.parseInt( System.getProperty( Const.HOP_SERVER_JETTY_ACCEPT_QUEUE_SIZE ) ) ); log.logBasic( BaseMessages .getString( PKG, "WebServer.Log.ConfigOptions", "acceptQueueSize", connector.getAcceptQueueSize() ) ); } if ( validProperty( Const.HOP_SERVER_JETTY_RES_MAX_IDLE_TIME ) ) { connector.setIdleTimeout( Integer.parseInt( System.getProperty( Const.HOP_SERVER_JETTY_RES_MAX_IDLE_TIME ) ) ); log.logBasic( BaseMessages.getString( PKG, "WebServer.Log.ConfigOptions", "lowResourcesMaxIdleTime", connector.getIdleTimeout() ) ); } }
Example 2
Source File: JettyHttpTestServer.java From parsec-libraries with Apache License 2.0 | 6 votes |
public JettyHttpTestServer(String host, int port){ this.host = host; this.port = port; server = new Server(); ServerConnector http = new ServerConnector(server); http.setHost(host); http.setPort(port); http.setIdleTimeout(30000); server.addConnector(http); server.setHandler(new RequestHandler()); try { server.start(); } catch (Exception e) { e.printStackTrace(); } this.port = http.getLocalPort(); }
Example 3
Source File: JettyConfigurationHelper.java From attic-polygene-java with Apache License 2.0 | 6 votes |
static void configureConnector( ServerConnector connector, JettyConfiguration config ) { // Host and Port connector.setHost( config.hostName().get() ); Integer port = config.port().get(); if( port == null ) { port = DEFAULT_PORT; } connector.setPort( port ); // Max idle times Integer maxIdleTime = config.maxIdleTime().get(); if( maxIdleTime != null ) { connector.setIdleTimeout( maxIdleTime ); } }
Example 4
Source File: ExampleKeePassHttpServer.java From KeePassJava2 with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Server server = new Server(); ServerConnector http = new ServerConnector(server); http.setHost("127.0.0.1"); http.setPort(19455); http.setIdleTimeout(300000); server.addConnector(http); KdbxCreds creds = new KdbxCreds("123".getBytes()); // create a database if we don't have one already if (Files.notExists(Paths.get(DEFAULT_DB_FILE))) { SimpleDatabase db = new SimpleDatabase(); db.setName("HTTP Database"); db.save(creds,new FileOutputStream(DEFAULT_DB_FILE)); } DatabaseAdaptor adaptor = new DatabaseAdaptor.Default(new File(DEFAULT_DB_FILE), creds, new HexPwGenerator(10)); server.setHandler(new KeePassHttpHandler(adaptor)); server.start(); server.join(); }
Example 5
Source File: TestServer.java From nifi with Apache License 2.0 | 5 votes |
/** * Creates the http connection */ private void createConnector() { final ServerConnector http = new ServerConnector(jetty); http.setPort(0); // Severely taxed environments may have significant delays when executing. http.setIdleTimeout(30000L); jetty.addConnector(http); }
Example 6
Source File: PullHttpChangeIngestorSSLTest.java From nifi-minifi with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { PullHttpChangeIngestorCommonTest.init(); SslContextFactory.Server ssl = new SslContextFactory.Server(); ssl.setKeyStorePath("./src/test/resources/localhost-ks.jks"); ssl.setKeyStorePassword("localtest"); ssl.setKeyStoreType("JKS"); ssl.setTrustStorePath("./src/test/resources/localhost-ts.jks"); ssl.setTrustStorePassword("localtest"); ssl.setTrustStoreType("JKS"); ssl.setNeedClientAuth(true); // build the connector final ServerConnector https = new ServerConnector(jetty, ssl); // set host and port https.setPort(0); https.setHost("localhost"); // Severely taxed environments may have significant delays when executing. https.setIdleTimeout(30000L); // add the connector jetty.addConnector(https); jetty.start(); Thread.sleep(1000); if (!jetty.isStarted()) { throw new IllegalStateException("Jetty server not started"); } }
Example 7
Source File: TestServer.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
/** * Starts the server and returns a {@link CompletableFuture}. The {@link CompletableFuture} gets completed as soon * as the server is ready to accept connections. * * @return a {@link CompletableFuture} which completes as soon as the server is ready to accept connections. */ public CompletableFuture<Boolean> startServer() { final CompletableFuture<Boolean> serverStarted = new CompletableFuture<>(); Thread thread = new Thread(new Runnable() { @Override public void run() { server = new Server(); ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(servletHolder, "/*"); server.setHandler(handler); // HTTP connector ServerConnector http = new ServerConnector(server); http.setHost(host); http.setPort(port); http.setIdleTimeout(timeout); server.addConnector(http); try { server.start(); serverStarted.complete(true); server.join(); } catch (InterruptedException ex) { logger.error("Server got interrupted", ex); serverStarted.completeExceptionally(ex); return; } catch (Exception e) { logger.error("Error in starting the server", e); serverStarted.completeExceptionally(e); return; } } }); thread.start(); return serverStarted; }
Example 8
Source File: RestChangeIngestor.java From nifi-minifi with Apache License 2.0 | 5 votes |
private void createSecureConnector(Properties properties) { SslContextFactory ssl = new SslContextFactory(); if (properties.getProperty(KEYSTORE_LOCATION_KEY) != null) { ssl.setKeyStorePath(properties.getProperty(KEYSTORE_LOCATION_KEY)); ssl.setKeyStorePassword(properties.getProperty(KEYSTORE_PASSWORD_KEY)); ssl.setKeyStoreType(properties.getProperty(KEYSTORE_TYPE_KEY)); } if (properties.getProperty(TRUSTSTORE_LOCATION_KEY) != null) { ssl.setTrustStorePath(properties.getProperty(TRUSTSTORE_LOCATION_KEY)); ssl.setTrustStorePassword(properties.getProperty(TRUSTSTORE_PASSWORD_KEY)); ssl.setTrustStoreType(properties.getProperty(TRUSTSTORE_TYPE_KEY)); ssl.setNeedClientAuth(Boolean.parseBoolean(properties.getProperty(NEED_CLIENT_AUTH_KEY, "true"))); } // build the connector final ServerConnector https = new ServerConnector(jetty, ssl); // set host and port https.setPort(Integer.parseInt(properties.getProperty(PORT_KEY, "0"))); https.setHost(properties.getProperty(HOST_KEY, "localhost")); // Severely taxed environments may have significant delays when executing. https.setIdleTimeout(30000L); // add the connector jetty.addConnector(https); logger.info("Added an https connector on the host '{}' and port '{}'", new Object[]{https.getHost(), https.getPort()}); }
Example 9
Source File: StreamingReceiver.java From kylin with Apache License 2.0 | 5 votes |
private void createAndConfigHttpServer(KylinConfig kylinConfig) { httpServer = new Server(createThreadPool(kylinConfig)); ServerConnector httpConnector = getHttpConnector(); httpConnector.setPort(getHttpPort()); httpConnector.setIdleTimeout(30000); httpServer.addConnector(httpConnector); }
Example 10
Source File: SSLUtils.java From warp10-platform with Apache License 2.0 | 5 votes |
public static ServerConnector getConnector(Server server, String prefix) { int sslAcceptors = Integer.parseInt(WarpConfig.getProperty(prefix + Configuration._SSL_ACCEPTORS, DEFAULT_SSL_ACCEPTORS)); int sslSelectors = Integer.parseInt(WarpConfig.getProperty(prefix + Configuration._SSL_SELECTORS, DEFAULT_SSL_SELECTORS)); int sslPort = Integer.parseInt(WarpConfig.getProperty(prefix + Configuration._SSL_PORT)); String sslHost = WarpConfig.getProperty(prefix + Configuration._SSL_HOST); int sslTcpBacklog = Integer.parseInt(WarpConfig.getProperty(prefix + Configuration._SSL_TCP_BACKLOG, "0")); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(WarpConfig.getProperty(prefix + Configuration._SSL_KEYSTORE_PATH)); sslContextFactory.setCertAlias(WarpConfig.getProperty(prefix + Configuration._SSL_CERT_ALIAS)); if (null != WarpConfig.getProperty(prefix + Configuration._SSL_KEYSTORE_PASSWORD)) { sslContextFactory.setKeyStorePassword(WarpConfig.getProperty(prefix + Configuration._SSL_KEYSTORE_PASSWORD)); } if (null != WarpConfig.getProperty(prefix + Configuration._SSL_KEYMANAGER_PASSWORD)) { sslContextFactory.setKeyManagerPassword(WarpConfig.getProperty(prefix + Configuration._SSL_KEYMANAGER_PASSWORD)); } ServerConnector connector = new ServerConnector(server, sslAcceptors, sslSelectors, sslContextFactory); connector.setPort(sslPort); connector.setAcceptQueueSize(sslTcpBacklog); if (null != sslHost) { connector.setHost(sslHost); } String idle = WarpConfig.getProperty(prefix + Configuration._SSL_IDLE_TIMEOUT); if (null != idle) { connector.setIdleTimeout(Long.parseLong(idle)); } return connector; }
Example 11
Source File: TestServer.java From localization_nifi with Apache License 2.0 | 5 votes |
private void createSecureConnector(final Map<String, String> sslProperties) { SslContextFactory ssl = new SslContextFactory(); if (sslProperties.get(StandardSSLContextService.KEYSTORE.getName()) != null) { ssl.setKeyStorePath(sslProperties.get(StandardSSLContextService.KEYSTORE.getName())); ssl.setKeyStorePassword(sslProperties.get(StandardSSLContextService.KEYSTORE_PASSWORD.getName())); ssl.setKeyStoreType(sslProperties.get(StandardSSLContextService.KEYSTORE_TYPE.getName())); } if (sslProperties.get(StandardSSLContextService.TRUSTSTORE.getName()) != null) { ssl.setTrustStorePath(sslProperties.get(StandardSSLContextService.TRUSTSTORE.getName())); ssl.setTrustStorePassword(sslProperties.get(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName())); ssl.setTrustStoreType(sslProperties.get(StandardSSLContextService.TRUSTSTORE_TYPE.getName())); } final String clientAuth = sslProperties.get(NEED_CLIENT_AUTH); if (clientAuth == null) { ssl.setNeedClientAuth(true); } else { ssl.setNeedClientAuth(Boolean.parseBoolean(clientAuth)); } // build the connector final ServerConnector https = new ServerConnector(jetty, ssl); // set host and port https.setPort(0); // Severely taxed environments may have significant delays when executing. https.setIdleTimeout(30000L); // add the connector jetty.addConnector(https); // mark secure as enabled secure = true; }
Example 12
Source File: TestServer.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Creates the http connection */ private void createConnector() { final ServerConnector http = new ServerConnector(jetty); http.setPort(0); // Severely taxed environments may have significant delays when executing. http.setIdleTimeout(30000L); jetty.addConnector(http); }
Example 13
Source File: ConnectorFactory.java From vespa with Apache License 2.0 | 5 votes |
public ServerConnector createConnector(final Metric metric, final Server server) { ServerConnector connector = new JDiscServerConnector( connectorConfig, metric, server, createConnectionFactories(metric).toArray(ConnectionFactory[]::new)); connector.setPort(connectorConfig.listenPort()); connector.setName(connectorConfig.name()); connector.setAcceptQueueSize(connectorConfig.acceptQueueSize()); connector.setReuseAddress(connectorConfig.reuseAddress()); connector.setIdleTimeout((long)(connectorConfig.idleTimeout() * 1000.0)); return connector; }
Example 14
Source File: JettyServerFactory.java From tutorials with MIT License | 5 votes |
/** * Returns a simple server listening on port 80 with a timeout of 30 seconds * for connections and no handlers. * * @return a server */ public static Server createBaseServer() { Server server = new Server(); // Adds a connector for port 80 with a timeout of 30 seconds. ServerConnector connector = new ServerConnector(server); connector.setPort(SERVER_PORT); connector.setHost("127.0.0.1"); connector.setIdleTimeout(30000); server.addConnector(connector); return server; }
Example 15
Source File: StartSolrJetty.java From lucene-solr with Apache License 2.0 | 5 votes |
public static void main( String[] args ) { //System.setProperty("solr.solr.home", "../../../example/solr"); Server server = new Server(); ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory()); // Set some timeout options to make debugging easier. connector.setIdleTimeout(1000 * 60 * 60); connector.setPort(8983); server.setConnectors(new Connector[] { connector }); WebAppContext bb = new WebAppContext(); bb.setServer(server); bb.setContextPath("/solr"); bb.setWar("webapp/web"); // // START JMX SERVER // if( true ) { // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer); // server.getContainer().addEventListener(mBeanContainer); // mBeanContainer.start(); // } server.setHandler(bb); try { System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP"); server.start(); while (System.in.available() == 0) { Thread.sleep(5000); } server.stop(); server.join(); } catch (Exception e) { e.printStackTrace(); System.exit(100); } }
Example 16
Source File: StreamingReceiver.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
private void createAndConfigHttpServer(KylinConfig kylinConfig) { httpServer = new Server(createThreadPool(kylinConfig)); ServerConnector httpConnector = getHttpConnector(); httpConnector.setPort(getHttpPort()); httpConnector.setIdleTimeout(30000); httpServer.addConnector(httpConnector); }
Example 17
Source File: TestServer.java From smarthome with Eclipse Public License 2.0 | 4 votes |
/** * Starts the server and returns a {@link CompletableFuture}. The {@link CompletableFuture} gets completed as soon * as the server is ready to accept connections. * * @return a {@link CompletableFuture} which completes as soon as the server is ready to accept connections. */ public CompletableFuture<Boolean> startServer() { final CompletableFuture<Boolean> serverStarted = new CompletableFuture<>(); Thread thread = new Thread(new Runnable() { @Override public void run() { server = new Server(); ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(servletHolder, "/*"); server.setHandler(handler); // HTTP connector ServerConnector http = new ServerConnector(server); http.setHost(host); http.setPort(port); http.setIdleTimeout(timeout); server.addConnector(http); try { server.start(); serverStarted.complete(true); server.join(); } catch (InterruptedException ex) { logger.error("Server got interrupted", ex); serverStarted.completeExceptionally(ex); return; } catch (Exception e) { logger.error("Error in starting the server", e); serverStarted.completeExceptionally(e); return; } } }); thread.start(); return serverStarted; }
Example 18
Source File: HttpManagement.java From qpid-broker-j with Apache License 2.0 | 4 votes |
@Override public void childRemoved(final ConfiguredObject<?> object, final ConfiguredObject<?> child) { if (child instanceof HttpPort) { final HttpPort<?> port = (HttpPort<?>) child; Server server = _server; if (server != null) { _sslContextFactoryMap.remove(port); final ServerConnector connector = _portConnectorMap.remove(port); if (connector != null) { final int localPort = connector.getLocalPort(); final ConnectionTrackingListener tracker = connector.getBean(ConnectionTrackingListener.class); // closes the server socket - we will see no new connections arriving connector.close(); // minimise the timeout of endpoints so they close in a timely fashion connector.setIdleTimeout(1); connector.getConnectedEndPoints().forEach(endPoint -> endPoint.setIdleTimeout(1)); LOGGER.debug("Connector has {} connection(s)", tracker.getConnectionCount()); final TaskExecutor taskExecutor = getBroker().getTaskExecutor(); tracker.getAllClosedFuture().addListener(new Runnable() { @Override public void run() { final int connectionCount = tracker.getConnectionCount(); if (connectionCount == 0) { LOGGER.debug("Stopping connector for http port {}", localPort); try { connector.stop(); } catch (Exception e) { LOGGER.warn("Failed to stop connector for http port {}", localPort, e); } finally { logOperationalShutdownMessage(localPort); _server.removeConnector(connector); } } else { LOGGER.debug("Connector still has {} connection(s)", tracker.getConnectionCount()); connector.getConnectedEndPoints().forEach(endPoint -> endPoint.setIdleTimeout(1)); tracker.getAllClosedFuture() .addListener(this, taskExecutor); } } }, taskExecutor); } } } }
Example 19
Source File: TestServer.java From nifi with Apache License 2.0 | 4 votes |
private void createSecureConnector(final Map<String, String> sslProperties) { SslContextFactory ssl = new SslContextFactory(); if (sslProperties.get(StandardSSLContextService.KEYSTORE.getName()) != null) { ssl.setKeyStorePath(sslProperties.get(StandardSSLContextService.KEYSTORE.getName())); ssl.setKeyStorePassword(sslProperties.get(StandardSSLContextService.KEYSTORE_PASSWORD.getName())); ssl.setKeyStoreType(sslProperties.get(StandardSSLContextService.KEYSTORE_TYPE.getName())); } if (sslProperties.get(StandardSSLContextService.TRUSTSTORE.getName()) != null) { ssl.setTrustStorePath(sslProperties.get(StandardSSLContextService.TRUSTSTORE.getName())); ssl.setTrustStorePassword(sslProperties.get(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName())); ssl.setTrustStoreType(sslProperties.get(StandardSSLContextService.TRUSTSTORE_TYPE.getName())); } final String clientAuth = sslProperties.get(NEED_CLIENT_AUTH); if (clientAuth == null) { ssl.setNeedClientAuth(true); } else { ssl.setNeedClientAuth(Boolean.parseBoolean(clientAuth)); } // Need to set SslContextFactory's endpointIdentificationAlgorithm to null; this is a server, // not a client. Server does not need to perform hostname verification on the client. // Previous to Jetty 9.4.15.v20190215, this defaulted to null, and now defaults to "HTTPS". ssl.setEndpointIdentificationAlgorithm(null); // build the connector final ServerConnector https = new ServerConnector(jetty, ssl); // set host and port https.setPort(0); // Severely taxed environments may have significant delays when executing. https.setIdleTimeout(30000L); // add the connector jetty.addConnector(https); // mark secure as enabled secure = true; }
Example 20
Source File: HttpServer.java From calcite-avatica with Apache License 2.0 | 2 votes |
/** * Configures the server connector. * * <p>The default configuration sets a timeout of 1 minute and disables * TCP linger time. * * <p>To change the configuration, override this method in a derived class. * The overriding method must call its super method. * * @param connector connector to be configured * @param port port number handed over in constructor */ protected ServerConnector configureConnector(ServerConnector connector, int port) { connector.setIdleTimeout(60 * 1000); connector.setPort(port); return connector; }