diff options
-rw-r--r-- | src/org/traccar/api/SecurityRequestFilter.java | 5 | ||||
-rw-r--r-- | src/org/traccar/web/WebServer.java | 7 | ||||
-rw-r--r-- | web/app/Application.js | 8 | ||||
-rw-r--r-- | web/app/controller/Root.js | 48 |
4 files changed, 37 insertions, 31 deletions
diff --git a/src/org/traccar/api/SecurityRequestFilter.java b/src/org/traccar/api/SecurityRequestFilter.java index 5f4d2332f..3563cbf77 100644 --- a/src/org/traccar/api/SecurityRequestFilter.java +++ b/src/org/traccar/api/SecurityRequestFilter.java @@ -16,6 +16,7 @@ package org.traccar.api; import org.traccar.Context; +import org.traccar.api.resource.ServerResource; import org.traccar.api.resource.SessionResource; import org.traccar.model.User; @@ -50,8 +51,10 @@ public class SecurityRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { + String path = requestContext.getUriInfo().getPath(); + String serverPath = ServerResource.class.getAnnotation(Path.class).value(); String sessionPath = SessionResource.class.getAnnotation(Path.class).value(); - if (sessionPath.equals(requestContext.getUriInfo().getPath())) { + if (serverPath.equals(path) || sessionPath.equals(path)) { return; } diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index 82a695e96..85be02e4a 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -64,10 +64,10 @@ public class WebServer { break; case "old": initOldApi(); - initRestApi(); initOldWebApp(); break; default: + initOldApi(); initRestApi(); if (config.getBoolean("web.console")) { initConsole(); @@ -130,9 +130,10 @@ public class WebServer { resourceConfig.register(CorsResponseFilter.class); resourceConfig.registerClasses( ServerResource.class, SessionResource.class, DeviceResource.class, UserResource.class); + ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); - ServletHolder servletHolder = new ServletHolder(new ServletContainer(resourceConfig)); - servletHandler.addServlet(servletHolder, "/rest/*"); + servletHandler.setContextPath("/rest"); + servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*"); handlers.addHandler(servletHandler); } diff --git a/web/app/Application.js b/web/app/Application.js index ebf685dbc..34d65d13a 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -78,6 +78,14 @@ Ext.define('Traccar.Application', { return this.getUser().get(key) || this.getServer().get(key) || defaultValue; }, + showError: function (response) { + if (response.statusText) { + Ext.Msg.alert(Strings.errorTitle, response.statusText); + } else { + Ext.Msg.alert(Strings.errorTitle, Strings.errorConnection); + } + }, + getErrorHandler: function (scope, handler) { return function (options, success, response) { var result; diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 733055cdf..de20a8f2b 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -33,43 +33,37 @@ Ext.define('Traccar.controller.Root', { onLaunch: function () { Ext.Ajax.request({ scope: this, - url: '/api/server/get', + url: '/rest/server', callback: this.onServerReturn }); }, onServerReturn: function (options, success, response) { - var result; Ext.get('spinner').remove(); - if (Traccar.ErrorManager.check(success, response)) { - result = Ext.decode(response.responseText); - if (result.success) { - Traccar.app.setServer(result.data); - Ext.Ajax.request({ - scope: this, - url: '/api/session', - callback: this.onSessionReturn - }); - } + if (success) { + Traccar.app.setServer(Ext.decode(response.responseText)); + Ext.Ajax.request({ + scope: this, + url: '/rest/session', + callback: this.onSessionReturn + }); + } else { + Traccar.app.showError(response); } }, onSessionReturn: function (options, success, response) { - var result; - if (Traccar.ErrorManager.check(success, response)) { - result = Ext.decode(response.responseText); - if (result.success) { - Traccar.app.setUser(result.data); - this.loadApp(); - } else { - this.login = Ext.create('widget.login', { - listeners: { - scope: this, - login: this.onLogin - } - }); - this.login.show(); - } + if (success) { + Traccar.app.setUser(Ext.decode(response.responseText)); + this.loadApp(); + } else { + this.login = Ext.create('widget.login', { + listeners: { + scope: this, + login: this.onLogin + } + }); + this.login.show(); } }, |