FELIX-1978 Register the ManagedService as a service factory and dynamically import Configuration Admin API. This allows to start Jetty without Configuration Admin but to still receive configuration once the Configuration Admin service is providing configuration
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1056882 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/jetty/pom.xml b/http/jetty/pom.xml
index e900085..129f986 100644
--- a/http/jetty/pom.xml
+++ b/http/jetty/pom.xml
@@ -57,6 +57,9 @@
org.slf4j;resolution:=optional,
*;resolution:=optional
</Import-Package>
+ <DynamicImport-Package>
+ org.osgi.service.cm;version=1.2
+ </DynamicImport-Package>
</instructions>
</configuration>
</plugin>
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedService.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedService.java
new file mode 100644
index 0000000..28bacd4
--- /dev/null
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedService.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.http.jetty.internal;
+
+import java.util.Dictionary;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ManagedService;
+
+public class JettyManagedService implements ServiceFactory
+{
+
+ private final JettyService jettyService;
+
+ JettyManagedService(final JettyService jettyService)
+ {
+ this.jettyService = jettyService;
+ }
+
+ public Object getService(Bundle bundle, ServiceRegistration registration)
+ {
+ return new ManagedService()
+ {
+ public void updated(Dictionary properties)
+ {
+ jettyService.updated(properties);
+ }
+ };
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
+ {
+ // just have the reference dropped, nothing to cleanup
+ }
+
+}
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
index 14681a0..9181ea6 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
@@ -16,8 +16,6 @@
*/
package org.apache.felix.http.jetty.internal;
-import org.osgi.service.cm.ManagedService;
-import org.osgi.service.cm.ConfigurationException;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
@@ -38,7 +36,7 @@
import java.util.Hashtable;
public final class JettyService
- implements ManagedService, Runnable
+ implements Runnable
{
/** PID for configuration of the HTTP service. */
private static final String PID = "org.apache.felix.http";
@@ -67,7 +65,8 @@
Properties props = new Properties();
props.put(Constants.SERVICE_PID, PID);
- this.configServiceReg = this.context.registerService(ManagedService.class.getName(), this, props);
+ this.configServiceReg = this.context.registerService("org.osgi.service.cm.ManagedService",
+ new JettyManagedService(this), props);
this.thread = new Thread(this, "Jetty HTTP Service");
this.thread.start();
@@ -98,7 +97,6 @@
}
public void updated(Dictionary props)
- throws ConfigurationException
{
this.config.update(props);