1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.osgi.equinoxtools;
20
21 import javax.servlet.ServletException;
22
23 import org.eclipse.jetty.osgi.equinoxtools.console.EquinoxChattingSupport;
24 import org.eclipse.jetty.osgi.equinoxtools.console.EquinoxConsoleContinuationServlet;
25 import org.eclipse.jetty.osgi.equinoxtools.console.EquinoxConsoleSyncServlet;
26 import org.eclipse.jetty.osgi.equinoxtools.console.EquinoxConsoleWebSocketServlet;
27 import org.eclipse.jetty.osgi.equinoxtools.console.WebConsoleSession;
28 import org.eclipse.jetty.util.log.Log;
29 import org.eclipse.jetty.util.log.Logger;
30 import org.eclipse.osgi.framework.console.ConsoleSession;
31 import org.osgi.framework.BundleActivator;
32 import org.osgi.framework.BundleContext;
33 import org.osgi.framework.ServiceReference;
34 import org.osgi.service.http.HttpService;
35 import org.osgi.service.http.NamespaceException;
36 import org.osgi.util.tracker.ServiceTracker;
37 import org.osgi.util.tracker.ServiceTrackerCustomizer;
38
39
40
41
42 public class WebEquinoxToolsActivator implements BundleActivator
43 {
44 private static final Logger LOG = Log.getLogger(WebEquinoxToolsActivator.class);
45
46
47 private static BundleContext context;
48 public static BundleContext getContext()
49 {
50 return context;
51 }
52
53 private HttpService _httpService;
54 private ServiceTracker _tracker;
55 private EquinoxChattingSupport _equinoxChattingSupport;
56
57
58
59
60
61
62
63 public void start(BundleContext bundleContext) throws Exception
64 {
65 WebEquinoxToolsActivator.context = bundleContext;
66
67 ServiceTrackerCustomizer httpServiceTrackerCustomizer = new ServiceTrackerCustomizer()
68 {
69 public void removedService(ServiceReference reference, Object service)
70 {
71 _httpService = null;
72 }
73
74 public void modifiedService(ServiceReference reference, Object service)
75 {
76 _httpService = (HttpService)context.getService(reference);
77 }
78
79 public Object addingService(ServiceReference reference)
80 {
81 _httpService = (HttpService)context.getService(reference);
82 try
83 {
84
85
86
87
88
89
90 _httpService.registerResources("/equinoxconsole/ws/index.html","/equinoxconsole/ws/index.html",null);
91 _httpService.registerServlet("/equinoxconsole/ws",new EquinoxConsoleWebSocketServlet(
92
93
94
95
96
97 _httpService.registerResources("/equinoxconsole/index.html","/equinoxconsole/index.html",null);
98 _httpService.registerServlet("/equinoxconsole",new EquinoxConsoleContinuationServlet(
99
100
101 WebConsoleSession syncSession = new WebConsoleSession();
102 WebEquinoxToolsActivator.context.registerService(ConsoleSession.class.getName(), syncSession, null);
103 _httpService.registerServlet("/equinoxconsole/sync",new EquinoxConsoleSyncServlet(syncSession),null,null);
104 }
105 catch (ServletException e)
106 {
107 LOG.warn(e);
108 }
109 catch (NamespaceException e)
110 {
111 LOG.warn(e);
112 }
113 return _httpService;
114 }
115 };
116
117 _tracker = new ServiceTracker(context,HttpService.class.getName(),httpServiceTrackerCustomizer);
118 _tracker.open();
119 }
120
121
122
123
124
125
126 public void stop(BundleContext bundleContext) throws Exception
127 {
128 _tracker.close();
129 WebEquinoxToolsActivator.context = null;
130 }
131
132
133 }