Search in sources :

Example 1 with ContainerLifecycleListener

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/*");
}
Also used : Container(org.glassfish.jersey.server.spi.Container) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ContainerLifecycleListener(org.glassfish.jersey.server.spi.ContainerLifecycleListener) GuiceIntoHK2Bridge(org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) AsyncSocketServlet(org.traccar.api.AsyncSocketServlet) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) DispatcherType(javax.servlet.DispatcherType) File(java.io.File)

Example 2 with ContainerLifecycleListener

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);
    }
}
Also used : ContainerLifecycleListener(org.glassfish.jersey.server.spi.ContainerLifecycleListener)

Aggregations

ContainerLifecycleListener (org.glassfish.jersey.server.spi.ContainerLifecycleListener)2 File (java.io.File)1 DispatcherType (javax.servlet.DispatcherType)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1 Container (org.glassfish.jersey.server.spi.Container)1 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)1 GuiceIntoHK2Bridge (org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge)1 AsyncSocketServlet (org.traccar.api.AsyncSocketServlet)1