Author: veithen
Date: Thu Mar 13 22:18:12 2014
New Revision: 1577348
URL: http://svn.apache.org/r1577348
Log:
AXIS2-5329:
* Remove the explicit invocation of OSGiConfigurationContextFactory#update and
instead let the config admin service do its job.
* Correctly handle the simultaneous dependency on ConfigurationContext and
HttpService for the registration of the OSGiAxisServlet: instead of tracking
the HttpService, we track the ConfigurationContext and register the servlet via
the HTTP whiteboard service.
Modified:
axis/axis2/java/core/trunk/modules/osgi-tests/pom.xml
axis/axis2/java/core/trunk/modules/osgi-tests/src/test/java/OSGiTest.java
axis/axis2/java/core/trunk/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
Modified: axis/axis2/java/core/trunk/modules/osgi-tests/pom.xml
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/osgi-tests/pom.xml?rev=1577348&r1=1577347&r2=1577348&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/osgi-tests/pom.xml (original)
+++ axis/axis2/java/core/trunk/modules/osgi-tests/pom.xml Thu Mar 13 22:18:12
2014
@@ -123,6 +123,16 @@
<version>2.2.2</version>
</artifact>
<artifact>
+ <groupId>org.apache.felix</groupId>
+
<artifactId>org.apache.felix.http.whiteboard</artifactId>
+ <version>2.2.2</version>
+ </artifact>
+ <artifact>
+ <groupId>org.apache.felix</groupId>
+
<artifactId>org.apache.felix.configadmin</artifactId>
+ <version>1.8.0</version>
+ </artifact>
+ <artifact>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.wsdl4j</artifactId>
<version>1.6.2_6</version>
Modified:
axis/axis2/java/core/trunk/modules/osgi-tests/src/test/java/OSGiTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/osgi-tests/src/test/java/OSGiTest.java?rev=1577348&r1=1577347&r2=1577348&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/osgi-tests/src/test/java/OSGiTest.java
(original)
+++ axis/axis2/java/core/trunk/modules/osgi-tests/src/test/java/OSGiTest.java
Thu Mar 13 22:18:12 2014
@@ -50,6 +50,7 @@ public class OSGiTest {
ExamSystem system = DefaultExamSystem.create(options(
url("link:classpath:META-INF/links/org.ops4j.pax.logging.api.link"),
url("link:classpath:META-INF/links/org.osgi.compendium.link"),
+ url("link:classpath:org.apache.felix.configadmin.link"),
url("link:classpath:org.apache.servicemix.bundles.wsdl4j.link"),
url("link:classpath:org.apache.geronimo.specs.geronimo-activation_1.1_spec.link"),
// TODO: should not be necessary on Java 6
url("link:classpath:org.apache.geronimo.specs.geronimo-jms_1.1_spec.link"), //
TODO: why the heck is this required???
@@ -73,6 +74,7 @@ public class OSGiTest {
url("link:classpath:org.apache.woden.core.link"),
url("link:classpath:org.apache.ws.xmlschema.core.link"),
url("link:classpath:org.apache.felix.http.jetty.link"),
+ url("link:classpath:org.apache.felix.http.whiteboard.link"),
url("link:classpath:org.apache.axis2.osgi.link"),
provision(bundle()
.add(Handler1.class)
Modified:
axis/axis2/java/core/trunk/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java?rev=1577348&r1=1577347&r2=1577348&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
(original)
+++
axis/axis2/java/core/trunk/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
Thu Mar 13 22:18:12 2014
@@ -15,18 +15,20 @@
*/
package org.apache.axis2.osgi.internal;
+import java.util.Hashtable;
+
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.osgi.OSGiAxisServlet;
+
import static
org.apache.axis2.osgi.deployment.OSGiAxis2Constants.AXIS2_OSGi_ROOT_CONTEXT;
+
import org.apache.axis2.osgi.deployment.OSGiConfigurationContextFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.*;
-import org.osgi.service.http.HttpService;
-import org.osgi.service.http.NamespaceException;
import org.osgi.util.tracker.ServiceTracker;
-import javax.servlet.ServletException;
+import javax.servlet.Servlet;
/**
* Activator will set the necessary parameters that initiate Axis2 OSGi
integration
@@ -35,7 +37,7 @@ public class Activator implements Bundle
private static Log log = LogFactory.getLog(Activator.class);
- private HttpServiceTracker tracker;
+ private ConfigurationContextTracker tracker;
private final OSGiConfigurationContextFactory managedService;
@@ -45,61 +47,49 @@ public class Activator implements Bundle
public void start(BundleContext context) throws Exception {
managedService.start(context);
- managedService.updated(null);
- tracker = new HttpServiceTracker(context);
+ tracker = new ConfigurationContextTracker(context);
tracker.open();
}
public void stop(BundleContext context) {
tracker.close();
managedService.stop();
- //ungetService ConfigurationContext.class.getName()
- ServiceReference configCtxRef =
-
context.getServiceReference(ConfigurationContext.class.getName());
- if (configCtxRef != null) {
- context.ungetService(configCtxRef);
- }
}
- //HttpServiceTracker
-
- class HttpServiceTracker extends ServiceTracker {
+ class ConfigurationContextTracker extends ServiceTracker {
- public HttpServiceTracker(BundleContext context) {
- super(context, HttpService.class.getName(), null);
+ public ConfigurationContextTracker(BundleContext context) {
+ super(context, ConfigurationContext.class.getName(), null);
}
public Object addingService(ServiceReference serviceReference) {
- HttpService httpService = (HttpService)
context.getService(serviceReference);
- try {
- ServiceReference configCtxRef =
-
context.getServiceReference(ConfigurationContext.class.getName());
- ConfigurationContext configCtx =
- (ConfigurationContext)
context.getService(configCtxRef);
- OSGiAxisServlet axisServlet = new OSGiAxisServlet(configCtx);
- String propServiceContextRoot =
context.getProperty(AXIS2_OSGi_ROOT_CONTEXT);
- String serviceContextRoot = "services";
- if (propServiceContextRoot != null &&
propServiceContextRoot.length() != 0) {
- if (propServiceContextRoot.startsWith("/")) {
- serviceContextRoot =
propServiceContextRoot.substring(1);
- } else {
- serviceContextRoot = propServiceContextRoot;
- }
+ ConfigurationContext configCtx = (ConfigurationContext)
context.getService(serviceReference);
+ OSGiAxisServlet axisServlet = new OSGiAxisServlet(configCtx);
+ String propServiceContextRoot =
context.getProperty(AXIS2_OSGi_ROOT_CONTEXT);
+ String serviceContextRoot = "services";
+ if (propServiceContextRoot != null &&
propServiceContextRoot.length() != 0) {
+ if (propServiceContextRoot.startsWith("/")) {
+ serviceContextRoot = propServiceContextRoot.substring(1);
+ } else {
+ serviceContextRoot = propServiceContextRoot;
}
- configCtx.setServicePath(serviceContextRoot);
- String contextRoot = "/" + serviceContextRoot;
- log.info("Registering SOAP message listener servlet to context
: " + contextRoot);
- httpService.registerServlet(contextRoot, axisServlet, null,
null);
- } catch (ServletException e) {
- String msg = "Error while registering servlets";
- log.error(msg, e);
- } catch (NamespaceException e) {
- String msg = "Namespace missmatch when registering servlets";
- log.error(msg, e);
}
- return httpService;
+ configCtx.setServicePath(serviceContextRoot);
+ String contextRoot = "/" + serviceContextRoot;
+ log.info("Registering SOAP message listener servlet to context : "
+ contextRoot);
+ Hashtable props = new Hashtable();
+ props.put("alias", contextRoot);
+ // Register the servlet as an OSGi service to be picked up by the
HTTP whiteboard service.
+ // We return the ServiceRegistration so that we can unregister the
servlet later.
+ return context.registerService(Servlet.class.getName(),
axisServlet, props);
}
+ @Override
+ public void removedService(ServiceReference reference, Object service)
{
+ // Unregister the servlet and unget the reference to the
ConfigurationContext.
+ ((ServiceRegistration)service).unregister();
+ context.ungetService(reference);
+ }
}
}