axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r662593 - in /webservices/axis2/trunk/java/modules/osgi: resources/META-INF/ src/org/apache/axis2/extensions/osgi/ src/org/apache/axis2/extensions/osgi/util/
Date Mon, 02 Jun 2008 22:43:02 GMT
Author: dims
Date: Mon Jun  2 15:43:02 2008
New Revision: 662593

URL: http://svn.apache.org/viewvc?rev=662593&view=rev
Log:
behave better when there is no log service running

Added:
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/Logger.java
Modified:
    webservices/axis2/trunk/java/modules/osgi/resources/META-INF/MANIFEST.MF
    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/ServiceRegistry.java

Modified: webservices/axis2/trunk/java/modules/osgi/resources/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/resources/META-INF/MANIFEST.MF?rev=662593&r1=662592&r2=662593&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/resources/META-INF/MANIFEST.MF (original)
+++ webservices/axis2/trunk/java/modules/osgi/resources/META-INF/MANIFEST.MF Mon Jun  2 15:43:02
2008
@@ -122,6 +122,7 @@
  org.jivesoftware.smack;resolution:=optional,
  org.osgi.framework,
  org.osgi.service.http,
+ org.osgi.util.tracker,
  org.osgi.service.log,
  org.w3c.dom,
  org.xml.sax

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=662593&r1=662592&r2=662593&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 15:43:02 2008
@@ -19,6 +19,7 @@
 
 package org.apache.axis2.extensions.osgi;
 
+import org.apache.axis2.extensions.osgi.util.Logger;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -34,11 +35,12 @@
     OSGiAxis2Servlet servlet = new OSGiAxis2Servlet();
     ServiceRegistry registry = null;
     HttpService httpServ = null;
-    LogService log = null;
+    Logger logger;
 
     public void start(BundleContext context) throws Exception {
         this.context = context;
-        System.out.println("[Axis2/OSGi] Registering Axis2 Servlet");
+        logger = new Logger(context);
+        logger.log(LogService.LOG_INFO,"[Axis2/OSGi] Registering Axis2 Servlet");
 
         ServiceReference sr = context.getServiceReference(HttpService.class.getName());
         if (sr != null) {
@@ -47,24 +49,15 @@
                 httpServ.registerServlet("/axis2",
                         servlet, null, null);
             } catch (Exception e) {
-                System.err.println("[Axis2/OSGi] Exception registering Axis Servlet:"
-                        + e);
+                logger.log(LogService.LOG_ERROR,"[Axis2/OSGi] Exception registering Axis
Servlet",
+                        e);
             }
         }
 
-        ServiceReference sr2 = context.getServiceReference(LogService.class.getName());
-        if (sr2 != null) {
-            log = (LogService) context.getService(sr);
-            if (log == null) {
-                System.err.println("[Axis2/OSGi] Unable to find Log Service");
-            }
-        }
+        registry = new ServiceRegistry(servlet, logger);
 
-        System.out.println("[Axis2/OSGi] Starting Bundle Listener");
+        logger.log(LogService.LOG_INFO, "[Axis2/OSGi] Starting Bundle Listener");
         context.addBundleListener(this);
-
-        registry = new ServiceRegistry(servlet, log);
-        
 // TODO: We should poke at all the bundles already in the system
 //        Bundle bundles[] = context.getBundles();
 //        for (int i = 0; i < bundles.length; i++) {
