camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/3] camel git commit: CAMEL-11681: camel-cxf - getting TypeConversionException when schema-validation-enabled=true for unwrapped response. Thanks to Chio Chuan Ooi for test case that show this regression.
Date Tue, 12 Sep 2017 09:06:47 GMT
CAMEL-11681: camel-cxf - getting TypeConversionException when schema-validation-enabled=true
for unwrapped response. Thanks to Chio Chuan Ooi for test case that show this regression.


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

Branch: refs/heads/camel-2.18.x
Commit: 66bf3616f4fb4bc740145d8e941b87847a337e4c
Parents: ccb8d4e
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Sep 12 11:02:55 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Sep 12 11:05:01 2017 +0200

----------------------------------------------------------------------
 .../cxf/converter/CachedCxfPayload.java         | 32 +++++++++++++-------
 1 file changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/66bf3616/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CachedCxfPayload.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CachedCxfPayload.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CachedCxfPayload.java
index b2b4db6..5ea6dca 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CachedCxfPayload.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CachedCxfPayload.java
@@ -27,6 +27,7 @@ import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stax.StAXSource;
+import javax.xml.transform.stream.StreamResult;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.StreamCache;
@@ -39,7 +40,6 @@ import org.apache.cxf.staxutils.StaxUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 public class CachedCxfPayload<T> extends CxfPayload<T> implements StreamCache
{
     private static final Logger LOG = LoggerFactory.getLogger(CachedCxfPayload.class);
 
@@ -69,18 +69,28 @@ public class CachedCxfPayload<T> extends CxfPayload<T> implements
StreamCache {
                 try {
                     StaxUtils.copy(reader, cos);
                     li.set(new StreamSourceCache(cos.newStreamCache()));
-                } catch (XMLStreamException e) {
-                    LOG.error("Transformation failed ", e);
-                } catch (IOException e) {
-                    LOG.error("Cannot Create StreamSourceCache ", e);
-                }
-
-            } else if (!(source instanceof DOMSource)) {
-                DOMSource document = exchange.getContext().getTypeConverter().convertTo(DOMSource.class,
exchange, source);
-                if (document != null) {
-                    li.set(document);
+                    // this worked so continue
+                    continue;
+                } catch (Exception e) {
+                    // fallback to trying to read the reader using another way
+                    StreamResult sr = new StreamResult(cos);
+                    try {
+                        xml.toResult(source, sr);
+                        li.set(new StreamSourceCache(cos.newStreamCache()));
+                        // this worked so continue
+                        continue;
+                    } catch (Exception e2) {
+                        // ignore did not work so we will fallback to DOM mode
+                        // this can happens in some rare cases such as reported by CAMEL-11681
+                        LOG.debug("Error during parsing XMLStreamReader from StaxSource/StAXSource.
Will fallback to using DOM mode. This exception is ignored", e2);
+                    }
                 }
             }
+            // fallback to using DOM
+            DOMSource document = exchange.getContext().getTypeConverter().tryConvertTo(DOMSource.class,
exchange, source);
+            if (document != null) {
+                li.set(document);
+            }
         }
     }
 


Mime
View raw message