1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.cometd.oort;
16
17
18 import java.io.IOException;
19
20 import javax.servlet.Servlet;
21 import javax.servlet.ServletConfig;
22 import javax.servlet.ServletException;
23 import javax.servlet.ServletRequest;
24 import javax.servlet.ServletResponse;
25 import javax.servlet.UnavailableException;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.cometd.Bayeux;
29 import org.mortbay.cometd.AbstractCometdServlet;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class OortServlet implements Servlet
51 {
52 private ServletConfig _config;
53
54 public void destroy()
55 {
56 }
57
58 public ServletConfig getServletConfig()
59 {
60 return _config;
61 }
62
63 public String getServletInfo()
64 {
65 return OortServlet.class.toString();
66 }
67
68 public void init(ServletConfig config) throws ServletException
69 {
70 _config=config;
71
72 Bayeux bayeux = (Bayeux)config.getServletContext().getAttribute(Bayeux.ATTRIBUTE);
73 if (bayeux==null)
74 {
75 _config.getServletContext().log("No "+Bayeux.ATTRIBUTE+" initialized");
76 throw new UnavailableException(Bayeux.ATTRIBUTE);
77 }
78
79 String url=_config.getInitParameter(Oort.OORT_URL);
80 if (url==null)
81 {
82 _config.getServletContext().log("No "+Oort.OORT_URL+" init parameter");
83 throw new UnavailableException(Oort.OORT_URL);
84 }
85
86 Oort oort= new Oort(url,bayeux);
87 _config.getServletContext().setAttribute(Oort.OORT_ATTRIBUTE,oort);
88
89 String channels=_config.getInitParameter(Oort.OORT_CHANNELS);
90 if (channels!=null)
91 {
92 String[] patterns=channels.split("[, ]");
93 for (String channel : patterns)
94 oort.observeChannel(channel);
95
96 }
97
98 try
99 {
100 oort.start();
101 }
102 catch(Exception e)
103 {
104 throw new ServletException(e);
105 }
106
107 String cloud = _config.getInitParameter(Oort.OORT_CLOUD);
108 if (cloud!=null)
109 {
110 String[] urls=cloud.split("[, ]");
111 for (String comet : urls)
112 oort.observeComet(comet);
113
114 }
115 }
116
117 public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
118 {
119 HttpServletResponse response = (HttpServletResponse)res;
120 response.sendError(503);
121 }
122 }