You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ay...@apache.org on 2012/12/23 19:22:56 UTC

svn commit: r1425506 - in /cxf/branches/2.5.x-fixes: ./ api/src/main/java/org/apache/cxf/interceptor/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/ rt/cor...

Author: ay
Date: Sun Dec 23 18:22:55 2012
New Revision: 1425506

URL: http://svn.apache.org/viewvc?rev=1425506&view=rev
Log:
Merged revisions 1424565 via  svn merge from
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

........
  r1424565 | ay | 2012-12-20 17:19:28 +0100 (Thu, 20 Dec 2012) | 9 lines
  
  Merged revisions 1423814 via  svn merge from
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1423814 | ay | 2012-12-19 11:15:45 +0100 (Wed, 19 Dec 2012) | 1 line
    
    revising the fix for CXF-4689
  ........
  
........

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/interceptor/Fault.java
    cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AbstractSoapInterceptor.java
    cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
    cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultOutInterceptor.java
    cxf/branches/2.5.x-fixes/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FaultOutInterceptor.java
    cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/GreeterImpl11.java
    cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap11ClientServerTest.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/interceptor/Fault.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/interceptor/Fault.java?rev=1425506&r1=1425505&r2=1425506&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/interceptor/Fault.java (original)
+++ cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/interceptor/Fault.java Sun Dec 23 18:22:55 2012
@@ -84,7 +84,7 @@ public class Fault extends UncheckedExce
         if (super.getMessage() != null) {
             message = super.getMessage();
         } else {
-            message = getMessage(t);
+            message = t == null ? null : t.getMessage();
         }
         code = FAULT_CODE_SERVER;
     }
@@ -106,7 +106,7 @@ public class Fault extends UncheckedExce
         if (super.getMessage() != null) {
             message = super.getMessage();
         } else {
-            message = getMessage(t);
+            message = t == null ? null : t.getMessage();
         }
         code = fc;
     }    
@@ -184,13 +184,4 @@ public class Fault extends UncheckedExce
     public void setStatusCode(int statusCode) {
         this.statusCode = statusCode;
     }
-
-    /**
-     * Extracts the effective message value from the specified exception object
-     * @param t
-     * @return
-     */
-    private static String getMessage(Throwable t) {
-        return t == null ? null : t.getMessage() != null ? t.getMessage() : t.toString();
-    }
 }

Modified: cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AbstractSoapInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AbstractSoapInterceptor.java?rev=1425506&r1=1425505&r2=1425506&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AbstractSoapInterceptor.java (original)
+++ cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AbstractSoapInterceptor.java Sun Dec 23 18:22:55 2012
@@ -34,6 +34,8 @@ import org.apache.cxf.binding.soap.SoapF
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.staxutils.StaxUtils;
 
@@ -73,9 +75,8 @@ public abstract class AbstractSoapInterc
     }
     
     protected void prepareStackTrace(SoapMessage message, SoapFault fault) throws Exception {
-        String config = (String)message
-            .getContextualProperty(org.apache.cxf.message.Message.FAULT_STACKTRACE_ENABLED);
-        if (config != null && Boolean.valueOf(config).booleanValue() && fault.getCause() != null) {
+        boolean config = MessageUtils.getContextualBoolean(message, Message.FAULT_STACKTRACE_ENABLED, false);
+        if (config && fault.getCause() != null) {
             StringBuilder sb = new StringBuilder();
             Throwable throwable = fault.getCause();
             while (throwable != null) {
@@ -109,4 +110,27 @@ public abstract class AbstractSoapInterc
             }
         }
     }
+
+    static String getFaultMessage(SoapMessage message, SoapFault fault) {
+        if (message.get("forced.faultstring") != null) {
+            return (String) message.get("forced.faultstring");
+        }
+        boolean config = MessageUtils.getContextualBoolean(message, Message.EXCEPTION_MESSAGE_CAUSE_ENABLED, false);
+        if (fault.getMessage() != null) {
+            if (config && fault.getCause() != null 
+                && fault.getCause().getMessage() != null && !fault.getMessage().equals(fault.getCause().getMessage())) {
+                return fault.getMessage() + " Caused by: " + fault.getCause().getMessage();
+            } else {
+                return fault.getMessage();
+            }
+        } else if (config && fault.getCause() != null) {
+            if (fault.getCause().getMessage() != null) {
+                return fault.getCause().getMessage();
+            } else {
+                return fault.getCause().toString();
+            }
+        } else {
+            return "Fault occurred while processing.";
+        }
+    }
 }

