diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-04-25 11:02:26 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-04-25 11:02:26 +1200 |
commit | 9ea2dbe8400bd1ab30451e3dc2b85aa7a583a8e1 (patch) | |
tree | b9d71935821a7c895c11f87b1eb1fe3579f5289b /src/org/traccar/http/MainServlet.java | |
parent | 5859529fa396cf74bdddc714ea1936c972d01579 (diff) | |
download | trackermap-server-9ea2dbe8400bd1ab30451e3dc2b85aa7a583a8e1.tar.gz trackermap-server-9ea2dbe8400bd1ab30451e3dc2b85aa7a583a8e1.tar.bz2 trackermap-server-9ea2dbe8400bd1ab30451e3dc2b85aa7a583a8e1.zip |
Use Java standard Json library
Diffstat (limited to 'src/org/traccar/http/MainServlet.java')
-rw-r--r-- | src/org/traccar/http/MainServlet.java | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/org/traccar/http/MainServlet.java b/src/org/traccar/http/MainServlet.java index e569b4892..7483b22b4 100644 --- a/src/org/traccar/http/MainServlet.java +++ b/src/org/traccar/http/MainServlet.java @@ -17,13 +17,14 @@ package org.traccar.http; import java.io.IOException; import java.sql.SQLException; +import javax.json.Json; +import javax.json.JsonObjectBuilder; import javax.servlet.AsyncContext; import javax.servlet.ServletException; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.json.JSONObject; import org.traccar.Context; import org.traccar.helper.Log; @@ -72,19 +73,19 @@ public class MainServlet extends HttpServlet { private void device(HttpServletRequest req, HttpServletResponse resp) throws IOException { - long userId = 1;//(Long) req.getSession().getAttribute(USER_ID); + long userId = (Long) req.getSession().getAttribute(USER_ID); - JSONObject result = new JSONObject(); + JsonObjectBuilder result = Json.createObjectBuilder(); try { - result.put("success", true); - result.put("data", Context.getDataManager().getDevices(userId)); + result.add("success", true); + result.add("data", Context.getDataManager().getDevices(userId)); } catch(SQLException error) { - result.put("success", false); - result.put("error", error.getMessage()); + result.add("success", false); + result.add("error", error.getMessage()); } - resp.getWriter().println(result.toString()); + resp.getWriter().println(result.build().toString()); } private void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |