From cbaf29aeb7525deb1f81426c7d4d6cd9f39f500d Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 16 Aug 2017 00:36:49 +1200 Subject: Make cache control configurable --- src/org/traccar/web/WebServer.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/org/traccar/web') diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index 83ead7ad8..9b4b566ef 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -29,6 +29,7 @@ import org.glassfish.jersey.jackson.JacksonFeature; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletContainer; import org.traccar.Config; +import org.traccar.Context; import org.traccar.api.AsyncSocketServlet; import org.traccar.api.CorsResponseFilter; import org.traccar.api.ObjectMapperProvider; @@ -105,7 +106,10 @@ public class WebServer { resourceHandler.setWelcomeFiles(new String[] {"debug.html", "index.html"}); resourceHandler.setMinMemoryMappedContentLength(-1); // avoid locking files on Windows } else { - resourceHandler.setCacheControl("max-age=3600,public"); + String cache = config.getString("web.cacheControl"); + if (cache != null && !cache.isEmpty()) { + resourceHandler.setCacheControl(cache); + } resourceHandler.setWelcomeFiles(new String[] {"release.html", "index.html"}); } handlers.addHandler(resourceHandler); -- cgit v1.2.3 From a781fec58e94326a1b1580239cf92dbc543a59a1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 16 Aug 2017 00:43:49 +1200 Subject: Fix style issue --- src/org/traccar/web/WebServer.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src/org/traccar/web') diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index 9b4b566ef..2055d1161 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -29,7 +29,6 @@ import org.glassfish.jersey.jackson.JacksonFeature; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletContainer; import org.traccar.Config; -import org.traccar.Context; import org.traccar.api.AsyncSocketServlet; import org.traccar.api.CorsResponseFilter; import org.traccar.api.ObjectMapperProvider; -- cgit v1.2.3 From ebd2dcda811a8604d889824f02a79c727c5f1674 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 2 Sep 2017 09:14:02 +1200 Subject: Implement OsmAnd web proxy --- pom.xml | 5 +++++ src/org/traccar/web/WebServer.java | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'src/org/traccar/web') diff --git a/pom.xml b/pom.xml index 4270a0cd7..f04a3ff68 100644 --- a/pom.xml +++ b/pom.xml @@ -103,6 +103,11 @@ jetty-jndi ${jetty.version} + + org.eclipse.jetty + jetty-proxy + ${jetty.version} + org.eclipse.jetty.websocket websocket-server diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index 2055d1161..e145ff554 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -15,7 +15,10 @@ */ package org.traccar.web; +import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpStatus; +import org.eclipse.jetty.proxy.AsyncProxyServlet; +import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.SessionManager; import org.eclipse.jetty.server.handler.ErrorHandler; @@ -29,6 +32,7 @@ import org.glassfish.jersey.jackson.JacksonFeature; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletContainer; import org.traccar.Config; +import org.traccar.Context; import org.traccar.api.AsyncSocketServlet; import org.traccar.api.CorsResponseFilter; import org.traccar.api.ObjectMapperProvider; @@ -38,7 +42,9 @@ import org.traccar.api.resource.ServerResource; import org.traccar.helper.Log; import javax.naming.InitialContext; +import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.sql.DataSource; import java.io.IOException; import java.io.Writer; @@ -86,6 +92,7 @@ public class WebServer { initWebApp(); break; } + initClientProxy(); server.setHandler(handlers); server.addBean(new ErrorHandler() { @@ -98,6 +105,26 @@ public class WebServer { }, false); } + private void initClientProxy() { + int port = Context.getConfig().getInteger("osmand.port"); + if (port != 0) { + ServletContextHandler servletHandler = new ServletContextHandler() { + @Override + public void doScope( + String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + if (target.equals("/") && request.getMethod().equals(HttpMethod.POST.asString())) { + super.doScope(target, baseRequest, request, response); + } + } + }; + ServletHolder servletHolder = new ServletHolder(new AsyncProxyServlet.Transparent()); + servletHolder.setInitParameter("proxyTo", "http://localhost:" + port); + servletHandler.addServlet(servletHolder, "/"); + handlers.addHandler(servletHandler); + } + } + private void initWebApp() { ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setResourceBase(config.getString("web.path")); -- cgit v1.2.3