aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/http/DeviceServlet.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/http/DeviceServlet.java')
-rw-r--r--src/org/traccar/http/DeviceServlet.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/org/traccar/http/DeviceServlet.java b/src/org/traccar/http/DeviceServlet.java
index 5cda5708e..64f7836a4 100644
--- a/src/org/traccar/http/DeviceServlet.java
+++ b/src/org/traccar/http/DeviceServlet.java
@@ -97,9 +97,51 @@ public class DeviceServlet extends HttpServlet {
}
private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+
+ JsonReader jsonReader = Json.createReader(req.getReader());
+ JsonObject jsonObject = jsonReader.readObject();
+ Device device = new Device();
+ try {
+ device.fromJson(jsonObject);
+ } catch (ParseException error) {
+ Log.warning(error);
+ }
+
+ JsonObjectBuilder result = Json.createObjectBuilder();
+
+ try {
+ result.add("success", true);
+ Context.getDataManager().updateDevice(device);
+ } catch(SQLException error) {
+ result.add("success", false);
+ result.add("error", error.getMessage());
+ }
+
+ resp.getWriter().println(result.build().toString());
}
private void remove(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+
+ JsonReader jsonReader = Json.createReader(req.getReader());
+ JsonObject jsonObject = jsonReader.readObject();
+ Device device = new Device();
+ try {
+ device.fromJson(jsonObject);
+ } catch (ParseException error) {
+ Log.warning(error);
+ }
+
+ JsonObjectBuilder result = Json.createObjectBuilder();
+
+ try {
+ result.add("success", true);
+ Context.getDataManager().removeDevice(device);
+ } catch(SQLException error) {
+ result.add("success", false);
+ result.add("error", error.getMessage());
+ }
+
+ resp.getWriter().println(result.build().toString());
}
}