aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/AsyncSocketServlet.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-12-15 14:24:35 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-12-15 14:24:35 +1300
commit44d38a8f121304fc6504ebaabbfb0a402779ca1d (patch)
treeb89d05f75c9df425d16c19cbd024aba525d0d24d /src/org/traccar/api/AsyncSocketServlet.java
parent08862079e544f2d501427fbb523ef28fc45fce75 (diff)
downloadtrackermap-server-44d38a8f121304fc6504ebaabbfb0a402779ca1d.tar.gz
trackermap-server-44d38a8f121304fc6504ebaabbfb0a402779ca1d.tar.bz2
trackermap-server-44d38a8f121304fc6504ebaabbfb0a402779ca1d.zip
Finish server side web sockets
Diffstat (limited to 'src/org/traccar/api/AsyncSocketServlet.java')
-rw-r--r--src/org/traccar/api/AsyncSocketServlet.java12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/org/traccar/api/AsyncSocketServlet.java b/src/org/traccar/api/AsyncSocketServlet.java
index 3b02bcfcd..59f0b7ee2 100644
--- a/src/org/traccar/api/AsyncSocketServlet.java
+++ b/src/org/traccar/api/AsyncSocketServlet.java
@@ -15,8 +15,12 @@
*/
package org.traccar.api;
+import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
+import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
+import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
+import org.traccar.api.resource.SessionResource;
public class AsyncSocketServlet extends WebSocketServlet {
@@ -25,7 +29,13 @@ public class AsyncSocketServlet extends WebSocketServlet {
@Override
public void configure(WebSocketServletFactory factory) {
factory.getPolicy().setIdleTimeout(ASYNC_TIMEOUT);
- factory.register(AsyncSocket.class);
+ factory.setCreator(new WebSocketCreator() {
+ @Override
+ public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) {
+ long userId = (Long) req.getSession().getAttribute(SessionResource.USER_ID_KEY);
+ return new AsyncSocket(userId);
+ }
+ });
}
}