use of org.glassfish.jersey.servlet.ServletContainer in project spring-boot by spring-projects.
the class JerseyAutoConfiguration method jerseyServletRegistration.
@Bean
@ConditionalOnMissingBean(name = "jerseyServletRegistration")
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "servlet", matchIfMissing = true)
public ServletRegistrationBean<ServletContainer> jerseyServletRegistration() {
ServletRegistrationBean<ServletContainer> registration = new ServletRegistrationBean<>(new ServletContainer(this.config), this.path);
addInitParameters(registration);
registration.setName(getServletRegistrationName());
registration.setLoadOnStartup(this.jersey.getServlet().getLoadOnStartup());
return registration;
}
use of org.glassfish.jersey.servlet.ServletContainer in project pulsar by yahoo.
the class WebService method addRestResources.
public void addRestResources(String basePath, String javaPackages, boolean requiresAuthentication) {
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(ObjectMapperFactory.create());
ResourceConfig config = new ResourceConfig();
config.packages("jersey.config.server.provider.packages", javaPackages);
config.register(provider);
ServletHolder servletHolder = new ServletHolder(new ServletContainer(config));
servletHolder.setAsyncSupported(true);
addServlet(basePath, servletHolder, requiresAuthentication);
}
use of org.glassfish.jersey.servlet.ServletContainer in project athenz by yahoo.
the class InstanceProviderContainer method run.
public void run() {
try {
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(16);
Server server = new Server(threadPool);
ServletContextHandler handler = new ServletContextHandler();
handler.setContextPath("");
ResourceConfig config = new ResourceConfig(InstanceProviderResources.class).register(new Binder());
handler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
server.setHandler(handler);
// SSL Context Factory
SslContextFactory sslContextFactory = createSSLContextObject();
// SSL HTTP Configuration
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(10043);
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
// SSL Connector
ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
sslConnector.setPort(10043);
server.addConnector(sslConnector);
server.start();
server.join();
} catch (Exception e) {
System.err.println("*** " + e);
}
}
use of org.glassfish.jersey.servlet.ServletContainer in project traccar by tananaev.
the class WebServer method initApi.
private void initApi() {
ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletHandler.setContextPath("/api");
servletHandler.getSessionHandler().setSessionManager(sessionManager);
servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket");
if (config.hasKey("media.path")) {
ServletHolder servletHolder = new ServletHolder("media", DefaultServlet.class);
servletHolder.setInitParameter("resourceBase", config.getString("media.path"));
servletHolder.setInitParameter("dirAllowed", config.getString("media.dirAllowed", "false"));
servletHolder.setInitParameter("pathInfoOnly", "true");
servletHandler.addServlet(servletHolder, "/media/*");
servletHandler.addFilter(MediaFilter.class, "/media/*", EnumSet.allOf(DispatcherType.class));
}
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.registerClasses(JacksonFeature.class, ObjectMapperProvider.class, ResourceErrorHandler.class);
resourceConfig.registerClasses(SecurityRequestFilter.class, CorsResponseFilter.class);
resourceConfig.packages(ServerResource.class.getPackage().getName());
servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*");
handlers.addHandler(servletHandler);
}
use of org.glassfish.jersey.servlet.ServletContainer in project incubator-heron by apache.
the class Runtime method main.
@SuppressWarnings({ "IllegalCatch", "RegexpSinglelineJava" })
public static void main(String[] args) throws Exception {
final Options options = createOptions();
final Options helpOptions = constructHelpOptions();
CommandLineParser parser = new DefaultParser();
// parse the help options first.
CommandLine cmd = parser.parse(helpOptions, args, true);
if (cmd.hasOption(Flag.Help.name)) {
usage(options);
return;
}
try {
cmd = parser.parse(options, args);
} catch (ParseException pe) {
System.err.println(pe.getMessage());
usage(options);
return;
}
final boolean verbose = isVerbose(cmd);
// set and configure logging level
Logging.setVerbose(verbose);
Logging.configure(verbose);
LOG.debug("apiserver overrides:\n {}", cmd.getOptionProperties(Flag.Property.name));
final String toolsHome = getToolsHome();
// read command line flags
final String cluster = cmd.getOptionValue(Flag.Cluster.name);
final String heronConfigurationDirectory = getConfigurationDirectory(toolsHome, cmd);
final String heronDirectory = getHeronDirectory(cmd);
final String releaseFile = getReleaseFile(toolsHome, cmd);
final String configurationOverrides = loadOverrides(cmd);
final int port = getPort(cmd);
final String downloadHostName = getDownloadHostName(cmd);
final String heronCorePackagePath = getHeronCorePackagePath(cmd);
final Config baseConfiguration = ConfigUtils.getBaseConfiguration(heronDirectory, heronConfigurationDirectory, releaseFile, configurationOverrides);
final ResourceConfig config = new ResourceConfig(Resources.get());
final Server server = new Server(port);
final ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
contextHandler.setContextPath("/");
LOG.info("using configuration path: {}", heronConfigurationDirectory);
contextHandler.setAttribute(HeronResource.ATTRIBUTE_CLUSTER, cluster);
contextHandler.setAttribute(HeronResource.ATTRIBUTE_CONFIGURATION, baseConfiguration);
contextHandler.setAttribute(HeronResource.ATTRIBUTE_CONFIGURATION_DIRECTORY, heronConfigurationDirectory);
contextHandler.setAttribute(HeronResource.ATTRIBUTE_CONFIGURATION_OVERRIDE_PATH, configurationOverrides);
contextHandler.setAttribute(HeronResource.ATTRIBUTE_PORT, String.valueOf(port));
contextHandler.setAttribute(HeronResource.ATTRIBUTE_DOWNLOAD_HOSTNAME, Utils.isNotEmpty(downloadHostName) ? String.valueOf(downloadHostName) : null);
contextHandler.setAttribute(HeronResource.ATTRIBUTE_HERON_CORE_PACKAGE_PATH, Utils.isNotEmpty(heronCorePackagePath) ? String.valueOf(heronCorePackagePath) : null);
server.setHandler(contextHandler);
final ServletHolder apiServlet = new ServletHolder(new ServletContainer(config));
contextHandler.addServlet(apiServlet, API_BASE_PATH);
try {
server.start();
LOG.info("Heron apiserver started at {}", server.getURI());
server.join();
} catch (Exception ex) {
final String message = getErrorMessage(server, port, ex);
LOG.error(message);
System.err.println(message);
System.exit(1);
} finally {
server.destroy();
}
}
Aggregations