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