aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/http/WebServer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/http/WebServer.java')
-rw-r--r--src/org/traccar/http/WebServer.java58
1 files changed, 48 insertions, 10 deletions
diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java
index 9a7cb9e4e..dac252be1 100644
--- a/src/org/traccar/http/WebServer.java
+++ b/src/org/traccar/http/WebServer.java
@@ -15,12 +15,25 @@
*/
package org.traccar.http;
+import java.io.IOException;
+import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
+
+import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerList;
+import org.eclipse.jetty.server.handler.ResourceHandler;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;
import org.traccar.helper.Log;
@@ -40,17 +53,42 @@ public class WebServer {
server = new Server(new InetSocketAddress(address, port));
}
- try {
- Context context = new InitialContext();
- context.bind("java:/DefaultDS", dataSource);
- } catch (Exception error) {
- Log.warning(error);
- }
+ if (Boolean.valueOf(properties.getProperty("http.new"))) {
+
+ ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ servletHandler.setContextPath("/api");
+ servletHandler.addServlet(new ServletHolder(new HttpServlet() {
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ PrintWriter out = resp.getWriter();
+ out.println("<html><body>api</body></html>");
+ }
+ }), "/*");
+
+ ResourceHandler resourceHandler = new ResourceHandler();
+ resourceHandler.setResourceBase(properties.getProperty("http.path"));
+ resourceHandler.setWelcomeFiles(new String[] {"index.html"});
- WebAppContext webapp = new WebAppContext();
- webapp.setContextPath("/");
- webapp.setWar(properties.getProperty("http.application"));
- server.setHandler(webapp);
+ HandlerList handlerList = new HandlerList();
+ handlerList.setHandlers(new Handler[] {servletHandler, resourceHandler});
+
+ server.setHandler(handlerList);
+
+ } else {
+
+ try {
+ Context context = new InitialContext();
+ context.bind("java:/DefaultDS", dataSource);
+ } catch (Exception error) {
+ Log.warning(error);
+ }
+
+ WebAppContext webapp = new WebAppContext();
+ webapp.setContextPath("/");
+ webapp.setWar(properties.getProperty("http.application"));
+ server.setHandler(webapp);
+
+ }
}
public void start() {