aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-12-02 11:48:40 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-12-02 11:48:40 +1300
commita0a96b253b90d389a5c06ba1133b2a2f32ecb0fc (patch)
treea6152b09c89027f1932c4f28c1c8aaf1a6055065
parent831a7b81004c0456c317ef4c521cbebd4cbf5fc2 (diff)
downloadtrackermap-server-a0a96b253b90d389a5c06ba1133b2a2f32ecb0fc.tar.gz
trackermap-server-a0a96b253b90d389a5c06ba1133b2a2f32ecb0fc.tar.bz2
trackermap-server-a0a96b253b90d389a5c06ba1133b2a2f32ecb0fc.zip
Share session between two API versions
-rw-r--r--src/org/traccar/web/BaseServlet.java2
-rw-r--r--src/org/traccar/web/WebServer.java31
-rw-r--r--web/app/controller/Root.js4
3 files changed, 15 insertions, 22 deletions
diff --git a/src/org/traccar/web/BaseServlet.java b/src/org/traccar/web/BaseServlet.java
index d215c62d0..69a073d39 100644
--- a/src/org/traccar/web/BaseServlet.java
+++ b/src/org/traccar/web/BaseServlet.java
@@ -36,7 +36,7 @@ import org.traccar.Context;
public abstract class BaseServlet extends HttpServlet {
- public static final String USER_ID_KEY = "user";
+ public static final String USER_ID_KEY = "userId";
public static final String ALLOW_ORIGIN_VALUE = "*";
public static final String ALLOW_HEADERS_VALUE = "Origin, X-Requested-With, Content-Type, Accept";
public static final String ALLOW_METHODS_VALUE = "GET, POST, PUT, DELETE";
diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java
index 85be02e4a..9cfe06e0e 100644
--- a/src/org/traccar/web/WebServer.java
+++ b/src/org/traccar/web/WebServer.java
@@ -60,15 +60,14 @@ public class WebServer {
initServer();
switch (config.getString("web.type", "new")) {
case "api":
- initOldApi();
+ initOldApi(false);
break;
case "old":
- initOldApi();
+ initOldApi(false);
initOldWebApp();
break;
default:
- initOldApi();
- initRestApi();
+ initOldApi(true);
if (config.getBoolean("web.console")) {
initConsole();
}
@@ -103,10 +102,17 @@ public class WebServer {
handlers.addHandler(app);
}
- @Deprecated
- private void initOldApi() {
+ private void initOldApi(boolean initRest) {
ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletHandler.setContextPath("/api");
+ if (initRest) {
+ ResourceConfig resourceConfig = new ResourceConfig();
+ resourceConfig.register(SecurityRequestFilter.class);
+ resourceConfig.register(CorsResponseFilter.class);
+ resourceConfig.registerClasses(
+ ServerResource.class, SessionResource.class, DeviceResource.class, UserResource.class);
+ servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/rest/*");
+ }
servletHandler.addServlet(new ServletHolder(new AsyncServlet()), "/async/*");
servletHandler.addServlet(new ServletHolder(new ServerServlet()), "/server/*");
servletHandler.addServlet(new ServletHolder(new UserServlet()), "/user/*");
@@ -124,19 +130,6 @@ public class WebServer {
handlers.addHandler(servletHandler);
}
- private void initRestApi() {
- ResourceConfig resourceConfig = new ResourceConfig();
- resourceConfig.register(SecurityRequestFilter.class);
- resourceConfig.register(CorsResponseFilter.class);
- resourceConfig.registerClasses(
- ServerResource.class, SessionResource.class, DeviceResource.class, UserResource.class);
-
- ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
- servletHandler.setContextPath("/rest");
- servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*");
- handlers.addHandler(servletHandler);
- }
-
public void start() {
try {
server.start();
diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js
index de20a8f2b..cd868d2bc 100644
--- a/web/app/controller/Root.js
+++ b/web/app/controller/Root.js
@@ -33,7 +33,7 @@ Ext.define('Traccar.controller.Root', {
onLaunch: function () {
Ext.Ajax.request({
scope: this,
- url: '/rest/server',
+ url: '/api/rest/server',
callback: this.onServerReturn
});
},
@@ -44,7 +44,7 @@ Ext.define('Traccar.controller.Root', {
Traccar.app.setServer(Ext.decode(response.responseText));
Ext.Ajax.request({
scope: this,
- url: '/rest/session',
+ url: '/api/rest/session',
callback: this.onSessionReturn
});
} else {