You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/09/04 12:04:39 UTC

svn commit: r572600 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/impl/converter/ tests/camel-partial-classpath-test/src/test/resources/

Author: jstrachan
Date: Tue Sep  4 03:04:33 2007
New Revision: 572600

URL: http://svn.apache.org/viewvc?rev=572600&view=rev
Log:
managed to reproduce and fix CAMEL-100

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
    activemq/camel/trunk/tests/camel-partial-classpath-test/src/test/resources/log4j.properties

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java?rev=572600&r1=572599&r2=572600&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java Tue Sep  4 03:04:33 2007
@@ -24,26 +24,25 @@
 import org.apache.camel.util.NoFactoryAvailableException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 
 /**
  * The default implementation of {@link ComponentResolver} which tries to find
  * components by using the URI scheme prefix and searching for a file of the URI
  * scheme name in the <b>META-INF/services/org/apache/camel/component/</b>
  * directory on the classpath.
- * 
+ *
  * @version $Revision$
  */
 public class DefaultComponentResolver<E extends Exchange> implements ComponentResolver<E> {
     private static final transient Log LOG = LogFactory.getLog(DefaultComponentResolver.class);
-    protected static final FactoryFinder COMPONENT_FACTORY = 
-        new FactoryFinder("META-INF/services/org/apache/camel/component/");
+    protected static final FactoryFinder COMPONENT_FACTORY =
+            new FactoryFinder("META-INF/services/org/apache/camel/component/");
 
     public Component<E> resolveComponent(String name, CamelContext context) {
         Object bean = null;
         try {
             bean = context.getRegistry().lookup(name);
-            if (LOG.isDebugEnabled()) {
+            if (bean != null && LOG.isDebugEnabled()) {
                 LOG.debug("Found component: " + name + " in registry: " + bean);
             }
         }
@@ -52,31 +51,35 @@
         }
         if (bean != null) {
             if (bean instanceof Component) {
-                return (Component)bean;
-            } else {
+                return (Component) bean;
+            }
+            else {
                 throw new IllegalArgumentException("Bean with name: " + name + " in registry is not a Component: " + bean);
             }
         }
         Class type;
         try {
             type = COMPONENT_FACTORY.findClass(name);
-        } catch (NoFactoryAvailableException e) {
+        }
+        catch (NoFactoryAvailableException e) {
             return null;
-        } catch (Throwable e) {
-            throw new IllegalArgumentException("Invalid URI, no Component registered for scheme : " 
-                                               + name, e);
+        }
+        catch (Throwable e) {
+            throw new IllegalArgumentException("Invalid URI, no Component registered for scheme : "
+                    + name, e);
         }
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Found component: " + name + " via type: " + type.getName() + " via " + COMPONENT_FACTORY.getPath());
+            LOG.debug("Found component: " + name + " via type: " + type.getName() + " via " + COMPONENT_FACTORY.getPath() + name);
         }
         if (type == null) {
             return null;
         }
         if (Component.class.isAssignableFrom(type)) {
-            return (Component<E>)context.getInjector().newInstance(type);
-        } else {
+            return (Component<E>) context.getInjector().newInstance(type);
+        }
+        else {
             throw new IllegalArgumentException("Type is not a Component implementation. Found: "
-                                               + type.getName());
+                    + type.getName());
         }
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java?rev=572600&r1=572599&r2=572600&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java Tue Sep  4 03:04:33 2007
@@ -16,32 +16,28 @@
  */
 package org.apache.camel.impl.converter;
 
+import org.apache.camel.Converter;
+import org.apache.camel.impl.CachingInjector;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ResolverUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.lang.reflect.Method;
+import static java.lang.reflect.Modifier.*;
 import java.net.URL;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.StringTokenizer;
 
-import static java.lang.reflect.Modifier.isAbstract;
-import static java.lang.reflect.Modifier.isPublic;
-import static java.lang.reflect.Modifier.isStatic;
-
-import org.apache.camel.Converter;
-import org.apache.camel.impl.CachingInjector;
-import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.ResolverUtil;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
 /**
  * A class which will auto-discover converter objects and methods to pre-load
  * the registry of converters on startup
- * 
+ *
  * @version $Revision$
  */
 public class AnnotationTypeConverterLoader implements TypeConverterLoader {
@@ -65,11 +61,10 @@
     /**
      * Finds the names of the packages to search for on the classpath looking
      * for text files on the classpath at the
-     * 
-     * @{link #META_INF_SERVICES} location
-     * 
+     *
      * @return a collection of packages to search for
      * @throws IOException
+     * @{link #META_INF_SERVICES} location
      */
     protected String[] findPackageNames() throws IOException {
         Set<String> packages = new HashSet<String>();
@@ -96,10 +91,12 @@
                         }
                         tokenize(packages, line);
                     }
