diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-14 15:15:31 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-14 15:15:31 +1200 |
commit | 7310ee5f15729ea8517bfb6b0890a46da1217610 (patch) | |
tree | 44504738f127708420179a7dbbe2942cb67d0849 /src/org/traccar/http | |
parent | 8e8da7019aab023ae255d0ed6d16b94d303fd468 (diff) | |
parent | 0a6faa86c4b634fa3a94633506c4422623e36f1e (diff) | |
download | trackermap-server-7310ee5f15729ea8517bfb6b0890a46da1217610.tar.gz trackermap-server-7310ee5f15729ea8517bfb6b0890a46da1217610.tar.bz2 trackermap-server-7310ee5f15729ea8517bfb6b0890a46da1217610.zip |
Merge Java 7 update (fix #1273)
Diffstat (limited to 'src/org/traccar/http')
-rw-r--r-- | src/org/traccar/http/AsyncServlet.java | 6 | ||||
-rw-r--r-- | src/org/traccar/http/CommandsServlet.java | 28 | ||||
-rw-r--r-- | src/org/traccar/http/DeviceServlet.java | 26 | ||||
-rw-r--r-- | src/org/traccar/http/JsonConverter.java | 8 | ||||
-rw-r--r-- | src/org/traccar/http/MainServlet.java | 28 | ||||
-rw-r--r-- | src/org/traccar/http/PositionServlet.java | 11 | ||||
-rw-r--r-- | src/org/traccar/http/ServerServlet.java | 18 | ||||
-rw-r--r-- | src/org/traccar/http/UserServlet.java | 28 |
8 files changed, 88 insertions, 65 deletions
diff --git a/src/org/traccar/http/AsyncServlet.java b/src/org/traccar/http/AsyncServlet.java index 47ffda3ad..0fc1cd2fb 100644 --- a/src/org/traccar/http/AsyncServlet.java +++ b/src/org/traccar/http/AsyncServlet.java @@ -57,10 +57,10 @@ public class AsyncServlet extends BaseServlet { private boolean destroyed; private final long userId; - private final Set<Long> devices = new HashSet<Long>(); + private final Set<Long> devices = new HashSet<>(); private Timeout sessionTimeout; private Timeout requestTimeout; - private final Map<Long, Position> positions = new HashMap<Long, Position>(); + private final Map<Long, Position> positions = new HashMap<>(); private AsyncContext activeContext; private void logEvent(String message) { @@ -177,7 +177,7 @@ public class AsyncServlet extends BaseServlet { } - private static final Map<Long, AsyncSession> asyncSessions = new HashMap<Long, AsyncSession>(); + private static final Map<Long, AsyncSession> asyncSessions = new HashMap<>(); public static void sessionRefreshUser(long userId) { asyncSessions.remove(userId); diff --git a/src/org/traccar/http/CommandsServlet.java b/src/org/traccar/http/CommandsServlet.java index bf40b79e6..8b3d43fe7 100644 --- a/src/org/traccar/http/CommandsServlet.java +++ b/src/org/traccar/http/CommandsServlet.java @@ -1,29 +1,29 @@ package org.traccar.http; -import org.traccar.Context; -import org.traccar.database.ActiveDevice; -import org.traccar.command.CommandType; -import org.traccar.command.GpsCommand; - import javax.json.Json; import javax.json.JsonObject; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.traccar.Context; +import org.traccar.command.CommandType; +import org.traccar.command.GpsCommand; +import org.traccar.database.ActiveDevice; public class CommandsServlet extends BaseServlet { @Override protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception { - if (command.equals("/send")) { - send(req, resp); - } - else if (command.equals("/raw")) { - sendRawCommand(req, resp); - } - else { - return false; + + switch (command) { + case "/send": + send(req, resp); + return true; + case "/raw": + sendRawCommand(req, resp); + return true; + default: + return false; } - return true; } private void send(HttpServletRequest req, HttpServletResponse resp) throws Exception { diff --git a/src/org/traccar/http/DeviceServlet.java b/src/org/traccar/http/DeviceServlet.java index 2a3e15a80..d1af1c106 100644 --- a/src/org/traccar/http/DeviceServlet.java +++ b/src/org/traccar/http/DeviceServlet.java @@ -24,16 +24,22 @@ public class DeviceServlet extends BaseServlet { @Override protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception { - if (command.equals("/get")) { - get(req, resp); - } else if (command.equals("/add")) { - add(req, resp); - } else if (command.equals("/update")) { - update(req, resp); - } else if (command.equals("/remove")) { - remove(req, resp); - } else { - return false; + + switch (command) { + case "/get": + get(req, resp); + break; + case "/add": + add(req, resp); + break; + case "/update": + update(req, resp); + break; + case "/remove": + remove(req, resp); + break; + default: + return false; } return true; } diff --git a/src/org/traccar/http/JsonConverter.java b/src/org/traccar/http/JsonConverter.java index d658ef7d6..d8773ec1f 100644 --- a/src/org/traccar/http/JsonConverter.java +++ b/src/org/traccar/http/JsonConverter.java @@ -30,7 +30,6 @@ import javax.json.JsonArrayBuilder; import javax.json.JsonObject; import javax.json.JsonObjectBuilder; import javax.json.JsonValue; - import org.traccar.model.Factory; public class JsonConverter { @@ -89,9 +88,7 @@ public class JsonConverter { populateObject(json.getJsonObject(name), nestedObject); method.invoke(object, nestedObject); } - } catch (IllegalAccessException error) { - } catch (InvocationTargetException error) { - } catch (InstantiationException e) { + } catch (IllegalAccessException | InvocationTargetException | InstantiationException error) { } } } @@ -130,8 +127,7 @@ public class JsonConverter { json.add(name, dateFormat.format(value)); } } - } catch (IllegalAccessException error) { - } catch (InvocationTargetException error) { + } catch (IllegalAccessException | InvocationTargetException error) { } } } diff --git a/src/org/traccar/http/MainServlet.java b/src/org/traccar/http/MainServlet.java index 18430f0c3..29eaaec33 100644 --- a/src/org/traccar/http/MainServlet.java +++ b/src/org/traccar/http/MainServlet.java @@ -26,18 +26,24 @@ public class MainServlet extends BaseServlet { @Override protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception { - if (command.equals("/session")) { - session(req, resp); - } else if (command.equals("/login")) { - login(req, resp); - } else if (command.equals("/logout")) { - logout(req, resp); - } else if (command.equals("/register")) { - register(req, resp); - } else { - return false; + + switch (command) { + case "/session": + session(req, resp); + break; + case "/login": + login(req, resp); + break; + case "/logout": + logout(req, resp); + break; + case "/register": + register(req, resp); + break; + default: + return false; } - return true; + return true; } private void session(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { diff --git a/src/org/traccar/http/PositionServlet.java b/src/org/traccar/http/PositionServlet.java index 57b411a79..6f973be3c 100644 --- a/src/org/traccar/http/PositionServlet.java +++ b/src/org/traccar/http/PositionServlet.java @@ -23,10 +23,15 @@ public class PositionServlet extends BaseServlet { @Override protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception { - if (command.equals("/get")) { - get(req, resp); + + switch (command) { + case "/get": + get(req, resp); + break; + default: + return false; } - return true; + return true; } private void get(HttpServletRequest req, HttpServletResponse resp) throws Exception { diff --git a/src/org/traccar/http/ServerServlet.java b/src/org/traccar/http/ServerServlet.java index d814769a8..836a109fc 100644 --- a/src/org/traccar/http/ServerServlet.java +++ b/src/org/traccar/http/ServerServlet.java @@ -24,14 +24,18 @@ public class ServerServlet extends BaseServlet { @Override protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception { - if (command.equals("/get")) { - get(req, resp); - } else if (command.equals("/update")) { - update(req, resp); - } else { - return false; + + switch (command) { + case "/get": + get(req, resp); + break; + case "/update": + update(req, resp); + break; + default: + return false; } - return true; + return true; } private void get(HttpServletRequest req, HttpServletResponse resp) throws Exception { diff --git a/src/org/traccar/http/UserServlet.java b/src/org/traccar/http/UserServlet.java index 71af74485..976a62890 100644 --- a/src/org/traccar/http/UserServlet.java +++ b/src/org/traccar/http/UserServlet.java @@ -24,18 +24,24 @@ public class UserServlet extends BaseServlet { @Override protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception { - if (command.equals("/get")) { - get(req, resp); - } else if (command.equals("/add")) { - add(req, resp); - } else if (command.equals("/update")) { - update(req, resp); - } else if (command.equals("/remove")) { - remove(req, resp); - } else { - return false; + + switch (command) { + case "/get": + get(req, resp); + break; + case "/add": + add(req, resp); + break; + case "/update": + update(req, resp); + break; + case "/remove": + remove(req, resp); + break; + default: + return false; } - return true; + return true; } private void get(HttpServletRequest req, HttpServletResponse resp) throws Exception { |