use of org.glassfish.jersey.server.spi.ContainerLifecycleListener 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.server.spi.ContainerLifecycleListener in project jersey by jersey.
the class ServletContainer method destroy.
@Override
public void destroy() {
super.destroy();
final ContainerLifecycleListener listener = containerListener;
if (listener != null) {
listener.onShutdown(this);
}
}
Aggregations