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

[2/3] camel git commit: Fix for CAMEL-10579. Similar to fix for CAMEL-8708, but for SOAP 1.1.

Fix for CAMEL-10579.  Similar to fix for CAMEL-8708, but for SOAP 1.1.

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

Branch: refs/heads/camel-2.18.x
Commit: ee45e2a7621ab28f12f13e6c2d3c89f62dca73cc
Parents: d574442
Author: Jonathan Scholis <sc...@10.0.0.2>
Authored: Sun Dec 11 10:56:59 2016 -0500
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Dec 12 10:11:15 2016 +0100

----------------------------------------------------------------------
 .../soap/Soap11DataFormatAdapter.java           | 20 ++++++++++-----
 .../dataformat/soap/SoapUnMarshalTest.java      | 13 ++++++++++
 .../dataformat/soap/faultWithoutDetail.xml      | 27 ++++++++++++++++++++
 3 files changed, 54 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ee45e2a7/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/Soap11DataFormatAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/Soap11DataFormatAdapter.java b/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/Soap11DataFormatAdapter.java
index 8242e5e..5a70bd1 100644
--- a/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/Soap11DataFormatAdapter.java
+++ b/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/Soap11DataFormatAdapter.java
@@ -26,7 +26,10 @@ 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;
@@ -179,20 +182,25 @@ public class Soap11DataFormatAdapter 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
+     * SOAPFaultException is created.
      * 
      * @param fault Soap fault
      * @return created Exception
      */
     private Exception createExceptionFromFault(Fault fault) {
-        List<Object> detailList = fault.getDetail().getAny();
         String message = fault.getFaultstring();
 
-        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.getFaultcode()));
+            } 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/ee45e2a7/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
----------------------------------------------------------------------
diff --git a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
index 679d5ba..cc17a13 100644
--- a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
+++ b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
@@ -19,6 +19,8 @@ package org.apache.camel.dataformat.soap;
 import java.io.IOException;
 import java.io.InputStream;
 
+import javax.xml.ws.soap.SOAPFaultException;
+
 import com.example.customerservice.GetCustomersByName;
 
 import org.apache.camel.EndpointInject;
@@ -58,6 +60,17 @@ public class SoapUnMarshalTest extends CamelTestSupport {
         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 {
         return new RouteBuilder() {

http://git-wip-us.apache.org/repos/asf/camel/blob/ee45e2a7/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/faultWithoutDetail.xml
----------------------------------------------------------------------
diff --git a/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/faultWithoutDetail.xml b/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/faultWithoutDetail.xml
new file mode 100644
index 0000000..21a88c8
--- /dev/null
+++ b/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/faultWithoutDetail.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<ns2:Envelope xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns3="http://customerservice.example.com/">
+    <ns2:Body>
+        <ns2:Fault>
+            <faultcode>ns2:Receiver</faultcode>
+            <faultstring>Customer not found</faultstring>
+        </ns2:Fault>
+    </ns2:Body>
+</ns2:Envelope>