use of org.glassfish.jersey.servlet.ServletContainer in project kylo by Teradata.
the class SpringJerseyConfiguration method jerseyServlet.
@Bean(name = "mainJerseyServlet")
public ServletRegistrationBean jerseyServlet(JerseyConfig jerseyConfig) {
ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(jerseyConfig));
registration.addUrlMappings("/api/*");
// our rest resources will be available in the path /api/*
registration.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, JerseyConfig.class.getName());
return registration;
}
use of org.glassfish.jersey.servlet.ServletContainer in project traccar by tananaev.
the class WebServer method initApi.
private void initApi(Config config, ServletContextHandler servletHandler) {
servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/api/socket");
JettyWebSocketServletContainerInitializer.configure(servletHandler, null);
String mediaPath = config.getString(Keys.MEDIA_PATH);
if (mediaPath != null) {
ServletHolder servletHolder = new ServletHolder(DefaultServlet.class);
servletHolder.setInitParameter("resourceBase", new File(mediaPath).getAbsolutePath());
servletHolder.setInitParameter("dirAllowed", "false");
servletHolder.setInitParameter("pathInfoOnly", "true");
servletHandler.addServlet(servletHolder, "/api/media/*");
servletHandler.addFilter(MediaFilter.class, "/api/media/*", EnumSet.allOf(DispatcherType.class));
}
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.registerClasses(JacksonFeature.class, ResourceErrorHandler.class, SecurityRequestFilter.class, CorsResponseFilter.class, DateParameterConverterProvider.class);
resourceConfig.packages(ServerResource.class.getPackage().getName());
resourceConfig.register(new ContainerLifecycleListener() {
@Override
public void onStartup(Container container) {
var injectionManager = container.getApplicationHandler().getInjectionManager();
var serviceLocator = ((ImmediateHk2InjectionManager) injectionManager).getServiceLocator();
GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
var guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
guiceBridge.bridgeGuiceInjector(Main.getInjector());
}
@Override
public void onReload(Container container) {
}
@Override
public void onShutdown(Container container) {
}
});
servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/api/*");
}
use of org.glassfish.jersey.servlet.ServletContainer in project jersey by jersey.
the class JerseyServletContainerInitializer method addServletWithDefaultConfiguration.
/**
* Enhance default servlet (named {@link Application}) configuration.
*/
private static void addServletWithDefaultConfiguration(final ServletContext context, final Set<Class<?>> classes) throws ServletException {
ServletRegistration registration = context.getServletRegistration(Application.class.getName());
if (registration != null) {
final Set<Class<?>> appClasses = getRootResourceAndProviderClasses(classes);
final ResourceConfig resourceConfig = ResourceConfig.forApplicationClass(ResourceConfig.class, appClasses).addProperties(getInitParams(registration)).addProperties(Utils.getContextParams(context));
if (registration.getClassName() != null) {
// class name present - complete servlet registration from container point of view
Utils.store(resourceConfig, context, registration.getName());
} else {
// no class name - no complete servlet registration from container point of view
final ServletContainer servlet = new ServletContainer(resourceConfig);
registration = context.addServlet(registration.getName(), servlet);
((ServletRegistration.Dynamic) registration).setLoadOnStartup(1);
if (registration.getMappings().isEmpty()) {
// Error
LOGGER.log(Level.WARNING, LocalizationMessages.JERSEY_APP_NO_MAPPING(registration.getName()));
} else {
LOGGER.log(Level.CONFIG, LocalizationMessages.JERSEY_APP_REGISTERED_CLASSES(registration.getName(), appClasses));
}
}
}
}
use of org.glassfish.jersey.servlet.ServletContainer in project jersey by jersey.
the class Activator method rawRegisterServlets.
private void rawRegisterServlets() throws ServletException, NamespaceException, InterruptedException {
logger.info("JERSEY BUNDLE: REGISTERING SERVLETS");
logger.info("JERSEY BUNDLE: HTTP SERVICE = " + httpService.toString());
// TODO - temporary workaround
// This is a workaround related to issue JERSEY-2093; grizzly (1.9.5) needs to have the correct context
// classloader set
ClassLoader myClassLoader = getClass().getClassLoader();
ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(myClassLoader);
httpService.registerServlet("/jersey-http-service", new ServletContainer(), getJerseyServletParams(), null);
} finally {
Thread.currentThread().setContextClassLoader(originalContextClassLoader);
}
// END of workaround - after grizzly updated to the recent version, only the inner call from try block will remain:
// httpService.registerServlet("/jersey-http-service", new ServletContainer(), getJerseyServletParams(), null);
sendAdminEvent();
logger.info("JERSEY BUNDLE: SERVLETS REGISTERED");
}
use of org.glassfish.jersey.servlet.ServletContainer in project spring-boot by spring-projects.
the class JerseyAutoConfiguration method jerseyFilterRegistration.
@Bean
@ConditionalOnMissingBean(name = "jerseyFilterRegistration")
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "filter")
public FilterRegistrationBean<ServletContainer> jerseyFilterRegistration() {
FilterRegistrationBean<ServletContainer> registration = new FilterRegistrationBean<>();
registration.setFilter(new ServletContainer(this.config));
registration.setUrlPatterns(Arrays.asList(this.path));
registration.setOrder(this.jersey.getFilter().getOrder());
registration.addInitParameter(ServletProperties.FILTER_CONTEXT_PATH, stripPattern(this.path));
addInitParameters(registration);
registration.setName("jerseyFilter");
registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
return registration;
}
Aggregations