moto web application
修訂 | 2dd62314104889a981c474da54dd46a35c83f201 (tree) |
---|---|
時間 | 2014-02-04 10:49:38 |
作者 | astoria-d <astoria-d@mail...> |
Commiter | astoria-d |
comet session check added
@@ -0,0 +1,38 @@ | ||
1 | +package motoSample; | |
2 | + | |
3 | +import org.atmosphere.cpr.PerRequestBroadcastFilter; | |
4 | +import org.atmosphere.cpr.BroadcastFilter.BroadcastAction; | |
5 | +import org.atmosphere.cpr.AtmosphereResource; | |
6 | + | |
7 | +import org.slf4j.Logger; | |
8 | +import org.slf4j.LoggerFactory; | |
9 | +import javax.servlet.http.HttpSession; | |
10 | + | |
11 | + | |
12 | +public class AtmosFilter implements PerRequestBroadcastFilter { | |
13 | + private final Logger logger = LoggerFactory.getLogger(AtmosFilter.class); | |
14 | + | |
15 | + @Override | |
16 | + public BroadcastAction filter(AtmosphereResource atmosphereResource, Object originalMessage, Object message) { | |
17 | + HttpSession session = atmosphereResource.session(); | |
18 | + | |
19 | + if (session == null) { | |
20 | + logger.info("session expired."); | |
21 | + return new BroadcastAction(BroadcastAction.ACTION.ABORT, message); | |
22 | + } | |
23 | + | |
24 | + UserBean ubean = (UserBean)session.getAttribute("userBean"); | |
25 | + if (ubean == null || !ubean.isLoggedIn()) { | |
26 | + logger.info("login required."); | |
27 | + return new BroadcastAction(BroadcastAction.ACTION.ABORT, message); | |
28 | + } | |
29 | + | |
30 | + //logger.info("atmos filter ok."); | |
31 | + return new BroadcastAction(message); | |
32 | + } | |
33 | + | |
34 | + @Override | |
35 | + public BroadcastAction filter(Object originalMessage, Object message) { | |
36 | + return new BroadcastAction(message); | |
37 | + } | |
38 | +} |
@@ -53,10 +53,20 @@ | ||
53 | 53 | <!-- Use it with mvn jetty:run --> |
54 | 54 | <load-on-startup>0</load-on-startup> |
55 | 55 | <async-supported>true</async-supported> |
56 | + | |
57 | + <!-- atmosphere filter mapping. --> | |
58 | + <init-param> | |
59 | + <param-name>org.atmosphere.cpr.sessionSupport</param-name> | |
60 | + <param-value>true</param-value> | |
61 | + </init-param> | |
62 | + <init-param> | |
63 | + <param-name>org.atmosphere.cpr.broadcastFilterClasses</param-name> | |
64 | + <param-value>motoSample.AtmosFilter</param-value> | |
65 | + </init-param> | |
66 | + | |
56 | 67 | </servlet> |
57 | 68 | <servlet-mapping> |
58 | 69 | <servlet-name>AtmosphereServlet</servlet-name> |
59 | 70 | <url-pattern>/chat/*</url-pattern> |
60 | 71 | </servlet-mapping> |
61 | - | |
62 | -</web-app> | |
72 | + </web-app> |