You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2008/06/18 12:35:12 UTC
svn commit: r669131 - in /webservices/axis2/trunk/java/modules/osgi: ./
resources/org/apache/axis2/osgi/deployment/ src/org/apache/axis2/osgi/
src/org/apache/axis2/osgi/deployment/ src/org/apache/axis2/osgi/internal/
Author: saminda
Date: Wed Jun 18 03:35:10 2008
New Revision: 669131
URL: http://svn.apache.org/viewvc?rev=669131&view=rev
Log:
AxisConfiguration will be created from a very minimal axis2.xml. Next step is to integrate listeners as OSGi services
and focusing on service/group/module deployment.
Added:
webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/InitServlet.java
webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/OSGiAxisServlet.java
webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java
Modified:
webservices/axis2/trunk/java/modules/osgi/pom.xml
webservices/axis2/trunk/java/modules/osgi/resources/org/apache/axis2/osgi/deployment/axis2.xml
webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiServerConfigurator.java
webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
Modified: webservices/axis2/trunk/java/modules/osgi/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/pom.xml?rev=669131&r1=669130&r2=669131&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/pom.xml (original)
+++ webservices/axis2/trunk/java/modules/osgi/pom.xml Wed Jun 18 03:35:10 2008
@@ -53,7 +53,7 @@
<instructions>
<Bundle-Version>1.0.0.${pom.version}</Bundle-Version>
<Bundle-Name>${pom.artifactId}</Bundle-Name>
- <Bundle-Vendor>WSO2 Inc</Bundle-Vendor>
+ <Bundle-Vendor>Apache Axis2, 2008</Bundle-Vendor>
<Bundle-Description>${pom.description}</Bundle-Description>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
<Export-Package>
@@ -65,7 +65,9 @@
!org.apache.axis2.*,
javax.servlet; version=2.4.0,
javax.servlet.http; version=2.4.0,
- org.osgi.framework;version=1.3.0,
+ org.osgi.framework; version=1.3.0,
+ org.osgi.service.http; version=1.2.0,
+ org.osgi.util.tracker; version=1.3.1,
*;resolution:=optional
</Import-Package>
<Private-Package>
@@ -75,7 +77,8 @@
org.apache.axis2.osgi.internal.Activator
</Bundle-Activator>
<Export-Service>
- org.apache.axis2.engine.AxisConfiguration
+ org.apache.axis2.engine.AxisConfiguration,
+ org.apache.axis2.context.ConfigurationContext
</Export-Service>
</instructions>
</configuration>
Modified: webservices/axis2/trunk/java/modules/osgi/resources/org/apache/axis2/osgi/deployment/axis2.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/resources/org/apache/axis2/osgi/deployment/axis2.xml?rev=669131&r1=669130&r2=669131&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/resources/org/apache/axis2/osgi/deployment/axis2.xml (original)
+++ webservices/axis2/trunk/java/modules/osgi/resources/org/apache/axis2/osgi/deployment/axis2.xml Wed Jun 18 03:35:10 2008
@@ -73,7 +73,7 @@
<!--Our HTTP endpoints can handle both REST and SOAP. Following parameters can be used to distinguiush those endpoints-->
<!--In case of a servlet, if you change this you have to manually change the settings of your servlet container to map this -->
<!--context path to proper Axis2 servlets-->
- <!--<parameter name="servicePath">services</parameter>-->
+ <parameter name="servicePath">services</parameter>
<!--<parameter name="restPath">rest</parameter>-->
<!-- Following parameter will completely disable REST handling in Axis2-->
Added: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/InitServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/InitServlet.java?rev=669131&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/InitServlet.java (added)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/InitServlet.java Wed Jun 18 03:35:10 2008
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.axis2.osgi;
+
+import org.apache.axis2.engine.AxisConfigurator;
+import org.apache.axis2.osgi.deployment.OSGiServerConfigurator;
+import org.apache.axis2.osgi.deployment.OSGiConfigurationContextFactory;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.AxisFault;
+import org.osgi.framework.BundleContext;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletContext;
+
+/**
+ * InitServlet is used only to initialize Axis2 environment
+ * and it's meant not to listen to any request.
+ */
+public class InitServlet extends HttpServlet{
+
+ private BundleContext context;
+
+ public InitServlet(BundleContext context) {
+ this.context = context;
+ }
+
+ public void init(ServletConfig servletConfig) throws ServletException {
+ super.init(servletConfig);
+ AxisConfigurator configurator = new OSGiServerConfigurator(context);
+ try {
+ ConfigurationContext configCtx = OSGiConfigurationContextFactory
+ .createConfigurationContext(configurator, context);
+ //regiser the ConfigurationContext as an service.
+ context.registerService(ConfigurationContext.class.getName(), configCtx, null);
+ } catch (AxisFault e) {
+ String msg = "Error while creating the ConfigurationContext";
+ throw new ServletException(msg, e);
+ }
+
+ }
+}
Added: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/OSGiAxisServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/OSGiAxisServlet.java?rev=669131&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/OSGiAxisServlet.java (added)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/OSGiAxisServlet.java Wed Jun 18 03:35:10 2008
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.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.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+/**
+ * This servlet is used with the association of HttpService.
+ * This is the entry point to all requests.
+ */
+public class OSGiAxisServlet extends AxisServlet {
+
+ private BundleContext context;
+
+ /**
+ * OSGiAxisServlet needs an referenc to OSGi environmentb
+ *
+ * @param context BundleContext
+ */
+ public OSGiAxisServlet(BundleContext context) {
+ this.context = context;
+ }
+
+
+ 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();
+ initParams();
+ ServletContext servletContext = servletConfig.getServletContext();
+ if (servletContext != null) {
+ servletContext.setAttribute(this.getClass().getName(), this);
+ }
+
+ }
+}
Added: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java?rev=669131&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java (added)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java Wed Jun 18 03:35:10 2008
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.axis2.osgi.deployment;
+
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.engine.AxisConfigurator;
+import org.apache.axis2.AxisFault;
+import org.osgi.framework.BundleContext;
+
+/**
+ *
+ */
+public class OSGiConfigurationContextFactory {
+
+ public static ConfigurationContext createConfigurationContext(
+ AxisConfigurator axisConfigurator, BundleContext context) throws AxisFault {
+ ConfigurationContext configCtx =
+ ConfigurationContextFactory.createConfigurationContext(axisConfigurator);
+ //TODO: TBD, add service, module listeners
+ return configCtx;
+
+ }
+
+
+}
Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiServerConfigurator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiServerConfigurator.java?rev=669131&r1=669130&r2=669131&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiServerConfigurator.java (original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiServerConfigurator.java Wed Jun 18 03:35:10 2008
@@ -41,7 +41,7 @@
public OSGiServerConfigurator(BundleContext context) {
this.context = context;
Enumeration entries = this.context.getBundle()
- .findEntries("org/apache/axis2.osgi/deployment", "axis2.xml", false);
+ .findEntries("org/apache/axis2/osgi/deployment", "axis2.xml", false);
if (entries != null && entries.hasMoreElements()) {
axis2XmlUrl = (URL)entries.nextElement();
}
@@ -89,4 +89,8 @@
context.registerService(AxisConfiguration.class.getName(), axisConfig, null);
return axisConfig;
}
+
+ public void loadServices() {
+ //TODO; TBD
+ }
}
Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java?rev=669131&r1=669130&r2=669131&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java (original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java Wed Jun 18 03:35:10 2008
@@ -15,21 +15,85 @@
*/
package org.apache.axis2.osgi.internal;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.engine.AxisConfigurator;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.osgi.InitServlet;
+import org.apache.axis2.osgi.OSGiAxisServlet;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+import org.osgi.util.tracker.ServiceTracker;
+
+import javax.servlet.ServletException;
/**
* Activator will set the necessary parameters that initiate Axis2 OSGi integration
- * TODO: TBD; yet the structure is being formed
+ * TODO: TBD; yet the structure is being formed
*/
public class Activator implements BundleActivator {
+ private HttpServiceTracker tracker;
- public void start(BundleContext context) throws Exception {
+ public void start(BundleContext context) throws Exception {
+ tracker = new HttpServiceTracker(context);
+ tracker.open();
}
public void stop(BundleContext context) throws Exception {
+ tracker.close();
+ //ungetService
+ ServiceReference axisConfigRef =
+ context.getServiceReference(AxisConfigurator.class.getName());
+ if (axisConfigRef != null) {
+ context.ungetService(axisConfigRef);
+ }
+ ServiceReference configCtxRef =
+ context.getServiceReference(ConfigurationContext.class.getName());
+ if (configCtxRef != null) {
+ context.ungetService(configCtxRef);
+ }
+ }
+
+ //service trackers
+
+ private static class HttpServiceTracker extends ServiceTracker {
+
+ public HttpServiceTracker(BundleContext context) {
+ super(context, HttpService.class.getName(), null);
+ }
+
+ public Object addingService(ServiceReference serviceReference) {
+
+ HttpService httpService = (HttpService) context.getService(serviceReference);
+ try {
+ InitServlet initServlet = new InitServlet(context);
+ httpService.registerServlet("/init_servlet_not_public", initServlet, null, null);
+ OSGiAxisServlet axisServlet = new OSGiAxisServlet(context);
+ ServiceReference axisConfigRef =
+ context.getServiceReference(AxisConfiguration.class.getName());
+ AxisConfiguration axisConfig = (AxisConfiguration)context.getService(axisConfigRef);
+ Object obj = axisConfig.getParameterValue("servicePath");
+ String servicepath = "/servicers";
+ if (obj != null) {
+ servicepath = (String)obj;
+ if (!servicepath.startsWith("/")) {
+ servicepath = "/" + servicepath;
+ }
+ }
+ httpService.registerServlet(servicepath, axisServlet, null, null);
+ } catch (ServletException e) {
+ String msg = "Error while registering servlets";
+ throw new RuntimeException(msg, e);
+ } catch (NamespaceException e) {
+ String msg = "Namespace missmatch when registering servlets";
+ throw new RuntimeException(msg, e);
+ }
+ return httpService;
+ }
}
}