Modified: cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java?rev=1425506&r1=1425505&r2=1425506&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java (original)
+++ cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java Sun Dec 23 18:22:55 2012
@@ -82,13 +82,9 @@ public class Soap11FaultOutInterceptor e
     
                 writer.writeCharacters(codeString);
                 writer.writeEndElement();
-    
+
                 writer.writeStartElement("faultstring");
-                if (fault.getMessage() != null) {
-                    writer.writeCharacters(fault.getMessage());
-                } else {
-                    writer.writeCharacters("Fault occurred while processing.");
-                }
+                writer.writeCharacters(getFaultMessage(message, fault));
                 writer.writeEndElement();
                 prepareStackTrace(message, fault);
     

Modified: cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultOutInterceptor.java?rev=1425506&r1=1425505&r2=1425506&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultOutInterceptor.java (original)
+++ cxf/branches/2.5.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultOutInterceptor.java Sun Dec 23 18:22:55 2012
@@ -105,11 +105,7 @@ public class Soap12FaultOutInterceptor e
                 writer.writeStartElement(defaultPrefix, "Reason", ns);
                 writer.writeStartElement(defaultPrefix, "Text", ns);
                 writer.writeAttribute("xml", "http://www.w3.org/XML/1998/namespace", "lang", getLangCode());
-                if (fault.getMessage() != null) {
-                    writer.writeCharacters(fault.getMessage());
-                } else {
-                    writer.writeCharacters("Fault occurred while processing.");
-                }
+                writer.writeCharacters(getFaultMessage(message, fault));
                 writer.writeEndElement();
                 writer.writeEndElement();
 

Modified: cxf/branches/2.5.x-fixes/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java?rev=1425506&r1=1425505&r2=1425506&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java (original)
+++ cxf/branches/2.5.x-fixes/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java Sun Dec 23 18:22:55 2012
@@ -147,12 +147,12 @@ public class SoapFaultSerializerTest ext
     public void testFaultToSoapFault() throws Exception {
         Exception ex = new Exception();
         Fault fault = new Fault(ex, Fault.FAULT_CODE_CLIENT);
-        verifyFaultToSoapFault(fault, ex.toString(), true, Soap11.getInstance());
-        verifyFaultToSoapFault(fault, ex.toString(), true, Soap12.getInstance());
+        verifyFaultToSoapFault(fault, null, true, Soap11.getInstance());
+        verifyFaultToSoapFault(fault, null, true, Soap12.getInstance());
         
         fault = new Fault(ex, Fault.FAULT_CODE_SERVER);
-        verifyFaultToSoapFault(fault, ex.toString(), false, Soap11.getInstance());
-        verifyFaultToSoapFault(fault, ex.toString(), false, Soap12.getInstance());
+        verifyFaultToSoapFault(fault, null, false, Soap11.getInstance());
+        verifyFaultToSoapFault(fault, null, false, Soap12.getInstance());
         
         fault.setMessage("fault-one");
         verifyFaultToSoapFault(fault, "fault-one", false, Soap11.getInstance());

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FaultOutInterceptor.java?rev=1425506&r1=1425505&r2=1425506&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FaultOutInterceptor.java (original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FaultOutInterceptor.java Sun Dec 23 18:22:55 2012
@@ -107,18 +107,6 @@ public class FaultOutInterceptor extends
                 //the fault like it was an unchecked exception.
                 LOG.log(Level.WARNING, "EXCEPTION_WHILE_WRITING_FAULT", fex);
             }
-        } else {
-            // Cannot find the fault info, now we should check if we need to 
-            // set the cause message of the exception
-            String config = (String)message.getContextualProperty(
-                org.apache.cxf.message.Message.EXCEPTION_MESSAGE_CAUSE_ENABLED);
-            if (config != null && Boolean.valueOf(config).booleanValue()) {
-                StringBuffer buffer = new StringBuffer();
-                buffer.append(f.getMessage());
-                buffer.append(" Caused by: ");
-                buffer.append(cause.getMessage());
-                f.setMessage(buffer.toString());
-            }
         }
     }
 

