use of org.glassfish.jersey.servlet.ServletContainer in project drill by axbaretto.
the class WebServer method buildServlets.
/**
* Build the web app with embedded servlets.
* <p>
* <b>ServletContextHandler</b>: is a Jetty-provided handler that add the
* extra bits needed to set up the context that servlets expect. Think of it
* as an adapter between the (simple) Jetty handler and the (more complex)
* servlet API.
*/
private void buildServlets(Config config) {
final ServletContextHandler servletContextHandler = new ServletContextHandler(null, "/");
servletContextHandler.setErrorHandler(createErrorHandler());
jettyServer.setHandler(servletContextHandler);
// Servlet holder for the pages of the Drill AM web app. The web app is a
// javax.ws application driven from annotations. The servlet holder "does
// the right thing" to drive the application, which is rooted at "/".
// The servlet container comes from Jersey, and manages the servlet
// lifecycle.
final ServletHolder servletHolder = new ServletHolder(new ServletContainer(new WebUiPageTree(dispatcher)));
servletHolder.setInitOrder(1);
servletContextHandler.addServlet(servletHolder, "/*");
final ServletHolder restHolder = new ServletHolder(new ServletContainer(new AmRestApi(dispatcher)));
restHolder.setInitOrder(2);
servletContextHandler.addServlet(restHolder, "/rest/*");
// Static resources (CSS, images, etc.)
setupStaticResources(servletContextHandler);
if (AMSecurityManagerImpl.isEnabled()) {
servletContextHandler.setSecurityHandler(createSecurityHandler(config));
servletContextHandler.setSessionHandler(createSessionHandler(config, servletContextHandler.getSecurityHandler()));
}
}
use of org.glassfish.jersey.servlet.ServletContainer in project drill by axbaretto.
the class WebServer method createServletContextHandler.
private ServletContextHandler createServletContextHandler(final boolean authEnabled) throws DrillbitStartupException {
// Add resources
final ErrorHandler errorHandler = new DrillErrorHandler();
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, servletContextHandler.getServletContext(), drillbit)));
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) {
// DrillSecurityHandler is used to support SPNEGO and FORM authentication together
servletContextHandler.setSecurityHandler(new DrillHttpSecurityHandlerProvider(config, workManager.getContext()));
servletContextHandler.setSessionHandler(createSessionHandler(servletContextHandler.getSecurityHandler()));
}
if (isImpersonationOnlyEnabled(workManager.getContext().getConfig())) {
for (String path : new String[] { "/query", "/query.json" }) {
servletContextHandler.addFilter(UserNameFilter.class, path, EnumSet.of(DispatcherType.REQUEST));
}
}
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));
}
}
return servletContextHandler;
}
use of org.glassfish.jersey.servlet.ServletContainer in project samza by apache.
the class SamzaRestService method main.
/**
* Command line interface to run the server.
*
* @param args arguments supported by {@link org.apache.samza.util.CommandLine}.
* In particular, --config job.config.loader.properties.path and
* --config job.config.loader.factory are used to read the Samza REST config file.
* @throws Exception if the server could not be successfully started.
*/
public static void main(String[] args) throws Exception {
SamzaMonitorService monitorService = null;
try {
SamzaRestConfig config = parseConfig(args);
ReadableMetricsRegistry metricsRegistry = new MetricsRegistryMap();
log.info("Creating new SamzaRestService with config: {}", config);
MetricsConfig metricsConfig = new MetricsConfig(config);
Map<String, MetricsReporter> metricsReporters = MetricsReporterLoader.getMetricsReporters(metricsConfig, Util.getLocalHost().getHostName());
SamzaRestService restService = new SamzaRestService(new Server(config.getPort()), metricsRegistry, metricsReporters, new ServletContextHandler(ServletContextHandler.SESSIONS));
// Add applications
SamzaRestApplication samzaRestApplication = new SamzaRestApplication(config);
ServletContainer container = new ServletContainer(samzaRestApplication);
restService.addServlet(container, "/*");
monitorService = new SamzaMonitorService(config, metricsRegistry);
monitorService.start();
restService.runBlocking();
} catch (Throwable t) {
log.error("Exception in main.", t);
} finally {
if (monitorService != null) {
monitorService.stop();
}
}
}
use of org.glassfish.jersey.servlet.ServletContainer in project JsonPath by jayway.
the class Main method createJerseyServlet.
private static ServletContainer createJerseyServlet() throws IOException {
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(JacksonFeature.class);
resourceConfig.register(new ApiResource());
return new ServletContainer(resourceConfig);
}
use of org.glassfish.jersey.servlet.ServletContainer in project neo4j by neo4j.
the class JaxRsServletHolderFactory method create.
public ServletHolder create(ComponentsBinder binder, boolean wadlEnabled) {
for (Injectable<?> injectable : injectables) {
Supplier<?> getValue = injectable::getValue;
Class<?> type = injectable.getType();
binder.addLazyBinding(getValue, type);
}
ResourceConfig resourceConfig = new ResourceConfig().register(binder).register(XForwardFilter.class).packages(packages.toArray(new String[0])).registerClasses(classes).property(WADL_FEATURE_DISABLE, String.valueOf(!wadlEnabled));
ServletContainer container = new ServletContainer(resourceConfig);
return new ServletHolder(container);
}
Aggregations