You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2014/05/15 00:48:22 UTC
svn commit: r1594748 - in /axis/axis2/java/core/branches/1_6: ./
modules/osgi-tests/ modules/osgi-tests/src/test/java/
modules/osgi-tests/src/test/java/org/
modules/osgi-tests/src/test/java/org/apache/axis2/osgi/module/
modules/osgi-tests/src/test/reso...
Author: veithen
Date: Wed May 14 22:48:21 2014
New Revision: 1594748
URL: http://svn.apache.org/r1594748
Log:
Merged the changes for AXIS2-4847 / AXIS2-5329 to the 1.6 branch.
Added:
axis/axis2/java/core/branches/1_6/modules/osgi-tests/
- copied from r1576937, axis/axis2/java/core/trunk/modules/osgi-tests/
axis/axis2/java/core/branches/1_6/modules/osgi-tests/src/test/java/org/
- copied from r1577119, axis/axis2/java/core/trunk/modules/osgi-tests/src/test/java/org/
axis/axis2/java/core/branches/1_6/modules/osgi-tests/src/test/java/org/apache/axis2/osgi/module/
- copied from r1577125, axis/axis2/java/core/trunk/modules/osgi-tests/src/test/java/org/apache/axis2/osgi/module/
axis/axis2/java/core/branches/1_6/modules/osgi-tests/src/test/resources/
- copied from r1577119, axis/axis2/java/core/trunk/modules/osgi-tests/src/test/resources/
axis/axis2/java/core/branches/1_6/modules/osgi-tests/src/test/resources/META-INF/module.xml
- copied unchanged from r1577125, axis/axis2/java/core/trunk/modules/osgi-tests/src/test/resources/META-INF/module.xml
Modified:
axis/axis2/java/core/branches/1_6/ (props changed)
axis/axis2/java/core/branches/1_6/modules/osgi-tests/pom.xml
axis/axis2/java/core/branches/1_6/modules/osgi-tests/src/test/java/OSGiTest.java
axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/OSGiAxisServlet.java
axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiServerConfigurator.java
axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
axis/axis2/java/core/branches/1_6/pom.xml
Propchange: axis/axis2/java/core/branches/1_6/
------------------------------------------------------------------------------
Merged /axis/axis2/java/core/trunk:r1576937,1577055,1577119,1577125,1577191,1577342-1577345,1577347-1577348
Modified: axis/axis2/java/core/branches/1_6/modules/osgi-tests/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/osgi-tests/pom.xml?rev=1594748&r1=1576937&r2=1594748&view=diff
==============================================================================
--- axis/axis2/java/core/branches/1_6/modules/osgi-tests/pom.xml (original)
+++ axis/axis2/java/core/branches/1_6/modules/osgi-tests/pom.xml Wed May 14 22:48:21 2014
@@ -21,7 +21,7 @@
<parent>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-parent</artifactId>
- <version>1.7.0-SNAPSHOT</version>
+ <version>1.6.3-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -39,7 +39,7 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>axis2-kernel</artifactId>
+ <artifactId>org.apache.axis2.osgi</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
@@ -76,22 +76,14 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-junit4</artifactId>
- <version>${exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-atinject_1.0_spec</artifactId>
- <version>1.0</version>
- <scope>test</scope>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axis2-testutils</artifactId>
+ <version>${project.version}</version>
</dependency>
</dependencies>
<pluginRepositories>
@@ -126,9 +118,19 @@
</dependencySet>
<artifacts>
<artifact>
- <groupId>${project.groupId}</groupId>
- <artifactId>org.apache.axis2.osgi</artifactId>
- <version>${project.version}</version>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.http.jetty</artifactId>
+ <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>
@@ -170,6 +172,11 @@
<artifactId>httpclient-osgi</artifactId>
<version>4.2.1</version>
</artifact>
+ <artifact>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.1</version>
+ </artifact>
</artifacts>
<paxExam>${exam.version}</paxExam>
</configuration>
Modified: axis/axis2/java/core/branches/1_6/modules/osgi-tests/src/test/java/OSGiTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/osgi-tests/src/test/java/OSGiTest.java?rev=1594748&r1=1576937&r2=1594748&view=diff
==============================================================================
--- axis/axis2/java/core/branches/1_6/modules/osgi-tests/src/test/java/OSGiTest.java (original)
+++ axis/axis2/java/core/branches/1_6/modules/osgi-tests/src/test/java/OSGiTest.java Wed May 14 22:48:21 2014
@@ -16,30 +16,41 @@
* specific language governing permissions and limitations
* under the License.
*/
-import static org.junit.Assert.assertTrue;
-import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.junit.Assert.assertEquals;
+import static org.ops4j.pax.exam.CoreOptions.frameworkProperty;
import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
import static org.ops4j.pax.exam.CoreOptions.url;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
-import javax.inject.Inject;
-
-import org.junit.Assert;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.osgi.module.Handler1;
+import org.apache.axis2.osgi.module.Handler2;
+import org.apache.axis2.osgi.module.SimpleModule;
+import org.apache.axis2.osgi.service.Activator;
+import org.apache.axis2.osgi.service.Calculator;
+import org.apache.axis2.osgi.service.Version;
+import org.apache.axis2.testutils.PortAllocator;
+import org.apache.felix.framework.FrameworkFactory;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
+import org.ops4j.pax.exam.ExamSystem;
+import org.ops4j.pax.exam.nat.internal.NativeTestContainer;
+import org.ops4j.pax.exam.spi.DefaultExamSystem;
+import org.osgi.framework.Constants;
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
public class OSGiTest {
- @Configuration
- public static Option[] configuration() {
- return options(
+ @Test
+ public void test() throws Exception {
+ int httpPort = PortAllocator.allocatePort();
+ 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???
@@ -60,25 +71,43 @@ public class OSGiTest {
url("link:classpath:org.apache.httpcomponents.httpcore.link"),
url("link:classpath:org.apache.httpcomponents.httpclient.link"),
url("link:classpath:org.apache.neethi.link"),
- url("link:classpath:org.apache.woden.core.link"),
- url("link:classpath:org.apache.ws.xmlschema.core.link"),
+ url("link:classpath:org.apache.woden.woden-api.link"),
+ url("link:classpath:org.apache.woden.woden-impl-commons.link"),
+ url("link:classpath:org.apache.ws.commons.schema.XmlSchema.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"),
- junitBundles());
- }
-
- @Inject
- private BundleContext context;
-
- @Test
- public void test() {
- boolean found = false;
- for (Bundle bundle : context.getBundles()) {
- if (bundle.getSymbolicName().equals("org.apache.axis2.osgi")) {
- found = true;
- Assert.assertEquals(Bundle.ACTIVE, bundle.getState());
- break;
- }
+ provision(bundle()
+ .add(Handler1.class)
+ .add(Handler2.class)
+ .add(SimpleModule.class)
+ .add("META-INF/module.xml", OSGiTest.class.getResource("/META-INF/module.xml"))
+ .set(Constants.BUNDLE_SYMBOLICNAME, "simple.module")
+ .set(Constants.DYNAMICIMPORT_PACKAGE, "*")
+ .build()),
+ provision(bundle()
+ .add(Activator.class)
+ .add(Calculator.class)
+ .add(Version.class)
+ .add("META-INF/services.xml", OSGiTest.class.getResource("/META-INF/services.xml"))
+ .set(Constants.BUNDLE_SYMBOLICNAME, "version.service")
+ .set(Constants.BUNDLE_ACTIVATOR, Activator.class.getName())
+ .set(Constants.DYNAMICIMPORT_PACKAGE, "*")
+ .build()),
+ frameworkProperty("org.osgi.service.http.port").value(String.valueOf(httpPort))));
+ NativeTestContainer container = new NativeTestContainer(system, new FrameworkFactory());
+ container.start();
+ try {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement payload = factory.createOMElement("getVersion", factory.createOMNamespace("http://service.osgi.axis2.apache.org", "ns"));
+ Options options = new Options();
+ options.setTo(new EndpointReference("http://localhost:" + httpPort + "/services/Version"));
+ ServiceClient serviceClient = new ServiceClient();
+ serviceClient.setOptions(options);
+ OMElement result = serviceClient.sendReceive(payload);
+ assertEquals("getVersionResponse", result.getLocalName());
+ } finally {
+ container.stop();
}
- assertTrue(found);
}
}
Modified: axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/OSGiAxisServlet.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/OSGiAxisServlet.java?rev=1594748&r1=1594747&r2=1594748&view=diff
==============================================================================
--- axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/OSGiAxisServlet.java (original)
+++ axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/OSGiAxisServlet.java Wed May 14 22:48:21 2014
@@ -17,12 +17,7 @@ package org.apache.axis2.osgi;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.engine.AxisConfigurator;
-import org.apache.axis2.osgi.deployment.OSGiConfigurationContextFactory;
import org.apache.axis2.transport.http.AxisServlet;
-import org.apache.axis2.transport.http.ListingAgent;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
@@ -34,30 +29,25 @@ import javax.servlet.ServletException;
*/
public class OSGiAxisServlet extends AxisServlet {
- private BundleContext context;
+ private ConfigurationContext configurationContext;
- /**
- * OSGiAxisServlet needs an referenc to OSGi environmentb
- *
- * @param context BundleContext
- */
- public OSGiAxisServlet(BundleContext context) {
- this.context = context;
+ public OSGiAxisServlet(ConfigurationContext configurationContext) {
+ this.configurationContext = configurationContext;
}
+ @Override
+ protected ConfigurationContext initConfigContext(ServletConfig config) throws ServletException {
+ return configurationContext;
+ }
+
+ @Override
+ protected void initTransports() throws AxisFault {
+ // Not sure if this is correct, but the original OSGiAxisServlet code effectively skipped
+ // the invocation of the initTransports method.
+ }
public void init(ServletConfig servletConfig) throws ServletException {
- this.servletConfig = servletConfig;
- ServiceReference reference =
- context.getServiceReference(ConfigurationContext.class.getName());
- if (reference == null) {
- throw new ServletException(
- "An instance of ConfigurationContext is not available to continue the proccess.");
- }
- configContext = (ConfigurationContext) context.getService(reference);
- axisConfiguration = configContext.getAxisConfiguration();
- agent = new ListingAgent(configContext);
- initParams();
+ super.init(servletConfig);
ServletContext servletContext = servletConfig.getServletContext();
if (servletContext != null) {
servletContext.setAttribute(this.getClass().getName(), this);
Modified: axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiServerConfigurator.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiServerConfigurator.java?rev=1594748&r1=1594747&r2=1594748&view=diff
==============================================================================
--- axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiServerConfigurator.java (original)
+++ axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiServerConfigurator.java Wed May 14 22:48:21 2014
@@ -73,20 +73,32 @@ public class OSGiServerConfigurator exte
}
public AxisConfiguration populateAxisConfiguration(InputStream in) throws DeploymentException {
- axisConfig = new AxisConfiguration();
- AxisConfigBuilder builder =
- new AxisConfigBuilder(in, axisConfig, this);
- builder.populateConfig();
+ // Dirty hack necessary because class loading in AxisConfigBuilder is completely broken:
+ // although it is possible to configure the class loaders explicitly in the AxisConfiguration,
+ // the AxisConfigBuilder will still use the thread context class loader in some places.
+ // On the other hand, in an OSGi environment, the TCCL is not well defined. To avoid problems,
+ // we set it to the class loader of the Axis2 OSGi bundle.
+ Thread currentThread = Thread.currentThread();
+ ClassLoader savedTCCL = currentThread.getContextClassLoader();
+ currentThread.setContextClassLoader(OSGiServerConfigurator.class.getClassLoader());
try {
- if (in != null) {
- in.close();
+ axisConfig = new AxisConfiguration();
+ AxisConfigBuilder builder =
+ new AxisConfigBuilder(in, axisConfig, this);
+ builder.populateConfig();
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException e) {
+ String msg = "Error in closing input stream";
+ throw new DeploymentException(msg, e);
}
- } catch (IOException e) {
- String msg = "Error in closing input stream";
- throw new DeploymentException(msg, e);
+ //TODO: if module deployer neede to set it should be set here.
+ return axisConfig;
+ } finally {
+ currentThread.setContextClassLoader(savedTCCL);
}
- //TODO: if module deployer neede to set it should be set here.
- return axisConfig;
}
public void loadServices() {
Modified: axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java?rev=1594748&r1=1594747&r2=1594748&view=diff
==============================================================================
--- axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java (original)
+++ axis/axis2/java/core/branches/1_6/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java Wed May 14 22:48:21 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 {
- OSGiAxisServlet axisServlet = new OSGiAxisServlet(context);
- ServiceReference configCtxRef =
- context.getServiceReference(ConfigurationContext.class.getName());
- ConfigurationContext configCtx =
- (ConfigurationContext) context.getService(configCtxRef);
- 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);
+ }
}
}
Modified: axis/axis2/java/core/branches/1_6/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/pom.xml?rev=1594748&r1=1594747&r2=1594748&view=diff
==============================================================================
--- axis/axis2/java/core/branches/1_6/pom.xml (original)
+++ axis/axis2/java/core/branches/1_6/pom.xml Wed May 14 22:48:21 2014
@@ -80,6 +80,7 @@
<module>modules/clustering</module>
<module>modules/corba</module>
<module>modules/osgi</module>
+ <module>modules/osgi-tests</module>
<module>modules/transport/local</module>
<module>modules/transport/http</module>
<module>modules/transport/base</module>