Modified: cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/GreeterImpl11.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/GreeterImpl11.java?rev=1425506&r1=1425505&r2=1425506&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/GreeterImpl11.java (original)
+++ cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/GreeterImpl11.java Sun Dec 23 18:22:55 2012
@@ -43,7 +43,19 @@ public class GreeterImpl11 {
     private static final Logger LOG = LogUtils.getLogger(GreeterImpl11.class);
 
     public String greetMe(String me) {
-        return "Hello " + me;
+        if (me.startsWith("A")) {
+            throw new Fault(new NullPointerException());
+        } else if (me.startsWith("B")) {
+            throw new Fault(new IllegalArgumentException("Get a wrong name for greetMe"));
+        } else if (me.startsWith("C")) {
+            throw new Fault("unexpected null", LOG, new NullPointerException());
+        } else if (me.startsWith("D")) {
+            throw new Fault("greetMeFault", LOG, new IllegalArgumentException("Get a wrong name greetMe"));
+        } else if (me.startsWith("E")) {
+            throw new Fault("invalid", LOG);
+        } else {
+            return "Hello " + me;
+        }
     }
 
     public String sayHi() {

Modified: cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap11ClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap11ClientServerTest.java?rev=1425506&r1=1425505&r2=1425506&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap11ClientServerTest.java (original)
+++ cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/soapfault/details/Soap11ClientServerTest.java Sun Dec 23 18:22:55 2012
@@ -53,9 +53,48 @@ public class Soap11ClientServerTest exte
             StackTraceElement[] elements = ex.getCause().getStackTrace();
             assertEquals("org.apache.cxf.systest.soapfault.details.GreeterImpl11", 
                          elements[0].getClassName());
+        }
+        
+        // testing Fault(new NullPointerException())
+        try {
+            greeter.greetMe("Anya");
+            fail("Should throw Exception!");
+        } catch (SOAPFaultException ex) {
+            assertEquals(NullPointerException.class.getName(), ex.getMessage());
+        } 
+
+        // testing Fault(new IllegalArgumentException("Get a wrong name for greetMe"))
+        try {
+            greeter.greetMe("Banya");
+            fail("Should throw Exception!");
+        } catch (SOAPFaultException ex) {
+            assertEquals("Get a wrong name for greetMe", ex.getMessage());
+        } 
+
+        // testing Fault("unexpected null", LOG, new NullPointerException())        
+        try {
+            greeter.greetMe("Canya");
+            fail("Should throw Exception!");
+        } catch (SOAPFaultException ex) {
+            assertEquals("unexpected null", ex.getMessage());
+        } 
+
+        // testing Fault("greetMeFault", LOG, new IllegalArgumentException("Get a wrong name greetMe"))
+        try {
+            greeter.greetMe("Danya");
+            fail("Should throw Exception!");
+        } catch (SOAPFaultException ex) {
+            assertEquals("greetMeFault Caused by: Get a wrong name greetMe", ex.getMessage());
+        } 
+
+        // testing Fault("invalid", LOG)        
+        try {
+            greeter.greetMe("Eanna");
+            fail("Should throw Exception!");
+        } catch (SOAPFaultException ex) {
+            assertEquals("invalid", ex.getMessage());
         } 
     }
-    
 
     @Test
     public void testPingMeFault() throws Exception {