camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/4] camel git commit: CAMEL-8708: SOAP marshaling shouldn't fail for Faults that lack an optional Detail element
Date Mon, 14 Dec 2015 07:09:06 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x fcb69ae3e -> 50d8821d0
  refs/heads/master 3d67a3e36 -> 80bcfbaac


CAMEL-8708: SOAP marshaling shouldn't fail for Faults that lack an optional Detail element


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

Branch: refs/heads/master
Commit: 5adc5d2f5591f4d5edc99389dbe1dd3a005b3cee
Parents: 3d67a3e
Author: Pascal Schumacher <pascalschumacher@gmx.net>
Authored: Fri Dec 11 18:22:40 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Dec 14 08:00:38 2015 +0100

----------------------------------------------------------------------
 .../soap/Soap12DataFormatAdapter.java           | 21 ++++++++++++++------
 .../dataformat/soap12/Soap12UnMarshalTest.java  | 16 ++++++++++++++-
 .../dataformat/soap12/faultWithoutDetail.xml    | 15 ++++++++++++++
 3 files changed, 45 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5adc5d2f/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/Soap12DataFormatAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/Soap12DataFormatAdapter.java
b/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/Soap12DataFormatAdapter.java
index cd63c79..6c7ac1a 100644
--- a/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/Soap12DataFormatAdapter.java
+++ b/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/Soap12DataFormatAdapter.java
@@ -23,10 +23,14 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
+
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBIntrospector;
 import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
 import javax.xml.ws.WebFault;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.RuntimeCamelException;
@@ -190,24 +194,29 @@ public class Soap12DataFormatAdapter implements SoapDataFormatAdapter
{
      * Creates an exception and eventually an embedded bean that contains the
      * fault detail. The exception class is determined by using the
      * elementNameStrategy. The qName of the fault detail should match the
-     * WebFault annotation of the Exception class. If no fault detail is set the
-     * a RuntimeCamelException is created.
+     * WebFault annotation of the Exception class. If no fault detail is set
+     * a {@link javax.xml.ws.soap.SOAPFaultException} is created.
      * 
      * @param fault Soap fault
      * @return created Exception
      */
     private Exception createExceptionFromFault(Fault fault) {
-        List<Object> detailList = fault.getDetail().getAny();
         StringBuilder sb = new StringBuilder();
         for (Reasontext text : fault.getReason().getText()) {
             sb.append(text);
         }
         String message = sb.toString();
 
-        if (detailList.size() == 0) {
-            return new RuntimeCamelException(message);
+        Detail faultDetail = fault.getDetail();
+        if (faultDetail == null || faultDetail.getAny().size() == 0) {
+            try {
+                return new SOAPFaultException(SOAPFactory.newInstance().createFault(message,
fault.getCode().getValue()));
+            } catch (SOAPException e) {
+                throw new RuntimeCamelException(e);
+            }
         }
-        JAXBElement<?> detailEl = (JAXBElement<?>) detailList.get(0);
+        
+        JAXBElement<?> detailEl = (JAXBElement<?>) faultDetail.getAny().get(0);
         Class<? extends Exception> exceptionClass = getDataFormat().getElementNameStrategy().findExceptionForFaultName(detailEl.getName());
         Constructor<? extends Exception> messageConstructor;
         Constructor<? extends Exception> constructor;

http://git-wip-us.apache.org/repos/asf/camel/blob/5adc5d2f/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap12/Soap12UnMarshalTest.java
----------------------------------------------------------------------
diff --git a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap12/Soap12UnMarshalTest.java
b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap12/Soap12UnMarshalTest.java
index ea376c5..ce70d4e 100644
--- a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap12/Soap12UnMarshalTest.java
+++ b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap12/Soap12UnMarshalTest.java
@@ -19,7 +19,8 @@ package org.apache.camel.dataformat.soap12;
 import java.io.IOException;
 import java.io.InputStream;
 
-import com.example.customerservice.GetCustomersByName;
+import javax.xml.ws.soap.SOAPFaultException;
+
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
 import org.apache.camel.Produce;
@@ -29,6 +30,8 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
+import com.example.customerservice.GetCustomersByName;
+
 /**
  * Checks that a static soap request is unmarshalled to the correct java
  * objects
@@ -55,6 +58,17 @@ public class Soap12UnMarshalTest extends CamelTestSupport {
         GetCustomersByName request = (GetCustomersByName) body;
         assertEquals("Smith", request.getName());
     }
+    
+    @Test
+    public void testUnMarshalSoapFaultWithoutDetail() throws IOException, InterruptedException
{
+        try {
+            InputStream in = this.getClass().getResourceAsStream("faultWithoutDetail.xml");
+            producer.sendBody(in);
+            fail("Should have thrown an Exception.");
+        } catch (Exception e) {
+            assertEquals(SOAPFaultException.class, e.getCause().getClass());
+        }
+    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/5adc5d2f/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap12/faultWithoutDetail.xml
----------------------------------------------------------------------
diff --git a/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap12/faultWithoutDetail.xml
b/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap12/faultWithoutDetail.xml
new file mode 100644
index 0000000..bf70b47
--- /dev/null
+++ b/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap12/faultWithoutDetail.xml
@@ -0,0 +1,15 @@
+<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
+	<env:Body>
+		<env:Fault>
+			<env:Code>
+				<env:Value>Sender</env:Value>
+				<env:Subcode>
+					<env:Value>Timeout</env:Value>
+				</env:Subcode>
+			</env:Code>
+			<env:Reason>
+				<env:Text xml:lang="en">Timeout</env:Text>
+			</env:Reason>
+		</env:Fault>
+	</env:Body>
+</env:Envelope>
\ No newline at end of file


Mime
View raw message