cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [1/9] cxf git commit: Small refactoring of exception wrapping
Date Mon, 09 Feb 2015 17:49:11 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 9c7847877 -> 268735e75


Small refactoring of exception wrapping


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

Branch: refs/heads/3.0.x-fixes
Commit: a23a473d8df5d9b0210d10b10a0e66ef9bbd056f
Parents: 9c78478
Author: Christian Schneider <chris@die-schneider.net>
Authored: Tue Jan 20 15:33:33 2015 +0100
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Mon Feb 9 12:48:54 2015 -0500

----------------------------------------------------------------------
 .../apache/cxf/phase/PhaseInterceptorChain.java | 111 ++++++++++---------
 1 file changed, 60 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a23a473d/core/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java b/core/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
index 8ad2dc8..5287e9a 100644
--- a/core/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
+++ b/core/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
@@ -318,58 +318,9 @@ public class PhaseInterceptorChain implements InterceptorChain {
                     pause();
                     throw ex;
                 } catch (RuntimeException ex) {
-                    
                     if (!faultOccurred) {
-     
                         faultOccurred = true;
-                                            
-                        StringBuilder description = new StringBuilder();
-                        if (message.getExchange() != null) {
-                            Exchange exchange = message.getExchange();
-                            Service service = exchange.get(Service.class);
-                            if (service != null) {
-                                description.append('\'');
-                                description.append(service.getName());
-                                OperationInfo opInfo = exchange.get(OperationInfo.class);
-                                if (opInfo != null) {
-                                    description.append("#").append(opInfo.getName());
-                                }
-                                description.append("\' ");
-                            }
-                        }
-                        
-                        message.setContent(Exception.class, ex);
-                        unwind(message);
-                        Exception ex2 = message.getContent(Exception.class);
-                        if (ex2 == null) {
-                            ex2 = ex;
-                        }
-                        
-                        FaultListener flogger = (FaultListener)
-                                message.getContextualProperty(FaultListener.class.getName());
-                        boolean useDefaultLogging = true;
-                        if (flogger != null) {
-                            useDefaultLogging = flogger.faultOccurred(ex2, description.toString(),
message);
-                        }
-                        if (useDefaultLogging) {
-                            doDefaultLogging(message, ex2, description);
-                        }
-                        
-                        boolean isOneWay = false;
-                        if (message.getExchange() != null) {
-                            if (message.getContent(Exception.class) != null) {
-                                message.getExchange().put(Exception.class, ex2);
-                            }
-                            isOneWay = message.getExchange().isOneWay() 
-                                && !MessageUtils.isTrue(message.getContextualProperty(Message.ROBUST_ONEWAY));
-                        }
-                        
-                        if (faultObserver != null && !isOneWay) {
-                            // CXF-5629. when exchange is one way and robust, it becomes
req-resp in order to
-                            // send the fault
-                            message.getExchange().setOneWay(false);
-                            faultObserver.onMessage(message);
-                        }
+                        wrapExceptionAsFault(message, ex);
                     }
                     state = State.ABORTED;
                 } 
@@ -383,7 +334,57 @@ public class PhaseInterceptorChain implements InterceptorChain {
         }
     }
 
-    private void doDefaultLogging(Message message, Exception ex, StringBuilder description)
{
+    private void wrapExceptionAsFault(Message message, RuntimeException ex) {
+        String description = getServiceInfo(message);
+        
+        message.setContent(Exception.class, ex);
+        unwind(message);
+        Exception ex2 = message.getContent(Exception.class);
+        if (ex2 == null) {
+            ex2 = ex;
+        }
+        
+        FaultListener flogger = (FaultListener)
+                message.getContextualProperty(FaultListener.class.getName());
+        boolean useDefaultLogging = true;
+        if (flogger != null) {
+            useDefaultLogging = flogger.faultOccurred(ex2, description, message);
+        }
+        if (useDefaultLogging) {
+            doDefaultLogging(message, ex2, description);
+        }
+        
+        if (message.getExchange() != null && message.getContent(Exception.class)
!= null) {
+            message.getExchange().put(Exception.class, ex2);
+        }
+
+        if (faultObserver != null && !isOneWay(message)) {
+            // CXF-5629. when exchange is one way and robust, it becomes req-resp in order
to
+            // send the fault
+            message.getExchange().setOneWay(false);
+            faultObserver.onMessage(message);
+        }
+    }
+
+    private String getServiceInfo(Message message) {
+        StringBuilder description = new StringBuilder();
+        if (message.getExchange() != null) {
+            Exchange exchange = message.getExchange();
+            Service service = exchange.get(Service.class);
+            if (service != null) {
+                description.append('\'');
+                description.append(service.getName());
+                OperationInfo opInfo = exchange.get(OperationInfo.class);
+                if (opInfo != null) {
+                    description.append("#").append(opInfo.getName());
+                }
+                description.append("\' ");
+            }
+        }
+        return description.toString();
+    }
+
+    private void doDefaultLogging(Message message, Exception ex, String description) {
         FaultMode mode = message.get(FaultMode.class);
         if (mode == FaultMode.CHECKED_APPLICATION_FAULT) {
             if (isFineLogging) {
@@ -415,6 +416,14 @@ public class PhaseInterceptorChain implements InterceptorChain {
             }
         }
     }
+    
+    private boolean isOneWay(Message message) {
+        return (message.getExchange() != null) ? message.getExchange().isOneWay() &&
!isRobustOneWay(message) : false;
+    }
+
+    private boolean isRobustOneWay(Message message) {
+        return MessageUtils.isTrue(message.getContextualProperty(Message.ROBUST_ONEWAY));
+    }
 
     /**
      * Intercept a message, invoking each phase's handlers in turn,


Mime
View raw message