[2/3] camel git commit: CAMEL-11455: Fixed camel-mongodb3 type converters which was implemented wrong and could lead to stop working on first parsing error.

2017-07-23 Thread davsclaus
CAMEL-11455: Fixed camel-mongodb3 type converters which was implemented wrong 
and could lead to stop working on first parsing error.


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

Branch: refs/heads/camel-2.19.x
Commit: 0289fbac7a196a40508a9951f5ca5604032b6649
Parents: f85efbd
Author: Claus Ibsen 
Authored: Sun Jul 23 11:34:27 2017 +0200
Committer: Claus Ibsen 
Committed: Sun Jul 23 13:38:43 2017 +0200

--
 .../converters/MongoDbBasicConverters.java  | 37 +
 .../converters/MongoDbFallbackConverter.java| 80 
 .../services/org/apache/camel/TypeConverter |  3 +-
 .../mongodb3/MongoDbExceptionHandlingTest.java  | 21 +
 4 files changed, 106 insertions(+), 35 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/camel/blob/0289fbac/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/converters/MongoDbBasicConverters.java
--
diff --git 
a/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/converters/MongoDbBasicConverters.java
 
b/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/converters/MongoDbBasicConverters.java
index 0bf2074..c03345f 100644
--- 
a/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/converters/MongoDbBasicConverters.java
+++ 
b/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/converters/MongoDbBasicConverters.java
@@ -18,15 +18,12 @@ package org.apache.camel.component.mongodb3.converters;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
 import org.apache.camel.converter.IOConverter;
