aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web
diff options
context:
space:
mode:
authorIvan Muratov <binakot@gmail.com>2017-10-24 14:52:48 +0300
committerGitHub <noreply@github.com>2017-10-24 14:52:48 +0300
commitdb02157dbb29539dda4b51a5e8b317293cfc536c (patch)
treeb974f082172406e16a92cb9da8136ef856f571a5 /src/org/traccar/web
parent09d3cf2b5416327700ad22b652cf4a0dca09aaf2 (diff)
parent96e15853b9c28bd31295ca2c014e226e4a50aaa1 (diff)
downloadtrackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.tar.gz
trackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.tar.bz2
trackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.zip
Merge branch 'master' into master
Diffstat (limited to 'src/org/traccar/web')
-rw-r--r--src/org/traccar/web/WebServer.java32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java
index 83ead7ad8..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"));
@@ -105,7 +132,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);