diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-16 16:20:13 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-16 16:20:13 -0700 |
commit | b100cb211161d1014dfaa1ab532f1670c699e80d (patch) | |
tree | 48b9191e793391f87e9fe5399d6ddf966040c184 /src/main/java/org/traccar/web/WebServer.java | |
parent | b47eca7a90438e738eb1486664717cccc277865f (diff) | |
download | trackermap-server-b100cb211161d1014dfaa1ab532f1670c699e80d.tar.gz trackermap-server-b100cb211161d1014dfaa1ab532f1670c699e80d.tar.bz2 trackermap-server-b100cb211161d1014dfaa1ab532f1670c699e80d.zip |
Improve web injection
Diffstat (limited to 'src/main/java/org/traccar/web/WebServer.java')
-rw-r--r-- | src/main/java/org/traccar/web/WebServer.java | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java index 36f3d7682..46e401779 100644 --- a/src/main/java/org/traccar/web/WebServer.java +++ b/src/main/java/org/traccar/web/WebServer.java @@ -15,6 +15,7 @@ */ package org.traccar.web; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.inject.Injector; import com.google.inject.servlet.GuiceFilter; import org.eclipse.jetty.http.HttpCookie; @@ -40,13 +41,9 @@ import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerI import org.glassfish.jersey.jackson.JacksonFeature; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletContainer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.traccar.LifecycleObject; -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.resource.ServerResource; @@ -88,6 +85,8 @@ public class WebServer implements LifecycleObject { } ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); + JettyWebSocketServletContainerInitializer.configure(servletHandler, null); + servletHandler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class)); initApi(servletHandler); initSessionConfig(servletHandler); @@ -140,7 +139,7 @@ public class WebServer implements LifecycleObject { } } }; - ServletHolder servletHolder = new ServletHolder(new AsyncProxyServlet.Transparent()); + ServletHolder servletHolder = new ServletHolder(AsyncProxyServlet.Transparent.class); servletHolder.setInitParameter("proxyTo", "http://localhost:" + port); servletHandler.addServlet(servletHolder, "/"); handlers.addHandler(servletHandler); @@ -164,11 +163,6 @@ public class WebServer implements LifecycleObject { } private void initApi(ServletContextHandler servletHandler) { - servletHandler.addFilter(GuiceFilter.class, "/api/*", EnumSet.allOf(DispatcherType.class)); - - servletHandler.addServlet(new ServletHolder(injector.getInstance(AsyncSocketServlet.class)), "/api/socket"); - JettyWebSocketServletContainerInitializer.configure(servletHandler, null); - String mediaPath = config.getString(Keys.MEDIA_PATH); if (mediaPath != null) { ServletHolder servletHolder = new ServletHolder(DefaultServlet.class); @@ -176,15 +170,18 @@ public class WebServer implements LifecycleObject { 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.register(new GuiceBridgeInitializer(injector)); + resourceConfig.register(new ObjectMapperProvider(injector.getInstance(ObjectMapper.class))); resourceConfig.registerClasses( - JacksonFeature.class, ObjectMapperProvider.class, ResourceErrorHandler.class, - SecurityRequestFilter.class, CorsResponseFilter.class, DateParameterConverterProvider.class); + JacksonFeature.class, + DateParameterConverterProvider.class, + SecurityRequestFilter.class, + CorsResponseFilter.class, + ResourceErrorHandler.class); resourceConfig.packages(ServerResource.class.getPackage().getName()); - resourceConfig.register(new GuiceBridgeInitializer(injector)); servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/api/*"); } |