-                } finally {
+                }
+                finally {
                     try {
                         reader.close();
-                    } catch (IOException e) {
+                    }
+                    catch (IOException e) {
                         LOG.warn("Caught exception closing stream: " + e, e);
                     }
                 }
@@ -129,46 +126,55 @@
             return;
         }
         visitedClasses.add(type);
-        Method[] methods = type.getDeclaredMethods();
-        CachingInjector injector = null;
-
-        for (Method method : methods) {
-            Converter annotation = method.getAnnotation(Converter.class);
-            if (annotation != null) {
-                Class<?>[] parameterTypes = method.getParameterTypes();
-                if (parameterTypes == null || parameterTypes.length != 1) {
-                    LOG.warn("Ignoring bad converter on type: " + type.getName() + " method: " + method
-                             + " as a converter method should have one parameter");
-                } else {
-                    int modifiers = method.getModifiers();
-                    if (isAbstract(modifiers) || !isPublic(modifiers)) {
+        try {
+            Method[] methods = type.getDeclaredMethods();
+            CachingInjector injector = null;
+
+            for (Method method : methods) {
+                Converter annotation = method.getAnnotation(Converter.class);
+                if (annotation != null) {
+                    Class<?>[] parameterTypes = method.getParameterTypes();
+                    if (parameterTypes == null || parameterTypes.length != 1) {
                         LOG.warn("Ignoring bad converter on type: " + type.getName() + " method: " + method
-                                 + " as a converter method is not a public and concrete method");
-                    } else {
-                        Class toType = method.getReturnType();
-                        if (toType.equals(Void.class)) {
-                            LOG.warn("Ignoring bad converter on type: " + type.getName() + " method: "
-                                     + method + " as a converter method returns a void method");
-                        } else {
-                            Class fromType = parameterTypes[0];
-                            if (isStatic(modifiers)) {
-                                registry.addTypeConverter(toType, fromType,
-                                                          new StaticMethodTypeConverter(method));
-                            } else {
-                                if (injector == null) {
-                                    injector = new CachingInjector(registry, type);
+                                + " as a converter method should have one parameter");
+                    }
+                    else {
+                        int modifiers = method.getModifiers();
+                        if (isAbstract(modifiers) || !isPublic(modifiers)) {
+                            LOG.warn("Ignoring bad converter on type: " + type.getName() + " method: " + method
+                                    + " as a converter method is not a public and concrete method");
+                        }
+                        else {
+                            Class toType = method.getReturnType();
+                            if (toType.equals(Void.class)) {
+                                LOG.warn("Ignoring bad converter on type: " + type.getName() + " method: "
+                                        + method + " as a converter method returns a void method");
+                            }
+                            else {
+                                Class fromType = parameterTypes[0];
+                                if (isStatic(modifiers)) {
+                                    registry.addTypeConverter(toType, fromType,
+                                            new StaticMethodTypeConverter(method));
+                                }
+                                else {
+                                    if (injector == null) {
+                                        injector = new CachingInjector(registry, type);
+                                    }
+                                    registry.addTypeConverter(toType, fromType,
+                                            new InstanceMethodTypeConverter(injector, method));
                                 }
-                                registry.addTypeConverter(toType, fromType,
-                                                          new InstanceMethodTypeConverter(injector, method));
                             }
                         }
                     }
                 }
             }
+            Class superclass = type.getSuperclass();
+            if (superclass != null && !superclass.equals(Object.class)) {
+                loadConverterMethods(registry, superclass);
+            }
         }
-        Class superclass = type.getSuperclass();
-        if (superclass != null && !superclass.equals(Object.class)) {
-            loadConverterMethods(registry, superclass);
+        catch (NoClassDefFoundError e) {
+            LOG.debug("Ignoring converter type: " + type.getName() + " as a dependent class could not be found: " + e, e);
         }
     }
 }

Modified: activemq/camel/trunk/tests/camel-partial-classpath-test/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-partial-classpath-test/src/test/resources/log4j.properties?rev=572600&r1=572599&r2=572600&view=diff
==============================================================================
--- activemq/camel/trunk/tests/camel-partial-classpath-test/src/test/resources/log4j.properties (original)
+++ activemq/camel/trunk/tests/camel-partial-classpath-test/src/test/resources/log4j.properties Tue Sep  4 03:04:33 2007
@@ -20,6 +20,9 @@
 #
 log4j.rootLogger=INFO, out
 
+# Use the following line to turn on debug output for camel
+#log4j.logger.org.apache.camel=DEBUG
+
 log4j.logger.org.apache.activemq.spring=WARN
 
 # CONSOLE appender not used by default