aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/web/WebServer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/web/WebServer.java')
-rw-r--r--src/main/java/org/traccar/web/WebServer.java49
1 files changed, 8 insertions, 41 deletions
diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java
index 5d20966ad..36f3d7682 100644
--- a/src/main/java/org/traccar/web/WebServer.java
+++ b/src/main/java/org/traccar/web/WebServer.java
@@ -37,27 +37,21 @@ import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
-import org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
-import org.glassfish.jersey.server.spi.Container;
-import org.glassfish.jersey.server.spi.ContainerLifecycleListener;
import org.glassfish.jersey.servlet.ServletContainer;
-import org.jvnet.hk2.guice.bridge.api.GuiceBridge;
-import org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.LifecycleObject;
-import org.traccar.Main;
-import org.traccar.api.DateParameterConverterProvider;
-import org.traccar.config.Config;
import org.traccar.api.AsyncSocketServlet;
import org.traccar.api.CorsResponseFilter;
+import org.traccar.api.DateParameterConverterProvider;
import org.traccar.api.MediaFilter;
import org.traccar.api.ObjectMapperProvider;
import org.traccar.api.ResourceErrorHandler;
-import org.traccar.api.security.SecurityRequestFilter;
import org.traccar.api.resource.ServerResource;
+import org.traccar.api.security.SecurityRequestFilter;
+import org.traccar.config.Config;
import org.traccar.config.Keys;
import javax.inject.Inject;
@@ -77,8 +71,6 @@ import java.util.EnumSet;
public class WebServer implements LifecycleObject {
- private static final Logger LOGGER = LoggerFactory.getLogger(WebServer.class);
-
private final Injector injector;
private final Config config;
private final Server server;
@@ -192,24 +184,7 @@ public class WebServer implements LifecycleObject {
JacksonFeature.class, ObjectMapperProvider.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) {
- }
- });
+ resourceConfig.register(new GuiceBridgeInitializer(injector));
servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/api/*");
}
@@ -251,21 +226,13 @@ public class WebServer implements LifecycleObject {
}
@Override
- public void start() {
- try {
- server.start();
- } catch (Exception error) {
- LOGGER.warn("Web server start failed", error);
- }
+ public void start() throws Exception {
+ server.start();
}
@Override
- public void stop() {
- try {
- server.stop();
- } catch (Exception error) {
- LOGGER.warn("Web server stop failed", error);
- }
+ public void stop() throws Exception {
+ server.stop();
}
}