Repository: camel
Updated Branches:
  refs/heads/master 213e351bc -> 00fef5857


CAMEL-10168: camel-aws ignores type converter loading error if the end user 
have opted-out some of the AWS features by not having the uber JAR but 
specialized JARs


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/00fef585
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/00fef585
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/00fef585

Branch: refs/heads/master
Commit: 00fef5857c0bcb0fc7a02f19f5ba51ef0382133d
Parents: 213e351
Author: Claus Ibsen <davscl...@apache.org>
Authored: Tue Aug 2 17:03:01 2016 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Aug 2 17:03:01 2016 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/camel/Converter.java     | 13 +++++++++++++
 .../impl/converter/AnnotationTypeConverterLoader.java | 14 +++++++++++++-
 .../aws/ddbstream/StringSequenceNumberConverter.java  |  3 ++-
 .../component/aws/kinesis/RecordStringConverter.java  |  3 ++-
 4 files changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/00fef585/camel-core/src/main/java/org/apache/camel/Converter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/Converter.java 
b/camel-core/src/main/java/org/apache/camel/Converter.java
index 1652e77..5c83841 100644
--- a/camel-core/src/main/java/org/apache/camel/Converter.java
+++ b/camel-core/src/main/java/org/apache/camel/Converter.java
@@ -39,4 +39,17 @@ public @interface Converter {
      * Whether or not returning <tt>null</tt> is a valid response.
      */
     boolean allowNull() default false;
+
+    /**
+     * Whether to ignore the type converter if it cannot be loaded for some 
reason.
+     * <p/>
+     * This can be used if a Camel component provides multiple components
+     * where the end user can opt-out some of these components by excluding
+     * dependencies on the classpath, meaning the type converter would not
+     * be able to load due class not found errors. But in those cases its
+     * okay as the component is opted-out.
+     * <p/>
+     * Important this configuration must be set on the class-level, not on the 
method.
+     */
+    boolean ignoreOnLoadError() default false;
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/00fef585/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
 
b/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
index c724870..eb1bd4b 100644
--- 
a/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
+++ 
b/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
@@ -285,7 +285,19 @@ public class AnnotationTypeConverterLoader implements 
TypeConverterLoader {
                 loadConverterMethods(registry, superclass);
             }
         } catch (NoClassDefFoundError e) {
-            LOG.warn("Ignoring converter type: " + type.getCanonicalName() + " 
as a dependent class could not be found: " + e, e);
+            boolean ignore = false;
+            // does the class allow to ignore the type converter when having 
load errors
+            if (ObjectHelper.hasAnnotation(type, Converter.class, true)) {
+                if (type.getAnnotation(Converter.class) != null) {
+                    ignore = 
type.getAnnotation(Converter.class).ignoreOnLoadError();
+                }
+            }
+            // if we should ignore then only log at debug level
+            if (ignore) {
+                LOG.debug("Ignoring converter type: " + 
type.getCanonicalName() + " as a dependent class could not be found: " + e, e);
+            } else {
+                LOG.warn("Ignoring converter type: " + type.getCanonicalName() 
+ " as a dependent class could not be found: " + e, e);
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/00fef585/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/StringSequenceNumberConverter.java
----------------------------------------------------------------------
diff --git 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/StringSequenceNumberConverter.java
 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/StringSequenceNumberConverter.java
index 0048ce0..d6e55c8 100644
--- 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/StringSequenceNumberConverter.java
+++ 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/StringSequenceNumberConverter.java
@@ -18,7 +18,8 @@ package org.apache.camel.component.aws.ddbstream;
 
 import org.apache.camel.Converter;
 
-@Converter
+// Allow to ignore this type converter if the ddbstream JARs are not present 
on the classpath
+@Converter(ignoreOnLoadError = true)
 public final class StringSequenceNumberConverter {
 
     private StringSequenceNumberConverter() {

http://git-wip-us.apache.org/repos/asf/camel/blob/00fef585/components/camel-aws/src/main/java/org/apache/camel/component/aws/kinesis/RecordStringConverter.java
----------------------------------------------------------------------
diff --git 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/kinesis/RecordStringConverter.java
 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/kinesis/RecordStringConverter.java
index 19b8590..df2f016 100644
--- 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/kinesis/RecordStringConverter.java
+++ 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/kinesis/RecordStringConverter.java
@@ -22,7 +22,8 @@ import java.nio.charset.Charset;
 import com.amazonaws.services.kinesis.model.Record;
 import org.apache.camel.Converter;
 
-@Converter
+// Allow to ignore this type converter if the kinesis JARs are not present on 
the classpath
+@Converter(ignoreOnLoadError = true)
 public final class RecordStringConverter {
 
     private RecordStringConverter() {

Reply via email to