aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/web
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-02-18 00:00:12 -0800
committerAnton Tananaev <anton@traccar.org>2022-02-18 00:00:12 -0800
commitb5b9eb8207f42235f7ed2a52a6424f5629590992 (patch)
tree011b444c6c9d71447c0f5c8d0ae3daa4021b7f8c /src/main/java/org/traccar/web
parente901e80d26544e86a9e3509532de92ceed0b87a8 (diff)
downloadtrackermap-server-b5b9eb8207f42235f7ed2a52a6424f5629590992.tar.gz
trackermap-server-b5b9eb8207f42235f7ed2a52a6424f5629590992.tar.bz2
trackermap-server-b5b9eb8207f42235f7ed2a52a6424f5629590992.zip
Migrate server API to storage
Diffstat (limited to 'src/main/java/org/traccar/web')
-rw-r--r--src/main/java/org/traccar/web/WebServer.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java
index 604edfedc..46c1f3912 100644
--- a/src/main/java/org/traccar/web/WebServer.java
+++ b/src/main/java/org/traccar/web/WebServer.java
@@ -35,12 +35,18 @@ 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.Context;
+import org.traccar.Main;
import org.traccar.api.DateParameterConverterProvider;
import org.traccar.config.Config;
import org.traccar.api.AsyncSocketServlet;
@@ -174,6 +180,24 @@ public class WebServer {
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) {
+ }
+ });
servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/api/*");
}