use of org.eclipse.jetty.server.Handler in project airpal by airbnb.
the class AirpalApplicationBase method run.
@Override
public void run(T config, Environment environment) throws Exception {
this.injector = Guice.createInjector(Stage.PRODUCTION, getModules(config, environment));
System.setProperty(IO_BUFFER_SIZE, String.valueOf(config.getBufferSize().toBytes()));
environment.healthChecks().register("presto", injector.getInstance(PrestoHealthCheck.class));
environment.jersey().register(injector.getInstance(ExecuteResource.class));
environment.jersey().register(injector.getInstance(QueryResource.class));
environment.jersey().register(injector.getInstance(QueriesResource.class));
environment.jersey().register(injector.getInstance(UserResource.class));
environment.jersey().register(injector.getInstance(UsersResource.class));
environment.jersey().register(injector.getInstance(TablesResource.class));
environment.jersey().register(injector.getInstance(HealthResource.class));
environment.jersey().register(injector.getInstance(PingResource.class));
environment.jersey().register(injector.getInstance(SessionResource.class));
environment.jersey().register(injector.getInstance(FilesResource.class));
environment.jersey().register(injector.getInstance(ResultsPreviewResource.class));
environment.jersey().register(injector.getInstance(S3FilesResource.class));
environment.jersey().register(injector.getInstance(AirpalUserFactory.class));
// Setup SSE (Server Sent Events)
ServletRegistration.Dynamic sseServlet = environment.servlets().addServlet("updates", injector.getInstance(SSEEventSourceServlet.class));
sseServlet.setAsyncSupported(true);
sseServlet.addMapping("/api/updates/subscribe");
// Disable GZIP content encoding for SSE endpoints
environment.lifecycle().addServerLifecycleListener(server -> {
for (Handler handler : server.getChildHandlersByClass(BiDiGzipHandler.class)) {
((BiDiGzipHandler) handler).addExcludedMimeTypes(SERVER_SENT_EVENTS);
}
});
}
use of org.eclipse.jetty.server.Handler 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.Handler in project spring-boot by spring-projects.
the class JettyServletWebServerFactoryTests method assertTimeout.
private void assertTimeout(JettyServletWebServerFactory factory, int expected) {
this.webServer = factory.getWebServer();
JettyWebServer jettyWebServer = (JettyWebServer) this.webServer;
Handler[] handlers = jettyWebServer.getServer().getChildHandlersByClass(WebAppContext.class);
WebAppContext webAppContext = (WebAppContext) handlers[0];
int actual = webAppContext.getSessionHandler().getMaxInactiveInterval();
assertThat(actual).isEqualTo(expected);
}
use of org.eclipse.jetty.server.Handler in project spring-boot by spring-projects.
the class JettyServletWebServerFactoryTests method wrappedHandlers.
@Test
public void wrappedHandlers() throws Exception {
JettyServletWebServerFactory factory = getFactory();
factory.setServerCustomizers(Arrays.asList(new JettyServerCustomizer() {
@Override
public void customize(Server server) {
Handler handler = server.getHandler();
HandlerWrapper wrapper = new HandlerWrapper();
wrapper.setHandler(handler);
HandlerCollection collection = new HandlerCollection();
collection.addHandler(wrapper);
server.setHandler(collection);
}
}));
this.webServer = factory.getWebServer(exampleServletRegistration());
this.webServer.start();
assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
}
use of org.eclipse.jetty.server.Handler in project otter by alibaba.
the class JettyEmbedServer method start.
public void start() throws Exception {
Resource configXml = Resource.newSystemResource(config);
XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
server = (Server) configuration.configure();
// Integer port = getPort();
// if (port != null && port > 0) {
// Connector[] connectors = server.getConnectors();
// for (Connector connector : connectors) {
// connector.setPort(port);
// }
// }
Handler handler = server.getHandler();
if (handler != null && handler instanceof WebAppContext) {
WebAppContext webAppContext = (WebAppContext) handler;
webAppContext.setResourceBase(JettyEmbedServer.class.getResource("/webapp").toString());
}
server.start();
if (logger.isInfoEnabled()) {
logger.info("##Jetty Embed Server is startup!");
}
}
Aggregations