1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.jmpeax.osgi.undertow.http;
19
20 import com.jmpeax.osgi.undertow.http.impl.UndertowHttpServer;
21 import com.jmpeax.osgi.undertow.http.impl.UndertowHttpService;
22 import org.osgi.framework.BundleActivator;
23 import org.osgi.framework.BundleContext;
24 import org.osgi.framework.ServiceRegistration;
25 import org.osgi.service.http.HttpService;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import java.io.IOException;
30 import java.util.Dictionary;
31 import java.util.Properties;
32
33
34
35
36
37
38 public class UndertowHttpServiceActivator implements BundleActivator {
39
40
41
42
43 private Logger log = LoggerFactory.getLogger(UndertowHttpServiceActivator.class);
44
45
46
47 private Dictionary<String, ?> configuration;
48 private ServiceRegistration<?> httpService;
49 private UndertowHttpServer server;
50
51 @Override
52 public void start(final BundleContext context) throws Exception {
53 defaults();
54 server = new UndertowHttpServer(configuration);
55 httpService = context.registerService(HttpService.class, new UndertowHttpService(server), null);
56 server.startServer();
57 }
58
59 @Override
60 public void stop(final BundleContext context) throws Exception {
61 if (httpService != null) {
62 log.debug("Unregister Http service");
63 httpService.unregister();
64 }
65 if (server != null) {
66 log.debug("Stopping Http Server");
67 server.stopServer();
68 }
69 }
70
71 private Dictionary defaults() throws IOException {
72 Properties properties = new Properties();
73 properties.load(getClass().getResourceAsStream("/undertow-defaults.properties"));
74 return properties;
75 }
76 }