axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r662633 - in /webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi: Activator.java util/HttpServiceTracker.java util/Logger.java
Date Tue, 03 Jun 2008 04:04:19 GMT
Author: dims
Date: Mon Jun  2 21:04:19 2008
New Revision: 662633

URL: http://svn.apache.org/viewvc?rev=662633&view=rev
Log:
add a tracker for HttpService(s)

Added:
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/HttpServiceTracker.java
Modified:
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/Activator.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/Logger.java

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/Activator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/Activator.java?rev=662633&r1=662632&r2=662633&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/Activator.java
(original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/Activator.java
Mon Jun  2 21:04:19 2008
@@ -19,13 +19,13 @@
 
 package org.apache.axis2.extensions.osgi;
 
+import org.apache.axis2.extensions.osgi.util.HttpServiceTracker;
 import org.apache.axis2.extensions.osgi.util.Logger;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleListener;
-import org.osgi.framework.ServiceReference;
 import org.osgi.service.http.HttpService;
 import org.osgi.service.log.LogService;
 
@@ -34,26 +34,14 @@
     BundleContext context;
     OSGiAxis2Servlet servlet = new OSGiAxis2Servlet();
     ServiceRegistry registry = null;
-    HttpService httpServ = null;
+    HttpServiceTracker httpTracker = null;
     Logger logger;
 
     public void start(BundleContext context) throws Exception {
         this.context = context;
-        logger = new Logger(context);
-        logger.log(LogService.LOG_INFO,"[Axis2/OSGi] Registering Axis2 Servlet");
-
-        ServiceReference sr = context.getServiceReference(HttpService.class.getName());
-        if (sr != null) {
-            HttpService httpServ = (HttpService) context.getService(sr);
-            try {
-                httpServ.registerServlet("/axis2",
-                        servlet, null, null);
-            } catch (Exception e) {
-                logger.log(LogService.LOG_ERROR,"[Axis2/OSGi] Exception registering Axis
Servlet",
-                        e);
-            }
-        }
 
+        logger = new Logger(context);
+        httpTracker = new HttpServiceTracker(context, servlet, logger); 
         registry = new ServiceRegistry(servlet, logger);
 
         logger.log(LogService.LOG_INFO, "[Axis2/OSGi] Starting Bundle Listener");
@@ -92,6 +80,7 @@
     public void stop(BundleContext context) throws Exception {
         logger.log(LogService.LOG_INFO,"[Axis2/OSGi] Stopping all services and the Bundle
Listener");
         this.context.removeBundleListener(this);
+        httpTracker.close();
         logger.close();
         registry.close();
     }

Added: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/HttpServiceTracker.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/HttpServiceTracker.java?rev=662633&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/HttpServiceTracker.java
(added)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/HttpServiceTracker.java
Mon Jun  2 21:04:19 2008
@@ -0,0 +1,43 @@
+package org.apache.axis2.extensions.osgi.util;
+
+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.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+
+public class HttpServiceTracker extends ServiceTracker {
+    int count;
+    Servlet servlet;
+    Logger logger;
+
+    public HttpServiceTracker(BundleContext context, Servlet servlet,
+        Logger logger) {
+        super(context, HttpService.class.getName(), null);
+        this.servlet = servlet;
+        this.logger = logger;
+        open();
+    }
+
+    public Object addingService(ServiceReference reference) {
+        try {
+            HttpService http = (HttpService) super.addingService(reference);
+            installServlet(http);
+            return http;
+        } catch (Exception nse) {
+            logger.log(LogService.LOG_ERROR,"Unable to install servlet: ", nse);
+        }
+
+        return null;
+    }
+
+    private void installServlet(HttpService http) throws ServletException, NamespaceException
{
+        http.registerServlet("/axis2", servlet, null, null);
+        logger.log(LogService.LOG_INFO,"Installed Axis2 Servlet in http service " + http);
+    }
+}

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/Logger.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/Logger.java?rev=662633&r1=662632&r2=662633&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/Logger.java
(original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/Logger.java
Mon Jun  2 21:04:19 2008
@@ -16,11 +16,11 @@
 
     public void log(int i, java.lang.String s) {
         LogService service = getLogService();
-        if(service == null){
-            print(i, s);
-        } else {
+        if(service != null){
             service.log(i, s);
+            //return;
         }
+        print(i, s);
     }
 
     private void print(int i, String s) {
@@ -32,7 +32,7 @@
                 System.out.print("[INFO]    ");
                 break;
             case LogService.LOG_WARNING: 
-                System.out.print("[WARNDING]");
+                System.out.print("[WARNING]");
                 break;
             case LogService.LOG_DEBUG: 
                 System.out.print("[DEBUG]   ");
@@ -43,11 +43,11 @@
 
     public void log(int i, java.lang.String s, java.lang.Throwable throwable) {
         LogService service = getLogService();
-        if(service == null){
-            print(i, s);
-            throwable.printStackTrace(System.out);
-        } else {
+        if(service != null){
             service.log(i, s, throwable);
+            //return;
         }
+        print(i, s);
+        throwable.printStackTrace(System.out);
     }
 }



Mime
View raw message