aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-11-27 15:12:28 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-11-27 15:12:28 +1300
commit7db2eb1ad224bf00608ebbcfe13bfa7fd519a7fc (patch)
tree60840d3b8b39c07802e8c65fee10e8222f992435
parent6eab101b0070cf5af8fd9e177a2a3ba40e5e836c (diff)
downloadtrackermap-server-7db2eb1ad224bf00608ebbcfe13bfa7fd519a7fc.tar.gz
trackermap-server-7db2eb1ad224bf00608ebbcfe13bfa7fd519a7fc.tar.bz2
trackermap-server-7db2eb1ad224bf00608ebbcfe13bfa7fd519a7fc.zip
Host database console using Jetty
-rw-r--r--debug.xml4
-rw-r--r--src/org/traccar/Context.java24
-rw-r--r--src/org/traccar/Main.java6
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java1
-rw-r--r--src/org/traccar/web/CommandServlet.java15
-rw-r--r--src/org/traccar/web/ConsoleServlet.java52
-rw-r--r--src/org/traccar/web/WebServer.java10
7 files changed, 78 insertions, 34 deletions
diff --git a/debug.xml b/debug.xml
index 0d61b2df0..0f6e49baf 100644
--- a/debug.xml
+++ b/debug.xml
@@ -13,6 +13,7 @@
<entry key='web.old'>true</entry>-->
<entry key='web.path'>web</entry>
<entry key='web.debug'>true</entry>
+ <entry key='web.console'>true</entry>
<entry key='geocoder.enable'>true</entry>
<entry key='geocoder.type'>nominatim</entry>
@@ -25,9 +26,6 @@
<entry key='distance.enable'>true</entry>
- <entry key='console.enable'>true</entry>
- <entry key='console.port'>8083</entry>
-
<!--<entry key='filter.enable'>true</entry>
<entry key='filter.limit'>3600</entry>
<entry key='filter.invalid'>true</entry>
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index 675465aff..c833d0c2e 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -16,8 +16,6 @@
package org.traccar;
import com.ning.http.client.AsyncHttpClient;
-import org.h2.server.web.ConnectionInfo;
-import org.h2.tools.Server;
import org.traccar.database.ConnectionManager;
import org.traccar.database.DataManager;
import org.traccar.database.IdentityManager;
@@ -36,8 +34,6 @@ import org.traccar.location.MozillaLocationProvider;
import org.traccar.location.OpenCellIdLocationProvider;
import org.traccar.web.WebServer;
-import java.lang.reflect.Method;
-
public final class Context {
private Context() {
@@ -97,12 +93,6 @@ public final class Context {
return webServer;
}
- private static Server databaseConsole;
-
- public static Server getDatabaseConsole() {
- return databaseConsole;
- }
-
private static ServerManager serverManager;
public static ServerManager getServerManager() {
@@ -185,20 +175,6 @@ public final class Context {
webServer = new WebServer(config, dataManager.getDataSource());
}
- if (config.getBoolean("console.enable")) {
- databaseConsole = Server.createWebServer("-webPort", config.getString("console.port"));
- org.h2.server.web.WebServer databaseService = (org.h2.server.web.WebServer) databaseConsole.getService();
-
- ConnectionInfo connectionInfo = new ConnectionInfo("Traccar|"
- + config.getString("database.driver") + "|"
- + config.getString("database.url") + "|"
- + config.getString("database.user"));
-
- Method method = databaseService.getClass().getDeclaredMethod("updateSetting", ConnectionInfo.class);
- method.setAccessible(true);
- method.invoke(databaseService, connectionInfo);
- }
-
connectionManager = new ConnectionManager(dataManager);
serverManager = new ServerManager();
diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java
index 7c2e00ca0..7ff93fda6 100644
--- a/src/org/traccar/Main.java
+++ b/src/org/traccar/Main.java
@@ -33,18 +33,12 @@ public final class Main {
if (Context.getWebServer() != null) {
Context.getWebServer().start();
}
- if (Context.getDatabaseConsole() != null) {
- Context.getDatabaseConsole().start();
- }
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Log.info("Shutting down server...");
- if (Context.getDatabaseConsole() != null) {
- Context.getDatabaseConsole().stop();
- }
if (Context.getWebServer() != null) {
Context.getWebServer().stop();
}
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index b941e332d..31bdd9aa9 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -27,7 +27,6 @@ import org.traccar.helper.ChannelBufferTools;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.PatternUtil;
import org.traccar.model.Event;
import org.traccar.model.Position;
diff --git a/src/org/traccar/web/CommandServlet.java b/src/org/traccar/web/CommandServlet.java
index 958f1a888..67bca2d57 100644
--- a/src/org/traccar/web/CommandServlet.java
+++ b/src/org/traccar/web/CommandServlet.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.traccar.web;
import javax.json.Json;
diff --git a/src/org/traccar/web/ConsoleServlet.java b/src/org/traccar/web/ConsoleServlet.java
new file mode 100644
index 000000000..b219eaba4
--- /dev/null
+++ b/src/org/traccar/web/ConsoleServlet.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.web;
+
+import org.h2.server.web.ConnectionInfo;
+import org.h2.server.web.WebServlet;
+import org.traccar.Context;
+import org.traccar.helper.Log;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public class ConsoleServlet extends WebServlet {
+
+ @Override
+ public void init() {
+ super.init();
+
+ try {
+ Field field = WebServlet.class.getDeclaredField("server");
+ field.setAccessible(true);
+ org.h2.server.web.WebServer server = (org.h2.server.web.WebServer) field.get(this);
+
+ ConnectionInfo connectionInfo = new ConnectionInfo("Traccar|"
+ + Context.getConfig().getString("database.driver") + "|"
+ + Context.getConfig().getString("database.url") + "|"
+ + Context.getConfig().getString("database.user"));
+
+ Method method = org.h2.server.web.WebServer.class.getDeclaredMethod("updateSetting", ConnectionInfo.class);
+ method.setAccessible(true);
+ method.invoke(server, connectionInfo);
+
+ } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
+ Log.warning(e);
+ }
+ }
+
+}
diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java
index 36c43736d..f5a6acdd9 100644
--- a/src/org/traccar/web/WebServer.java
+++ b/src/org/traccar/web/WebServer.java
@@ -59,6 +59,9 @@ public class WebServer {
break;
case "new":
initApi();
+ if (config.getBoolean("web.console")) {
+ initConsole();
+ }
initWebApp();
break;
case "old":
@@ -110,6 +113,13 @@ public class WebServer {
handlers.addHandler(servletHandler);
}
+ private void initConsole() {
+ ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ servletHandler.setContextPath("/console");
+ servletHandler.addServlet(new ServletHolder(new ConsoleServlet()), "/*");
+ handlers.addHandler(servletHandler);
+ }
+
public void start() {
try {
server.start();