diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-09-02 09:14:02 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-09-02 09:14:02 +1200 |
commit | ebd2dcda811a8604d889824f02a79c727c5f1674 (patch) | |
tree | cd2675e7e33d7e7580bbf5807bfb3c66e9973908 /src | |
parent | 7153cce6c715caed906f5e274f8ce50342926262 (diff) | |
download | trackermap-server-ebd2dcda811a8604d889824f02a79c727c5f1674.tar.gz trackermap-server-ebd2dcda811a8604d889824f02a79c727c5f1674.tar.bz2 trackermap-server-ebd2dcda811a8604d889824f02a79c727c5f1674.zip |
Implement OsmAnd web proxy
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/web/WebServer.java | 27 |
1 files changed, 27 insertions, 0 deletions
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")); |