cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject [2/3] cxf git commit: [CXF-4242] Adjust how the exception is output in the stack trace as well as how it's created on the client. Fixes the failing tests
Date Thu, 13 Nov 2014 22:50:08 GMT
[CXF-4242] Adjust how the exception is output in the stack trace as well as how it's created
on the client.
Fixes the failing tests


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

Branch: refs/heads/3.0.x-fixes
Commit: affbb7daebc6aad7d9e64ee0f602d901e406c915
Parents: 22b1125
Author: Daniel Kulp <dkulp@apache.org>
Authored: Thu Nov 13 13:16:37 2014 -0500
Committer: Alessio Soldano <asoldano@redhat.com>
Committed: Thu Nov 13 23:05:59 2014 +0100

----------------------------------------------------------------------
 .../cxf/interceptor/ClientFaultConverter.java   | 27 +++++++++++++++++---
 .../interceptor/AbstractSoapInterceptor.java    |  3 ++-
 .../details/Soap11ClientServerTest.java         |  2 +-
 .../details/Soap12ClientServerTest.java         |  1 +
 4 files changed, 28 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/affbb7da/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java b/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
index 9f2a178..3391779 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
@@ -260,8 +260,14 @@ public class ClientFaultConverter extends AbstractInDatabindingInterceptor
{
                 if (!stackTraceList.isEmpty()) {
                     StackTraceElement[] stackTraceElement = new StackTraceElement[stackTraceList.size()];
                     e.setStackTrace(stackTraceList.toArray(stackTraceElement));
-                }
-                if (cause != null) {
+                } else if (cause != null
+                    && cause.getMessage() != null
+                    && cause.getMessage().startsWith(e.getClass().getName())) {
+                    e.setStackTrace(cause.getStackTrace());
+                    if (cause.getCause() != null) {
+                        e.initCause(cause.getCause());
+                    }
+                } else if (cause != null) {
                     e.initCause(cause);
                 }
             }
@@ -273,7 +279,22 @@ public class ClientFaultConverter extends AbstractInDatabindingInterceptor
{
     private Throwable getCause(Iterator<String> linesIterator, String firstLine) {
         // The actual exception class of the cause might be unavailable at the
         // client -> use a standard throwable to represent the cause.
-        Throwable res = new Throwable(firstLine.substring(firstLine.indexOf(":") + 2));
+        firstLine = firstLine.substring(firstLine.indexOf(":") + 1).trim();
+        Throwable res = null;
+        if (firstLine.indexOf(":") != -1) {
+            String cn = firstLine.substring(0, firstLine.indexOf(":")).trim();
+            if (cn.startsWith("java.lang")) {
+                try {
+                    res = (Throwable)Class.forName(cn).getConstructor(String.class)
+                            .newInstance(firstLine.substring(firstLine.indexOf(":") + 2));
+                } catch (Throwable t) {
+                    //ignore, use the default
+                }
+            }
+        }
+        if (res == null) {
+            res = new Throwable(firstLine);
+        }
         List<StackTraceElement> stackTraceList = new ArrayList<StackTraceElement>();
         while (linesIterator.hasNext()) {
             String oneLine = linesIterator.next();

http://git-wip-us.apache.org/repos/asf/cxf/blob/affbb7da/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AbstractSoapInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AbstractSoapInterceptor.java
b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AbstractSoapInterceptor.java
index 1815a99..096ca02 100644
--- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AbstractSoapInterceptor.java
+++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AbstractSoapInterceptor.java
@@ -72,7 +72,8 @@ public abstract class AbstractSoapInterceptor extends AbstractPhaseInterceptor<S
         if (config && fault.getCause() != null) {
             StringBuilder sb = new StringBuilder();
             Throwable throwable = fault.getCause();
-            sb.append(throwable.getClass().getCanonicalName() + " : " + throwable.getMessage()
+ "\n");
+            sb.append("Caused by: ").append(throwable.getClass().getCanonicalName())
+                .append(": " + throwable.getMessage() + "\n").append(Message.EXCEPTION_CAUSE_SUFFIX);
             while (throwable != null) {
                 for (StackTraceElement ste : throwable.getStackTrace()) {
                     sb.append(ste.getClassName() + "!" + ste.getMethodName() + "!" + ste.getFileName()
+ "!"

http://git-wip-us.apache.org/repos/asf/cxf/blob/affbb7da/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap11ClientServerTest.java
----------------------------------------------------------------------
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap11ClientServerTest.java
b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap11ClientServerTest.java
index a5b2470..b1da372 100644
--- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap11ClientServerTest.java
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap11ClientServerTest.java
@@ -109,7 +109,7 @@ public class Soap11ClientServerTest extends AbstractBusClientServerTestBase
{
             StackTraceElement[] elements = ex.getCause().getStackTrace();
             assertEquals("org.apache.cxf.systest.soapfault.details.GreeterImpl11", 
                          elements[0].getClassName());
-            assertTrue(ex.getCause().getMessage().endsWith("Test \n cause."));
+            assertTrue(ex.getCause().getCause().getMessage().endsWith("Test \n cause."));
         } 
 
         

http://git-wip-us.apache.org/repos/asf/cxf/blob/affbb7da/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap12ClientServerTest.java
----------------------------------------------------------------------
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap12ClientServerTest.java
b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap12ClientServerTest.java
index 83acb5b..b3c50c9 100644
--- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap12ClientServerTest.java
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap12ClientServerTest.java
@@ -73,6 +73,7 @@ public class Soap12ClientServerTest extends AbstractBusClientServerTestBase
{
             assertEquals((short)1, detail.getMinor());
             assertEquals("PingMeFault raised by server", ex.getMessage());
             StackTraceElement[] element = ex.getStackTrace();
+            ex.printStackTrace();
             assertEquals("org.apache.cxf.systest.soapfault.details.GreeterImpl12", element[0].getClassName());
         }
     }


Mime
View raw message