|
55 | 55 | import org.jupnp.transport.spi.StreamClientConfiguration;
|
56 | 56 | import org.jupnp.transport.spi.StreamServer;
|
57 | 57 | import org.osgi.framework.BundleContext;
|
58 |
| -import org.osgi.framework.ServiceReference; |
59 | 58 | import org.osgi.service.component.annotations.Activate;
|
60 | 59 | import org.osgi.service.component.annotations.Component;
|
61 | 60 | import org.osgi.service.component.annotations.ConfigurationPolicy;
|
|
87 | 86 | * @author Kai Kreuzer - introduced bounded thread pool and http service streaming server
|
88 | 87 | * @author Victor Toni - consolidated transport abstraction into one interface
|
89 | 88 | * @author Wouter Born - conditionally enable component based on autoEnable configuration value
|
| 89 | + * @author Laurent Garnier - do not release the OSGi HttpService |
90 | 90 | */
|
91 | 91 | @Component(configurationPid = "org.jupnp", configurationPolicy = ConfigurationPolicy.REQUIRE, enabled = false)
|
92 | 92 | public class OSGiUpnpServiceConfiguration implements UpnpServiceConfiguration {
|
@@ -122,16 +122,15 @@ public class OSGiUpnpServiceConfiguration implements UpnpServiceConfiguration {
|
122 | 122 |
|
123 | 123 | protected BundleContext context;
|
124 | 124 |
|
125 |
| - @SuppressWarnings("rawtypes") |
126 |
| - protected ServiceReference httpServiceReference; |
127 |
| - |
128 | 125 | @SuppressWarnings("rawtypes")
|
129 | 126 | protected TransportConfiguration transportConfiguration;
|
130 | 127 |
|
131 | 128 | protected Integer timeoutSeconds = 10;
|
132 | 129 | protected Integer retryIterations = 5;
|
133 | 130 | protected Integer retryAfterSeconds = (int) TimeUnit.MINUTES.toSeconds(10);
|
134 | 131 |
|
| 132 | + protected HttpService httpService; |
| 133 | + |
135 | 134 | /**
|
136 | 135 | * Defaults to port '0', ephemeral.
|
137 | 136 | */
|
@@ -185,15 +184,14 @@ protected void activate(BundleContext context, Map<String, Object> configProps)
|
185 | 184 |
|
186 | 185 | @Deactivate
|
187 | 186 | protected void deactivate() {
|
188 |
| - if (httpServiceReference != null) { |
189 |
| - context.ungetService(httpServiceReference); |
190 |
| - } |
191 |
| - |
192 | 187 | shutdown();
|
193 |
| - |
194 | 188 | logger.debug("{} deactivated", this);
|
195 | 189 | }
|
196 | 190 |
|
| 191 | + protected void setHttpService(HttpService httpService) { |
| 192 | + this.httpService = httpService; |
| 193 | + } |
| 194 | + |
197 | 195 | @Override
|
198 | 196 | public DatagramProcessor getDatagramProcessor() {
|
199 | 197 | return datagramProcessor;
|
@@ -237,25 +235,14 @@ public DatagramIO createDatagramIO(NetworkAddressFactory networkAddressFactory)
|
237 | 235 | @Override
|
238 | 236 | @SuppressWarnings({ "rawtypes", "unchecked" })
|
239 | 237 | public StreamServer createStreamServer(NetworkAddressFactory networkAddressFactory) {
|
240 |
| - ServiceReference serviceReference = context.getServiceReference(HttpService.class.getName()); |
241 |
| - |
242 |
| - if (serviceReference != null) { |
243 |
| - |
244 |
| - if (httpServiceReference != null) { |
245 |
| - context.ungetService(httpServiceReference); |
246 |
| - } |
247 |
| - |
248 |
| - httpServiceReference = serviceReference; |
249 |
| - |
250 |
| - HttpService httpService = (HttpService) context.getService(serviceReference); |
251 |
| - |
252 |
| - if (httpService != null) { |
253 |
| - return new ServletStreamServerImpl(new ServletStreamServerConfigurationImpl( |
254 |
| - HttpServiceServletContainerAdapter.getInstance(httpService, context), |
255 |
| - httpProxyPort != -1 ? httpProxyPort : callbackURI.getBasePath().getPort())); |
256 |
| - } |
| 238 | + if (httpService != null) { |
| 239 | + logger.debug("createStreamServer using OSGi HttpService"); |
| 240 | + return new ServletStreamServerImpl(new ServletStreamServerConfigurationImpl( |
| 241 | + HttpServiceServletContainerAdapter.getInstance(httpService, context), |
| 242 | + httpProxyPort != -1 ? httpProxyPort : callbackURI.getBasePath().getPort())); |
257 | 243 | }
|
258 | 244 |
|
| 245 | + logger.debug("createStreamServer without OSGi HttpService"); |
259 | 246 | return transportConfiguration.createStreamServer(networkAddressFactory.getStreamListenPort());
|
260 | 247 | }
|
261 | 248 |
|
|
0 commit comments