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 System.err.println("INIT "+config);
71 _config=config;
72
73 Bayeux bayeux = (Bayeux)config.getServletContext().getAttribute(Bayeux.ATTRIBUTE);
74 if (bayeux==null)
75 {
76 _config.getServletContext().log("No "+Bayeux.ATTRIBUTE+" initialized");
77 throw new UnavailableException(Bayeux.ATTRIBUTE);
78 }
79
80 String url=_config.getInitParameter(Oort.OORT_URL);
81 if (url==null)
82 {
83 _config.getServletContext().log("No "+Oort.OORT_URL+" init parameter");
84 throw new UnavailableException(Oort.OORT_URL);
85 }
86
87 Oort oort= new Oort(url,bayeux);
88 _config.getServletContext().setAttribute(Oort.OORT_ATTRIBUTE,oort);
89
90 String channels=_config.getInitParameter(Oort.OORT_CHANNELS);
91 if (channels!=null)
92 {
93 String[] patterns=channels.split("[, ]");
94 for (String channel : patterns)
95 oort.observeChannel(channel);
96
97 }
98
99 try
100 {
101 oort.start();
102 }
103 catch(Exception e)
104 {
105 throw new ServletException(e);
106 }
107
108 String cloud = _config.getInitParameter(Oort.OORT_CLOUD);
109 if (cloud!=null)
110 {
111 String[] urls=cloud.split("[, ]");
112 for (String comet : urls)
113 oort.observeComet(comet);
114
115 }
116 }
117
118 public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
119 {
120 HttpServletResponse response = (HttpServletResponse)res;
121 response.sendError(503);
122 }
123 }