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