aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/http
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-04-24 19:05:00 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-04-24 19:05:00 +1200
commit48a2cd9e5bf3a56c7bb4724a014a1e353cf7eac4 (patch)
tree18ae0d1d921683e81d6bd52e3afa61599847bb6b /src/org/traccar/http
parentc9eb46368a3e8de594ea53770cd5853b5d025966 (diff)
downloadtrackermap-server-48a2cd9e5bf3a56c7bb4724a014a1e353cf7eac4.tar.gz
trackermap-server-48a2cd9e5bf3a56c7bb4724a014a1e353cf7eac4.tar.bz2
trackermap-server-48a2cd9e5bf3a56c7bb4724a014a1e353cf7eac4.zip
Add dummy asyc Servlet
Diffstat (limited to 'src/org/traccar/http')
-rw-r--r--src/org/traccar/http/MainServlet.java35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/org/traccar/http/MainServlet.java b/src/org/traccar/http/MainServlet.java
index 720e75df4..c924898e2 100644
--- a/src/org/traccar/http/MainServlet.java
+++ b/src/org/traccar/http/MainServlet.java
@@ -15,14 +15,16 @@
*/
package org.traccar.http;
-import org.traccar.database.DataManager;
-
+import java.io.IOException;
+import java.sql.SQLException;
+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 java.io.IOException;
-import java.sql.SQLException;
+import org.traccar.database.DataManager;
+import org.traccar.helper.Log;
public class MainServlet extends HttpServlet {
@@ -39,7 +41,9 @@ public class MainServlet extends HttpServlet {
String command = req.getPathInfo();
- if (command.equals("/login")) {
+ if (command.equals("/async")) {
+ async(req.startAsync());
+ } else if (command.equals("/login")) {
login(req, resp);
} else if (command.equals("/logout")) {
logout(req, resp);
@@ -47,6 +51,27 @@ public class MainServlet extends HttpServlet {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
}
}
+
+ private void async(final AsyncContext context) {
+ context.start(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(5000); // DELME
+
+ ServletResponse response = context.getResponse();
+ response.getWriter().println("{ success: true, data: ["+
+ "{ id: 1, device_id: 1, time: \"2012-04-23T18:25:43.511Z\", latitude: 60, longitude: 30, speed: 0, course: 0 }," +
+ "{ id: 2, device_id: 2, time: \"2012-04-23T19:25:43.511Z\", latitude: 61, longitude: 31, speed: 0, course: 0 }" +
+ "] }");
+ context.complete();
+
+ } catch (Exception ex) {
+ Log.warning(ex);
+ }
+ }
+ });
+ }
private void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {