cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject svn commit: r469384 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/phase/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ rt/core/src/main/java/org/apache/cxf/endpoint/ rt/core/src/main/java/org/apache/cxf/intercept...
Date Tue, 31 Oct 2006 06:06:03 GMT
Author: tli
Date: Mon Oct 30 22:06:03 2006
New Revision: 469384

URL: http://svn.apache.org/viewvc?view=rev&rev=469384
Log:
refactor the client out chain fault handling

Added:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientOutFaultObserver.java
  (with props)
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AttachmentOutInterceptor.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/MessageSenderInterceptor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedOutInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java?view=diff&rev=469384&r1=469383&r2=469384
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
(original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
Mon Oct 30 22:06:03 2006
@@ -65,6 +65,10 @@
     private Message pausedMessage;
     private MessageObserver faultObserver;
     
+    // currently one chain for one request/response, use below as signal to avoid duplicate
fault processing
+    // on nested calling of doIntercept(), which will throw same fault multi-times
+    private boolean faultOccured;
+    
     public PhaseInterceptorChain(List<Phase> ps) {
         state = State.EXECUTING;
         subChainState = new Stack<State>();
@@ -146,20 +150,16 @@
                     return true;
                 }
             } catch (Exception ex) {
-                if (LOG.isLoggable(Level.INFO)) {
-                    LogUtils.log(LOG, Level.INFO, "Interceptor has thrown exception, unwinding
now", ex);
-                }
-                message.setContent(Exception.class, ex);
-                unwind(message);
-                
-                if (faultObserver != null) {
-                    faultObserver.onMessage(message);
-                } else {
-                    // Client out-bound message, directly throw exception back to client
-                    if (message.getExchange() != null 
-                            && message == message.getExchange().getOutMessage() 
-                            && message.containsKey(Message.REQUESTOR_ROLE)) {
-                        throw new RuntimeException(ex);
+                if (!faultOccured) {
+                    faultOccured = true;
+                    if (LOG.isLoggable(Level.INFO)) {
+                        LogUtils.log(LOG, Level.INFO, "Interceptor has thrown exception,
unwinding now", ex);
+                    }
+                    message.setContent(Exception.class, ex);
+                    unwind(message);
+                    
+                    if (faultObserver != null) {
+                        faultObserver.onMessage(message);
                     }
                 }
                 state = State.ABORTED;

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AttachmentOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AttachmentOutInterceptor.java?view=diff&rev=469384&r1=469383&r2=469384
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AttachmentOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AttachmentOutInterceptor.java
Mon Oct 30 22:06:03 2006
@@ -50,7 +50,10 @@
         message.setContent(OutputStream.class, cs);
         
         // Calling for soap out interceptor
-        message.getInterceptorChain().doIntercept(message);
+        if (!message.getInterceptorChain().doIntercept(message) 
+            && message.getContent(Exception.class) != null) {            
+            throw new Fault(message.getContent(Exception.class));            
+        }
         // Set back the output stream
         message.setContent(OutputStream.class, os);        
         try {

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java?view=diff&rev=469384&r1=469383&r2=469384
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
Mon Oct 30 22:06:03 2006
@@ -85,9 +85,11 @@
                                   soapVersion.getNamespace());
             
             // Calling for Wrapped/RPC/Doc/ Interceptor for writing SOAP body
-            //message.getInterceptorChain().doIntercept(message);
-            message.getInterceptorChain().doInterceptInSubChain(message);
-
+            //message.getInterceptorChain().doIntercept(message);            
+            if (!message.getInterceptorChain().doInterceptInSubChain(message) 
+                && message.getContent(Exception.class) != null) {
+                throw new Fault(message.getContent(Exception.class));
+            }
             xtw.writeEndElement();            
             // Write Envelop end element
             xtw.writeEndElement();

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java?view=diff&rev=469384&r1=469383&r2=469384
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java Mon
Oct 30 22:06:03 2006
@@ -31,6 +31,7 @@
 import org.apache.cxf.BusException;
 import org.apache.cxf.binding.Binding;
 import org.apache.cxf.interceptor.AbstractBasicInterceptorProvider;
+import org.apache.cxf.interceptor.ClientOutFaultObserver;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.InterceptorChain;
@@ -63,12 +64,14 @@
     private Bus bus;
     private Endpoint endpoint;
     private Conduit initedConduit;
+    private ClientOutFaultObserver outFaultObserver; 
     private int synchronousTimeout = 100000; // default 10 second timeout
 
     public ClientImpl(Bus b, Endpoint e) {
         bus = b;
         endpoint = e;
         getOutInterceptors().add(new MessageSenderInterceptor());
+        outFaultObserver = new ClientOutFaultObserver(bus);
     }
 
     public Endpoint getEndpoint() {
@@ -130,7 +133,7 @@
         chain.add(il);        
         
         modifyChain(chain, requestContext);
-        
+        chain.setFaultObserver(outFaultObserver);
         // setup conduit
         Conduit conduit = getConduit();
         exchange.setConduit(conduit);

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientOutFaultObserver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientOutFaultObserver.java?view=auto&rev=469384
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientOutFaultObserver.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientOutFaultObserver.java
Mon Oct 30 22:06:03 2006
@@ -0,0 +1,46 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.interceptor;
+
+import java.util.List;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.phase.PhaseManager;
+
+public class ClientOutFaultObserver extends AbstractFaultChainIntiatorObserver {
+
+    
+    public ClientOutFaultObserver(Bus bus) {
+        super(bus);
+    }
+    
+    @Override
+    protected List<Phase> getPhases() {
+        return getBus().getExtension(PhaseManager.class).getOutPhases();
+    }
+    /**
+     * override the super class method
+     */
+    public void onMessage(Message m) {
+        // do nothing for exception occured during client sending out request
+    }
+}

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientOutFaultObserver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientOutFaultObserver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/MessageSenderInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/MessageSenderInterceptor.java?view=diff&rev=469384&r1=469383&r2=469384
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/MessageSenderInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/MessageSenderInterceptor.java
Mon Oct 30 22:06:03 2006
@@ -54,9 +54,13 @@
         try {
             conduit.send(message);
 
-            message.getInterceptorChain().doIntercept(message);
-
-            conduit.close(message);
+            if (message.getInterceptorChain().doIntercept(message)) {
+                conduit.close(message);
+            } else {
+                if (message.getContent(Exception.class) != null) {
+                    throw new Fault(message.getContent(Exception.class));
+                }
+            }
         } catch (IOException ex) {
             throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_SEND", BUNDLE),
ex);
         }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java?view=diff&rev=469384&r1=469383&r2=469384
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
Mon Oct 30 22:06:03 2006
@@ -66,10 +66,16 @@
 
         message.setContent(XMLStreamWriter.class, writer);
 
-        message.getInterceptorChain().doIntercept(message);
-
+        boolean result = message.getInterceptorChain().doIntercept(message);
+        
         try {
-            writer.close();
+            if (writer != null) {
+                writer.close();
+            }
+            
+            if (!result && message.getContent(Exception.class) != null) {
+                throw new Fault(message.getContent(Exception.class));
+            }            
         } catch (XMLStreamException e) {
             throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE),
e);
         }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedOutInterceptor.java?view=diff&rev=469384&r1=469383&r2=469384
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedOutInterceptor.java
Mon Oct 30 22:06:03 2006
@@ -61,7 +61,10 @@
                 xmlWriter.setDefaultNamespace(name.getNamespaceURI());
                 xmlWriter.writeStartElement(name.getNamespaceURI(), name.getLocalPart());
                 xmlWriter.writeDefaultNamespace(name.getNamespaceURI());
-                message.getInterceptorChain().doIntercept(message);
+                if (!message.getInterceptorChain().doIntercept(message) 
+                        && message.getContent(Exception.class) != null) {       
            
+                    throw new Fault(message.getContent(Exception.class));               
    
+                }
                 xmlWriter.writeEndElement();
             } catch (XMLStreamException e) {
                 throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC",
BUNDLE), e);

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java?view=diff&rev=469384&r1=469383&r2=469384
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
Mon Oct 30 22:06:03 2006
@@ -36,6 +36,7 @@
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.interceptor.SoapInterceptor;
 import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.StaxOutInterceptor;
 import org.apache.cxf.io.AbstractCachedOutputStream;
 import org.apache.cxf.jaxws.handler.AbstractProtocolHandlerInterceptor;
@@ -81,7 +82,10 @@
             CachedStream cs = new CachedStream();
             message.setContent(OutputStream.class, cs);
 
-            message.getInterceptorChain().doInterceptInSubChain(message);
+            if (message.getInterceptorChain().doInterceptInSubChain(message) 
+                && message.getContent(Exception.class) != null) {
+                throw new Fault(message.getContent(Exception.class));
+            }
 
             super.handleMessage(message);
 

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java?view=diff&rev=469384&r1=469383&r2=469384
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
Mon Oct 30 22:06:03 2006
@@ -144,14 +144,35 @@
         }
         
         try {
+            client.getEndpoint().getOutInterceptors().add(new NestedFaultThrower());
             client.getEndpoint().getOutInterceptors().add(new FaultThrower());
             client.invoke(bop, new Object[] {"BadRecordLitFault"}, null);
             fail("Should have returned a fault!");
-        } catch (RuntimeException ex) {
-            assertEquals(true, ex.getMessage().indexOf("Foo") > 0);
-        } 
+        } catch (Fault fault) {
+            assertEquals(true, fault.getMessage().indexOf("Foo") >= 0);
+        }         
+        
     }
 
+    
+    public static class NestedFaultThrower extends AbstractPhaseInterceptor<Message>
{
+        
+        public NestedFaultThrower() {
+            super();
+            setPhase(Phase.PRE_LOGICAL);
+            addBefore(FaultThrower.class.getName());
+        }
+
+        public void handleMessage(Message message) throws Fault {
+            boolean result = message.getInterceptorChain().doIntercept(message);
+            assertEquals("doIntercept not return false", result, false);
+            assertNotNull(message.getContent(Exception.class));
+            throw new Fault(message.getContent(Exception.class));
+        }
+
+    }
+
+    
     public static class FaultThrower extends AbstractPhaseInterceptor<Message> {
         
         public FaultThrower() {



Mime
View raw message