aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/http/MainServlet.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-05-03 14:35:59 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-05-03 14:35:59 +1200
commit7b58913edc7d1572ef66e16bd1c989a510455b6e (patch)
tree4cdc76ee53fe86ea357c711e967f4906c7deb275 /src/org/traccar/http/MainServlet.java
parent18127a2dfc362ffd7de4110e013a10a9f894469b (diff)
downloadtrackermap-server-7b58913edc7d1572ef66e16bd1c989a510455b6e.tar.gz
trackermap-server-7b58913edc7d1572ef66e16bd1c989a510455b6e.tar.bz2
trackermap-server-7b58913edc7d1572ef66e16bd1c989a510455b6e.zip
Create base servlet class
Diffstat (limited to 'src/org/traccar/http/MainServlet.java')
-rw-r--r--src/org/traccar/http/MainServlet.java48
1 files changed, 11 insertions, 37 deletions
diff --git a/src/org/traccar/http/MainServlet.java b/src/org/traccar/http/MainServlet.java
index a881d3f45..8fa0a13af 100644
--- a/src/org/traccar/http/MainServlet.java
+++ b/src/org/traccar/http/MainServlet.java
@@ -16,66 +16,40 @@
package org.traccar.http;
import java.io.IOException;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-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.jboss.netty.util.Timeout;
-import org.jboss.netty.util.TimerTask;
import org.traccar.Context;
-import org.traccar.GlobalTimer;
-import org.traccar.database.DataCache;
-import org.traccar.helper.Log;
-import org.traccar.model.Position;
-public class MainServlet extends HttpServlet {
-
- public static final String USER_ID = "userId";
+public class MainServlet extends BaseServlet {
@Override
- protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
-
- String command = req.getPathInfo();
-
- if (command == null) {
- resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
- } else if (command.equals("/session")) {
+ 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 {
- resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
+ return false;
}
+ return true;
}
private void session(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().println("{ success: true, session: " + (req.getSession().getAttribute(USER_ID) != null) + " }");
}
- private void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- try {
- req.getSession().setAttribute(USER_ID,
- Context.getDataManager().login(req.getParameter("email"), req.getParameter("password")));
- resp.getWriter().println("{ success: true }");
- } catch (SQLException e) {
- throw new ServletException(e);
- }
+ private void login(HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ req.getSession().setAttribute(USER_ID, Context.getDataManager().login(
+ req.getParameter("email"), req.getParameter("password")));
+ sendResponse(resp.getWriter());
}
- private void logout(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ private void logout(HttpServletRequest req, HttpServletResponse resp) throws Exception {
req.getSession().removeAttribute(USER_ID);
- resp.getWriter().println("{ success: true }");
+ sendResponse(resp.getWriter());
}
}