From 48a2cd9e5bf3a56c7bb4724a014a1e353cf7eac4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 24 Apr 2015 19:05:00 +1200 Subject: Add dummy asyc Servlet --- src/org/traccar/http/MainServlet.java | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src/org/traccar/http') 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 { -- cgit v1.2.3