aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-01-29 16:01:53 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-01-29 16:01:53 +1300
commit0ee8100a5535f2d44802919a2a7bb3cec1e547af (patch)
treeb36f6165da092be78e4731362cb7f5a92577f6f8
parent75aa9f8ba896fe88f7842126081b367872a26c46 (diff)
downloadtrackermap-server-0ee8100a5535f2d44802919a2a7bb3cec1e547af.tar.gz
trackermap-server-0ee8100a5535f2d44802919a2a7bb3cec1e547af.tar.bz2
trackermap-server-0ee8100a5535f2d44802919a2a7bb3cec1e547af.zip
Serve static files and embedded servlets
-rw-r--r--default.cfg10
-rw-r--r--src/org/traccar/http/WebServer.java58
-rw-r--r--web/index.html6
3 files changed, 60 insertions, 14 deletions
diff --git a/default.cfg b/default.cfg
index 781f41136..0b478b974 100644
--- a/default.cfg
+++ b/default.cfg
@@ -5,9 +5,9 @@
<properties>
<!-- Global configuration -->
- <!--<entry key='database.driverFile'>/home/user/Documents/traccar/hsqldb.jar</entry>-->
+ <!--<entry key='database.driverFile'>hsqldb.jar</entry>-->
<entry key='database.driver'>org.h2.Driver</entry>
- <entry key='database.url'>jdbc:h2:/home/user/Documents/traccar/target/database</entry>
+ <entry key='database.url'>jdbc:h2:target/database</entry>
<entry key='database.user'>sa</entry>
<entry key='database.password'></entry>
@@ -48,7 +48,9 @@
<entry key='http.enable'>true</entry>
<!--<entry key='http.address'></entry>-->
<entry key='http.port'>8082</entry>
- <entry key='http.application'>/home/user/Documents/traccar-web/traccar-web.war</entry>
+ <entry key='http.application'>../traccar-web/traccar-web.war</entry>
+ <entry key='http.new'>false</entry>
+ <entry key='http.path'>web</entry>
<!-- Geocoder options -->
<entry key='geocoder.enable'>false</entry>
@@ -66,7 +68,7 @@
<!-- Logging options -->
<entry key='logger.enable'>true</entry>
<entry key='logger.level'>all</entry>
- <entry key='logger.file'>/home/user/Documents/traccar/target/tracker-server.log</entry>
+ <entry key='logger.file'>target/tracker-server.log</entry>
<!-- Protocol detector -->
<entry key='detector.enable'>true</entry>
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() {
diff --git a/web/index.html b/web/index.html
new file mode 100644
index 000000000..45c0febd8
--- /dev/null
+++ b/web/index.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+<body>
+file
+</body>
+</html>