use of org.eclipse.jetty.servlet.FilterHolder in project meteo by pierre.
the class JettyServer method start.
public void start(final Injector injector) throws Exception {
final long startTime = System.currentTimeMillis();
server = new Server();
// Setup JMX
final MBeanContainer mbContainer = new MBeanContainer(mbeanServer);
server.getContainer().addEventListener(mbContainer);
server.addBean(mbContainer);
mbContainer.addBean(Log.getLog());
final Connector connector = new SelectChannelConnector();
connector.setStatsOn(config.isJettyStatsOn());
connector.setHost(config.getLocalIp());
connector.setPort(config.getLocalPort());
server.addConnector(connector);
server.setStopAtShutdown(true);
final ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addEventListener(new GuiceServletContextListener() {
@Override
protected Injector getInjector() {
return injector;
}
});
// Jersey insists on using java.util.logging (JUL)
final EventListener listener = new SetupJULBridge();
context.addEventListener(listener);
// Make sure Guice filter all requests
final FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
// Backend servlet for Guice - never used
final ServletHolder sh = new ServletHolder(DefaultServlet.class);
context.addServlet(sh, "/*");
server.start();
final long secondsToStart = (System.currentTimeMillis() - startTime) / 1000;
log.info(String.format("Jetty server started in %d:%02d", secondsToStart / 60, secondsToStart % 60));
}
use of org.eclipse.jetty.servlet.FilterHolder in project spring-framework by spring-projects.
the class JettyWebSocketTestServer method deployConfig.
@Override
public void deployConfig(WebApplicationContext wac, Filter... filters) {
ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(wac));
this.contextHandler = new ServletContextHandler();
this.contextHandler.addServlet(servletHolder, "/");
for (Filter filter : filters) {
this.contextHandler.addFilter(new FilterHolder(filter), "/*", getDispatcherTypes());
}
this.jettyServer.setHandler(this.contextHandler);
}
use of org.eclipse.jetty.servlet.FilterHolder in project camel by apache.
the class WebsocketComponent method applyCrossOriginFiltering.
private void applyCrossOriginFiltering(WebsocketEndpoint endpoint, ServletContextHandler context) {
if (endpoint.isCrossOriginFilterOn()) {
FilterHolder filterHolder = new FilterHolder();
CrossOriginFilter filter = new CrossOriginFilter();
filterHolder.setFilter(filter);
filterHolder.setInitParameter("allowedOrigins", endpoint.getAllowedOrigins());
context.addFilter(filterHolder, endpoint.getFilterPath(), EnumSet.allOf(DispatcherType.class));
}
}
use of org.eclipse.jetty.servlet.FilterHolder in project graphhopper by graphhopper.
the class GHServer method start.
public void start(Injector injector) throws Exception {
ResourceHandler resHandler = new ResourceHandler();
resHandler.setDirectoriesListed(false);
resHandler.setWelcomeFiles(new String[] { "index.html" });
resHandler.setResourceBase(args.get("jetty.resourcebase", "./web/src/main/webapp"));
server = new Server();
// getSessionHandler and getSecurityHandler should always return null
ServletContextHandler servHandler = new ServletContextHandler(ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
servHandler.setErrorHandler(new GHErrorHandler());
servHandler.setContextPath("/");
servHandler.addServlet(new ServletHolder(new InvalidRequestServlet()), "/*");
FilterHolder guiceFilter = new FilterHolder(injector.getInstance(GuiceFilter.class));
servHandler.addFilter(guiceFilter, "/*", EnumSet.allOf(DispatcherType.class));
ServerConnector connector0 = new ServerConnector(server);
int httpPort = args.getInt("jetty.port", 8989);
String host = args.get("jetty.host", "");
connector0.setPort(httpPort);
int requestHeaderSize = args.getInt("jetty.request_header_size", -1);
if (requestHeaderSize > 0)
connector0.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setRequestHeaderSize(requestHeaderSize);
if (!host.isEmpty())
connector0.setHost(host);
server.addConnector(connector0);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resHandler, servHandler });
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setIncludedMethods("GET", "POST");
// Note: gzip only affects the response body like our previous 'GHGZIPHook' behaviour: http://stackoverflow.com/a/31565805/194609
// If no mimeTypes are defined the content-type is "not 'application/gzip'", See also https://github.com/graphhopper/directions-api/issues/28 for pitfalls
// gzipHandler.setIncludedMimeTypes();
gzipHandler.setHandler(handlers);
server.setHandler(gzipHandler);
server.start();
logger.info("Started server at HTTP " + host + ":" + httpPort);
}
use of org.eclipse.jetty.servlet.FilterHolder in project drill by apache.
the class WebServer method start.
/**
* Start the web server including setup.
* @throws Exception
*/
public void start() throws Exception {
if (embeddedJetty == null) {
return;
}
final boolean authEnabled = config.getBoolean(ExecConstants.USER_AUTHENTICATION_ENABLED);
if (authEnabled && !context.getAuthProvider().containsFactory(PlainFactory.SIMPLE_NAME)) {
logger.warn("Not starting web server. Currently Drill supports web authentication only through " + "username/password. But PLAIN mechanism is not configured.");
return;
}
final ServerConnector serverConnector;
if (config.getBoolean(ExecConstants.HTTP_ENABLE_SSL)) {
serverConnector = createHttpsConnector();
} else {
serverConnector = createHttpConnector();
}
embeddedJetty.addConnector(serverConnector);
// Add resources
final ErrorHandler errorHandler = new ErrorHandler();
errorHandler.setShowStacks(true);
errorHandler.setShowMessageInTitle(true);
final ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setErrorHandler(errorHandler);
servletContextHandler.setContextPath("/");
final ServletHolder servletHolder = new ServletHolder(new ServletContainer(new DrillRestServer(workManager)));
servletHolder.setInitOrder(1);
servletContextHandler.addServlet(servletHolder, "/*");
servletContextHandler.addServlet(new ServletHolder(new MetricsServlet(metrics)), "/status/metrics");
servletContextHandler.addServlet(new ServletHolder(new ThreadDumpServlet()), "/status/threads");
final ServletHolder staticHolder = new ServletHolder("static", DefaultServlet.class);
// Get resource URL for Drill static assets, based on where Drill icon is located
String drillIconResourcePath = Resource.newClassPathResource(BASE_STATIC_PATH + DRILL_ICON_RESOURCE_RELATIVE_PATH).getURL().toString();
staticHolder.setInitParameter("resourceBase", drillIconResourcePath.substring(0, drillIconResourcePath.length() - DRILL_ICON_RESOURCE_RELATIVE_PATH.length()));
staticHolder.setInitParameter("dirAllowed", "false");
staticHolder.setInitParameter("pathInfoOnly", "true");
servletContextHandler.addServlet(staticHolder, "/static/*");
if (authEnabled) {
servletContextHandler.setSecurityHandler(createSecurityHandler());
servletContextHandler.setSessionHandler(createSessionHandler(servletContextHandler.getSecurityHandler()));
}
if (config.getBoolean(ExecConstants.HTTP_CORS_ENABLED)) {
FilterHolder holder = new FilterHolder(CrossOriginFilter.class);
holder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_ORIGINS), ","));
holder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_METHODS), ","));
holder.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_HEADERS), ","));
holder.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, String.valueOf(config.getBoolean(ExecConstants.HTTP_CORS_CREDENTIALS)));
for (String path : new String[] { "*.json", "/storage/*/enable/*", "/status*" }) {
servletContextHandler.addFilter(holder, path, EnumSet.of(DispatcherType.REQUEST));
}
}
embeddedJetty.setHandler(servletContextHandler);
embeddedJetty.start();
}
Aggregations