@@ -82,14 +75,14 @@
         switch (event.getType()) {
             case BundleEvent.STARTED:
                 if(context.getBundle() != bundle){
-                    System.out.println("[Axis2/OSGi] Starting any services in Bundle - "
+ bundle.getSymbolicName());
+                    logger.log(LogService.LOG_INFO,"[Axis2/OSGi] Starting any services in
Bundle - " + bundle.getSymbolicName());
                     registry.register(event.getBundle());
                 }
                 break;
 
             case BundleEvent.STOPPED:
                 if(context.getBundle() != bundle){
-                    System.out.println("[Axis2/OSGi] Stopping any services in Bundle - "
+ bundle.getSymbolicName());
+                    logger.log(LogService.LOG_INFO,"[Axis2/OSGi] Stopping any services in
Bundle - " + bundle.getSymbolicName());
                     registry.unregister(event.getBundle());
                 }
                 break;
@@ -97,7 +90,7 @@
     }
 
     public void stop(BundleContext context) throws Exception {
-        System.out.println("[Axis2/OSGi] Stopping all services and the Bundle Listener");
+        logger.log(LogService.LOG_INFO,"[Axis2/OSGi] Stopping all services and the Bundle
Listener");
         this.context.removeBundleListener(this);
         registry.close();
     }

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/ServiceRegistry.java?rev=662593&r1=662592&r2=662593&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/ServiceRegistry.java
(original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/ServiceRegistry.java
Mon Jun  2 15:43:02 2008
@@ -29,9 +29,11 @@
 import org.apache.axis2.description.AxisServiceGroup;
 import org.apache.axis2.description.Flow;
 import org.apache.axis2.extensions.osgi.util.BundleClassLoader;
+import org.apache.axis2.extensions.osgi.util.Logger;
 import org.apache.axis2.jaxws.framework.JAXWSDeployer;
 import org.osgi.framework.Bundle;
 import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
 
 import java.net.URL;
 import java.util.ArrayList;
@@ -41,20 +43,20 @@
 
 public class ServiceRegistry extends JAXWSDeployer {
     private OSGiAxis2Servlet servlet;
-    private LogService log;
+    private Logger logger;
     private HashMap services = new HashMap();
     private boolean isInited = false;
 
-    public ServiceRegistry(OSGiAxis2Servlet servlet, LogService log) {
+    public ServiceRegistry(OSGiAxis2Servlet servlet, Logger logger) {
         this.servlet = servlet;
-        this.log = log;
+        this.logger = logger;
     }
 
     public void register(Bundle bundle) {
         if(!isInited){
             ConfigurationContext context = servlet.ConfigurationContext();
             if(context == null){
-                System.out.println("[Axis2/OSGi] Configuration Context is null. unable to
register bundle");
+                logger.log(LogService.LOG_INFO,"[Axis2/OSGi] Configuration Context is null.
unable to register bundle");
                 return;
             }
             init(context);
@@ -79,17 +81,17 @@
         try {
             AxisServiceGroup serviceGroup = deployClasses(bundle.getSymbolicName(), null,
loader, classes);
             if (serviceGroup != null) {
-                System.out.println("[Axis2/OSGi] Deployed ServiceGroup - " + serviceGroup.getServiceGroupName());
+                logger.log(LogService.LOG_INFO,"[Axis2/OSGi] Deployed ServiceGroup - " +
serviceGroup.getServiceGroupName());
 
                 for (Iterator iterator = serviceGroup.getServices(); iterator.hasNext();)
{
                     AxisService service = (AxisService) iterator.next();
-                    System.out.println("[Axis2/OSGi]      Service - " + service.getName());
+                    logger.log(LogService.LOG_INFO,"[Axis2/OSGi]      Service - " + service.getName());
                 }
                 services.put(bundle, serviceGroup);
             }
         } catch (Exception e) {
-            if(log != null) {
-                log.log(LogService.LOG_INFO, "Exception deploying classes", e);
+            if(logger != null) {
+                logger.log(LogService.LOG_INFO, "Exception deploying classes", e);
             }
         }
     }
@@ -137,8 +139,8 @@
                 }
             }
         } catch (Exception e) {
-            if(log != null) {
-                log.log(LogService.LOG_INFO, "Exception deploying modules", e);
+            if(logger != null) {
+                logger.log(LogService.LOG_INFO, "Exception deploying modules", e);
             }
         }
     }
@@ -148,15 +150,15 @@
             AxisServiceGroup serviceGroup = (AxisServiceGroup) iterator.next();
             try {
                 axisConfig.removeServiceGroup(serviceGroup.getServiceGroupName());
-                System.out.println("[Axis2/OSGi] Undeployed ServiceGroup - " + serviceGroup.getServiceGroupName());
+                logger.log(LogService.LOG_INFO,"[Axis2/OSGi] Undeployed ServiceGroup - "
+ serviceGroup.getServiceGroupName());
 
                 for (Iterator iterator2 = serviceGroup.getServices(); iterator2.hasNext();)
{
                     AxisService service = (AxisService) iterator2.next();
-                    System.out.println("[Axis2/OSGi]      Service - " + service.getName());
+                    logger.log(LogService.LOG_INFO,"[Axis2/OSGi]      Service - " + service.getName());
                 }
             } catch (AxisFault axisFault) {
-                if(log != null) {
-                    log.log(LogService.LOG_INFO, axisFault.getMessage(), axisFault);
+                if(logger != null) {
+                    logger.log(LogService.LOG_INFO, axisFault.getMessage(), axisFault);
                 }
             }
         }
@@ -167,15 +169,15 @@
         if (serviceGroup != null) {
             try {
                 axisConfig.removeServiceGroup(serviceGroup.getServiceGroupName());
-                System.out.println("[Axis2/OSGi] Undeployed ServiceGroup - " + serviceGroup.getServiceGroupName());
+                logger.log(LogService.LOG_INFO,"[Axis2/OSGi] Undeployed ServiceGroup - "
+ serviceGroup.getServiceGroupName());
 
                 for (Iterator iterator2 = serviceGroup.getServices(); iterator2.hasNext();)
{
                     AxisService service = (AxisService) iterator2.next();
-                    System.out.println("[Axis2/OSGi]      Service - " + service.getName());
+                    logger.log(LogService.LOG_INFO,"[Axis2/OSGi]      Service - " + service.getName());
                 }
             } catch (AxisFault axisFault) {
-                if(log != null) {
-                    log.log(LogService.LOG_INFO, axisFault.getMessage(), axisFault);
+                if(logger != null) {
+                    logger.log(LogService.LOG_INFO, axisFault.getMessage(), axisFault);
                 }
             }
         }

Added: 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=662593&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/Logger.java
(added)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/Logger.java
Mon Jun  2 15:43:02 2008
@@ -0,0 +1,53 @@
+package org.apache.axis2.extensions.osgi.util;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class Logger extends ServiceTracker {
+    public Logger(BundleContext context){
+        super(context, LogService.class.getName(), null);
+        open();
+    }
+    
+    public LogService getLogService(){
+        return (LogService)this.getService();
+    }
+
+    public void log(int i, java.lang.String s) {
+        LogService service = getLogService();
+        if(service == null){
+            print(i, s);
+        } else {
+            service.log(i, s);
+        }
+    }
+
+    private void print(int i, String s) {
+        switch(i){
+                case LogService.LOG_ERROR: 
+                System.out.print("[ERROR]   ");
+                break;
+            case LogService.LOG_INFO: 
+                System.out.print("[INFO]    ");
+                break;
+            case LogService.LOG_WARNING: 
+                System.out.print("[WARNDING]");
+                break;
+            case LogService.LOG_DEBUG: 
+                System.out.print("[DEBUG]   ");
+                break;
+        }
+        System.out.println(" : " + s);
+    }
+
+    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 {
+            service.log(i, s, throwable);
+        }
+    }
+}



Mime
View raw message