From 4113e28eda3df4725cc72527216a02d1b9cfed17 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 15 Dec 2015 15:02:01 +1300 Subject: Enable only REST API by default --- src/org/traccar/web/WebServer.java | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index cd01d04b4..ebcdc7137 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -71,14 +71,14 @@ public class WebServer { initServer(); switch (config.getString("web.type", "new")) { case "api": - initOldApi(false); + initApi(); break; case "old": - initOldApi(false); + initOldApi(); initOldWebApp(); break; default: - initOldApi(true); + initApi(); if (config.getBoolean("web.console")) { initConsole(); } @@ -122,19 +122,26 @@ public class WebServer { handlers.addHandler(app); } - private void initOldApi(boolean initRest) { + private void initApi() { ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); servletHandler.setContextPath("/api"); - if (initRest) { - ResourceConfig resourceConfig = new ResourceConfig(); - resourceConfig.register(ResourceErrorHandler.class); - resourceConfig.register(SecurityRequestFilter.class); - resourceConfig.register(CorsResponseFilter.class); - resourceConfig.registerClasses(ServerResource.class, SessionResource.class, CommandResource.class, - PermissionResource.class, DeviceResource.class, UserResource.class, PositionResource.class); - servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/rest/*"); - } + servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket"); + + ResourceConfig resourceConfig = new ResourceConfig(); + resourceConfig.register(ResourceErrorHandler.class); + resourceConfig.register(SecurityRequestFilter.class); + resourceConfig.register(CorsResponseFilter.class); + resourceConfig.registerClasses(ServerResource.class, SessionResource.class, CommandResource.class, + PermissionResource.class, DeviceResource.class, UserResource.class, PositionResource.class); + servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*"); + + handlers.addHandler(servletHandler); + } + + private void initOldApi() { + ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); + servletHandler.setContextPath("/api"); servletHandler.addServlet(new ServletHolder(new AsyncServlet()), "/async/*"); servletHandler.addServlet(new ServletHolder(new ServerServlet()), "/server/*"); servletHandler.addServlet(new ServletHolder(new UserServlet()), "/user/*"); -- cgit v1.2.3