@@ -52,10 +49,6 @@ public final class MongoDbBasicConverters {
 
 private static final Logger LOG = 
LoggerFactory.getLogger(MongoDbBasicConverters.class);
 
-// Jackson's ObjectMapper is thread-safe, so no need to create a pool nor
-// synchronize access to it
-private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
-
 private MongoDbBasicConverters() {
 }
 
@@ -71,23 +64,16 @@ public final class MongoDbBasicConverters {
 
 @Converter
 public static Document fromStringToDocument(String s) {
-Document answer = null;
-try {
-answer = Document.parse(s);
-} catch (Exception e) {
-LOG.warn("String -> Document conversion selected, but the 
following exception occurred. Returning null.", e);
-}
-
-return answer;
+return Document.parse(s);
 }
 
 @Converter
-public static Document fromFileToDocument(File f, Exchange exchange) 
throws FileNotFoundException {
+public static Document fromFileToDocument(File f, Exchange exchange) 
throws Exception {
 return fromInputStreamToDocument(new FileInputStream(f), exchange);
 }
 
 @Converter
-public static Document fromInputStreamToDocument(InputStream is, Exchange 
exchange) {
+public static Document fromInputStreamToDocument(InputStream is, Exchange 
exchange) throws Exception {
 Document answer = null;
 try {
 byte[] input = IOConverter.toBytes(is);
@@ -100,8 +86,6 @@ public final class MongoDbBasicConverters {
 } else {
 answer = Document.parse(IOConverter.toString(input, exchange));
 }
-} catch (Exception e) {
-LOG.warn("String -> Document conversion selected, but the 
following exception occurred. Returning null.", e);
 } finally {
 // we need to make sure to close the input stream
 IOHelper.close(is, "InputStream", LOG);
@@ -127,21 +111,6 @@ public final class MongoDbBasicConverters {
 }
 
 @Converter
-public static Document fromAnyObjectToDocument(Object value) {
-Document answer;
-try {
-@SuppressWarnings("unchecked")
-Map m = OBJECT_MAPPER.convertValue(value, 
Map.class);
-answer = new Document(m);
-} catch (Exception e) {
-LOG.warn("Conversion has fallen back to generic Object -> 
Document, but unable to convert type {}. Returning null. {}", 
value.getClass().getCanonicalName(),
- e.getClass().getCanonicalName() + ": " + e.getMessage());
-

[2/3] camel git commit: CAMEL-11455: Fixed camel-mongodb3 type converters which was implemented wrong and could lead to stop working on first parsing error.

2017-07-23 Thread davsclaus
CAMEL-11455: Fixed camel-mongodb3 type converters which was implemented wrong 
and could lead to stop working on first parsing error.


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

Branch: refs/heads/master
Commit: 54073597bdee87a035a569c74c4e9fb465a866f2
Parents: dadbbf3
Author: Claus Ibsen 
Authored: Sun Jul 23 11:34:27 2017 +0200
Committer: Claus Ibsen 
Committed: Sun Jul 23 11:34:27 2017 +0200

--
 .../converters/MongoDbBasicConverters.java  | 37 +
 .../converters/MongoDbFallbackConverter.java| 80 
 .../services/org/apache/camel/TypeConverter |  3 +-
 .../mongodb3/MongoDbExceptionHandlingTest.java  | 21 +
 4 files changed, 106 insertions(+), 35 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/camel/blob/54073597/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/converters/MongoDbBasicConverters.java
--
diff --git 
a/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/converters/MongoDbBasicConverters.java
 
b/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/converters/MongoDbBasicConverters.java
index 0bf2074..c03345f 100644
--- 
a/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/converters/MongoDbBasicConverters.java
+++ 
b/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/converters/MongoDbBasicConverters.java
@@ -18,15 +18,12 @@ package org.apache.camel.component.mongodb3.converters;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
 import org.apache.camel.converter.IOConverter;
@@ -52,10 +49,6 @@ public final class MongoDbBasicConverters {
 
 private static final Logger LOG = 
LoggerFactory.getLogger(MongoDbBasicConverters.class);
 
-// Jackson's ObjectMapper is thread-safe, so no need to create a pool nor
-// synchronize access to it
-private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
-
 private MongoDbBasicConverters() {
 }
 
@@ -71,23 +64,16 @@ public final class MongoDbBasicConverters {
 
 @Converter
 public static Document fromStringToDocument(String s) {
-Document answer = null;
-try {
-answer = Document.parse(s);
-} catch (Exception e) {
-LOG.warn("String -> Document conversion selected, but the 
following exception occurred. Returning null.", e);
-}
-
-return answer;
+return Document.parse(s);
 }
 
 @Converter
-public static Document fromFileToDocument(File f, Exchange exchange) 
throws FileNotFoundException {
+public static Document fromFileToDocument(File f, Exchange exchange) 
throws Exception {
 return fromInputStreamToDocument(new FileInputStream(f), exchange);
 }
 
 @Converter
-public static Document fromInputStreamToDocument(InputStream is, Exchange 
exchange) {
+public static Document fromInputStreamToDocument(InputStream is, Exchange 
exchange) throws Exception {
 Document answer = null;
 try {
 byte[] input = IOConverter.toBytes(is);
@@ -100,8 +86,6 @@ public final class MongoDbBasicConverters {
 } else {
 answer = Document.parse(IOConverter.toString(input, exchange));
 }
-} catch (Exception e) {
-LOG.warn("String -> Document conversion selected, but the 
following exception occurred. Returning null.", e);
 } finally {
 // we need to make sure to close the input stream
 IOHelper.close(is, "InputStream", LOG);
@@ -127,21 +111,6 @@ public final class MongoDbBasicConverters {
 }
 
 @Converter
-public static Document fromAnyObjectToDocument(Object value) {
-Document answer;
-try {
-@SuppressWarnings("unchecked")
-Map m = OBJECT_MAPPER.convertValue(value, 
Map.class);
-answer = new Document(m);
-} catch (Exception e) {
-LOG.warn("Conversion has fallen back to generic Object -> 
Document, but unable to convert type {}. Returning null. {}", 
value.getClass().getCanonicalName(),
- e.getClass().getCanonicalName() + ": " + e.getMessage());
-return