1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springbyexample.cometd.continuation;
18
19 import java.util.Map;
20
21 import javax.servlet.ServletException;
22
23 import org.mortbay.cometd.AbstractBayeux;
24 import org.mortbay.cometd.continuation.ContinuationCometdServlet;
25 import org.springframework.web.context.support.WebApplicationContextUtils;
26
27
28
29
30
31
32
33
34
35
36 public class SpringContinuationCometdServlet extends ContinuationCometdServlet {
37
38 private static final long serialVersionUID = 6186673799799707142L;
39
40
41
42
43
44
45
46
47
48
49
50 @Override
51 @SuppressWarnings("unchecked")
52 public void init() throws ServletException {
53 synchronized (SpringContinuationCometdServlet.class) {
54 Map<String, AbstractBayeux> hBayeuxBeans = (Map<String, AbstractBayeux>)WebApplicationContextUtils.getWebApplicationContext(getServletContext()).getBeansOfType(AbstractBayeux.class);
55
56 if (hBayeuxBeans == null || hBayeuxBeans.size() != 1) {
57 throw new ServletException("Unable to find a unique Spring bean of the type AbstractBayeux.");
58 }
59
60 for (AbstractBayeux bayeux : hBayeuxBeans.values()) {
61 _bayeux = bayeux;
62 break;
63 }
64 }
65
66 String async = getInitParameter("asyncDeliver");
67
68 if (async!=null) {
69 _asyncDeliver = Boolean.parseBoolean(async);
70 }
71 }
72
73 }