use of org.eclipse.jetty.server.ServerConnector in project spark by perwendel.
the class EmbeddedJettyServer method ignite.
/**
* {@inheritDoc}
*/
@Override
public int ignite(String host, int port, SslStores sslStores, int maxThreads, int minThreads, int threadIdleTimeoutMillis) {
if (port == 0) {
try (ServerSocket s = new ServerSocket(0)) {
port = s.getLocalPort();
} catch (IOException e) {
logger.error("Could not get first available port (port set to 0), using default: {}", SPARK_DEFAULT_PORT);
port = SPARK_DEFAULT_PORT;
}
}
server = JettyServer.create(maxThreads, minThreads, threadIdleTimeoutMillis);
ServerConnector connector;
if (sslStores == null) {
connector = SocketConnectorFactory.createSocketConnector(server, host, port);
} else {
connector = SocketConnectorFactory.createSecureSocketConnector(server, host, port, sslStores);
}
server = connector.getServer();
server.setConnectors(new Connector[] { connector });
ServletContextHandler webSocketServletContextHandler = WebSocketServletContextHandlerFactory.create(webSocketHandlers, webSocketIdleTimeoutMillis);
// Handle web socket routes
if (webSocketServletContextHandler == null) {
server.setHandler(handler);
} else {
List<Handler> handlersInList = new ArrayList<>();
handlersInList.add(handler);
// WebSocket handler must be the last one
if (webSocketServletContextHandler != null) {
handlersInList.add(webSocketServletContextHandler);
}
HandlerList handlers = new HandlerList();
handlers.setHandlers(handlersInList.toArray(new Handler[handlersInList.size()]));
server.setHandler(handlers);
}
try {
logger.info("== {} has ignited ...", NAME);
logger.info(">> Listening on {}:{}", host, port);
server.start();
} catch (Exception e) {
logger.error("ignite failed", e);
System.exit(100);
}
return port;
}
use of org.eclipse.jetty.server.ServerConnector in project spark by perwendel.
the class SocketConnectorFactoryTest method testCreateSocketConnector.
@Test
public void testCreateSocketConnector() {
final String host = "localhost";
final int port = 8888;
Server server = new Server();
ServerConnector serverConnector = SocketConnectorFactory.createSocketConnector(server, "localhost", 8888);
String internalHost = Whitebox.getInternalState(serverConnector, "_host");
int internalPort = Whitebox.getInternalState(serverConnector, "_port");
Server internalServerConnector = Whitebox.getInternalState(serverConnector, "_server");
assertEquals("Server Connector Host should be set to the specified server", host, internalHost);
assertEquals("Server Connector Port should be set to the specified port", port, internalPort);
assertEquals("Server Connector Server should be set to the specified server", internalServerConnector, server);
}
use of org.eclipse.jetty.server.ServerConnector in project spark by perwendel.
the class ServletTest method setup.
@BeforeClass
public static void setup() throws InterruptedException {
testUtil = new SparkTestUtil(PORT);
final Server server = new Server();
ServerConnector connector = new ServerConnector(server);
// Set some timeout options to make debugging easier.
connector.setIdleTimeout(1000 * 60 * 60);
connector.setSoLingerTime(-1);
connector.setPort(PORT);
server.setConnectors(new Connector[] { connector });
WebAppContext bb = new WebAppContext();
bb.setServer(server);
bb.setContextPath(SOMEPATH);
bb.setWar("src/test/webapp");
server.setHandler(bb);
CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable() {
@Override
public void run() {
try {
LOGGER.info(">>> STARTING EMBEDDED JETTY SERVER for jUnit testing of SparkFilter");
server.start();
latch.countDown();
System.in.read();
LOGGER.info(">>> STOPPING EMBEDDED JETTY SERVER");
server.stop();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(100);
}
}
}).start();
latch.await();
}
use of org.eclipse.jetty.server.ServerConnector in project spring-boot by spring-projects.
the class JettyServletWebServerFactoryTests method sslEnabledProtocolsConfiguration.
@Test
public void sslEnabledProtocolsConfiguration() throws Exception {
Ssl ssl = new Ssl();
ssl.setKeyStore("src/test/resources/test.jks");
ssl.setKeyStorePassword("secret");
ssl.setKeyPassword("password");
ssl.setCiphers(new String[] { "ALPHA", "BRAVO", "CHARLIE" });
ssl.setEnabledProtocols(new String[] { "TLSv1.1" });
JettyServletWebServerFactory factory = getFactory();
factory.setSsl(ssl);
this.webServer = factory.getWebServer();
this.webServer.start();
JettyWebServer jettyWebServer = (JettyWebServer) this.webServer;
ServerConnector connector = (ServerConnector) jettyWebServer.getServer().getConnectors()[0];
SslConnectionFactory connectionFactory = connector.getConnectionFactory(SslConnectionFactory.class);
assertThat(connectionFactory.getSslContextFactory().getIncludeProtocols()).isEqualTo(new String[] { "TLSv1.1" });
}
use of org.eclipse.jetty.server.ServerConnector in project spring-framework by spring-projects.
the class JettyHttpServer method initServer.
@Override
protected void initServer() throws Exception {
this.jettyServer = new Server();
ServletHttpHandlerAdapter servlet = createServletAdapter();
ServletHolder servletHolder = new ServletHolder(servlet);
this.contextHandler = new ServletContextHandler(this.jettyServer, "", false, false);
this.contextHandler.addServlet(servletHolder, "/");
this.contextHandler.start();
ServerConnector connector = new ServerConnector(this.jettyServer);
connector.setHost(getHost());
connector.setPort(getPort());
this.jettyServer.addConnector(connector);
}
Aggregations