cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r502515 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/ rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/ systests/src/test/java/org/apache/cxf/systest/handlers/
Date Fri, 02 Feb 2007 06:05:37 GMT
Author: jliu
Date: Thu Feb  1 22:05:36 2007
New Revision: 502515

URL: http://svn.apache.org/viewvc?view=rev&rev=502515
Log:
CXF-333 patch from Unreal

Removed:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/StreamHandler.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/StreamHandlerInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/StreamMessageContext.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/StreamMessageContextImpl.java
Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java?view=diff&rev=502515&r1=502514&r2=502515
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java
Thu Feb  1 22:05:36 2007
@@ -46,54 +46,47 @@
 
     private static final Logger LOG = LogUtils.getL7dLogger(HandlerChainInvoker.class);
 
-    private final List<Handler> protocolHandlers = new ArrayList<Handler>();

-    private List<LogicalHandler> logicalHandlers  = new ArrayList<LogicalHandler>();

-    private final List<StreamHandler> streamHandlers  = new ArrayList<StreamHandler>();

-    private final List<Handler> invokedHandlers  = new ArrayList<Handler>();

-    private final List<Handler> closeHandlers  = new ArrayList<Handler>(); 
+    private final List<Handler> protocolHandlers = new ArrayList<Handler>();
+    private List<LogicalHandler> logicalHandlers  = new ArrayList<LogicalHandler>();
+    private final List<Handler> invokedHandlers  = new ArrayList<Handler>();
+    private final List<Handler> closeHandlers  = new ArrayList<Handler>();
 
-    private boolean outbound; 
-    private boolean responseExpected = true; 
+    private boolean outbound;
+    private boolean responseExpected = true;
     private boolean faultExpected;
-    private boolean handlerProcessingAborted; 
-    private boolean closed;  
+    private boolean handlerProcessingAborted;
+    private boolean closed;
     private Exception fault;
     private MessageContext logicalMessageContext;
     private MessageContext protocolMessageContext;
-    
+
     public HandlerChainInvoker(List<Handler> hc) {
         this(hc, true);
-    }    
+    }
 
     public HandlerChainInvoker(List<Handler> hc, boolean isOutbound) {
         if (LOG.isLoggable(Level.FINE)) {
             LOG.log(Level.FINE, "invoker for chain size: " + (hc != null ? hc.size() : 0));
         }
-        
-        if (hc != null) { 
-            for (Handler h : hc) { 
-                if (h instanceof LogicalHandler) {                    
+
+        if (hc != null) {
+            for (Handler h : hc) {
+                if (h instanceof LogicalHandler) {
                     logicalHandlers.add((LogicalHandler)h);
-                } else if (h instanceof StreamHandler) {
-                    streamHandlers.add((StreamHandler)h); 
-                } else { 
+                } else {
                     protocolHandlers.add(h);
                 }
             }
         }
         outbound = isOutbound;
     }
-    
-    public List<LogicalHandler> getLogicalHandlers() { 
-        return logicalHandlers;
-    } 
 
-    public List<Handler> getProtocolHandlers() { 
-        return protocolHandlers;
+    public List<LogicalHandler> getLogicalHandlers() {
+        return logicalHandlers;
     }
 
-    public List<StreamHandler> getStreamHandlers() { 
-        return streamHandlers;
+    public List<Handler> getProtocolHandlers() {
+        return protocolHandlers;
     }
 
     public MessageContext getLogicalMessageContext() {
@@ -102,35 +95,31 @@
     public void setLogicalMessageContext(MessageContext mc) {
         logicalMessageContext = mc;
     }
-    
+
     public MessageContext getProtocolMessageContext() {
         return protocolMessageContext;
     }
     public void setProtocolMessageContext(MessageContext mc) {
         protocolMessageContext = mc;
     }
-    
-    public boolean invokeLogicalHandlers(boolean requestor, LogicalMessageContext context)
{ 
+
+    public boolean invokeLogicalHandlers(boolean requestor, LogicalMessageContext context)
{
         // objectCtx.setRequestorRole(requestor);
-        context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, isOutbound()); 
-        return invokeHandlerChain(logicalHandlers, context); 
+        context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, isOutbound());
+        return invokeHandlerChain(logicalHandlers, context);
 
     }
-        
+
     public boolean invokeProtocolHandlers(boolean requestor, MessageContext context) {
         // WrappedMessageContext context = new WrappedMessageContext(message);
         // bindingContext.put(ObjectMessageContext.REQUESTOR_ROLE_PROPERTY, requestor);
-        context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, isOutbound()); 
+        context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, isOutbound());
 
         return invokeHandlerChain(protocolHandlers, context);
-    }    
-       
-    public void closeHandlers() {
-        //nothing to do
     }
-    
+
     public void setResponseExpected(boolean expected) {
-        responseExpected = expected; 
+        responseExpected = expected;
     }
 
     public boolean isResponseExpected() {
@@ -139,12 +128,12 @@
 
     public boolean isOutbound() {
         return outbound;
-    }    
-    
-    public boolean isInbound() { 
+    }
+
+    public boolean isInbound() {
         return !outbound;
     }
-    
+
     public void setInbound() {
         outbound = false;
     }
@@ -155,14 +144,14 @@
 
 
     public boolean faultRaised() {
-        return null != fault  || faultExpected; 
+        return null != fault  || faultExpected;
     }
-    
+
     public Exception getFault() {
         return fault;
     }
 
-    public void setFault(boolean fe) { 
+    public void setFault(boolean fe) {
         faultExpected = fe;
     }
 
@@ -190,13 +179,13 @@
      *
      */
     public boolean isClosed() {
-        return closed; 
+        return closed;
     }
-    
+
     /**
      * Allows an the logical handler chain for one invoker to be used
      * as an alternate chain for another.
-     * 
+     *
      * @param invoker the invoker encalsulting the alternate logical handler
      * chain
      */
@@ -204,12 +193,12 @@
         logicalHandlers = invoker.getLogicalHandlers();
     }
 
-    List getInvokedHandlers() { 
+    List getInvokedHandlers() {
         return Collections.unmodifiableList(invokedHandlers);
     }
-    
+
     private <T extends Handler> void invokeClose(List<T> handlers, MessageContext
context) {
-        handlers = reverseHandlerChain(handlers); 
+        handlers = reverseHandlerChain(handlers);
         for (Handler h : handlers) {
             if (closeHandlers.contains(h)) {
                 h.close(context);
@@ -217,9 +206,9 @@
         }
     }
 
-    private boolean invokeHandlerChain(List<? extends Handler> handlerChain, MessageContext
ctx) { 
+    private boolean invokeHandlerChain(List<? extends Handler> handlerChain, MessageContext
ctx) {
         if (handlerChain.isEmpty()) {
-            LOG.log(Level.FINEST, "no handlers registered");        
+            LOG.log(Level.FINEST, "no handlers registered");
             return true;
         }
 
@@ -228,17 +217,17 @@
         }
 
         if (LOG.isLoggable(Level.FINE)) {
-            LOG.log(Level.FINE, "invoking handlers, direction: " + (outbound ? "outbound"
: "inbound"));  
+            LOG.log(Level.FINE, "invoking handlers, direction: " + (outbound ? "outbound"
: "inbound"));
         }
         setMessageOutboundProperty(ctx);
 
         if (!outbound) {
             handlerChain = reverseHandlerChain(handlerChain);
         }
-        
-        boolean continueProcessing = true; 
-        
-        WebServiceContextImpl.setMessageContext(ctx); 
+
+        boolean continueProcessing = true;
+
+        WebServiceContextImpl.setMessageContext(ctx);
 
         if (!faultRaised()) {
             continueProcessing = invokeHandleMessage(handlerChain, ctx);
@@ -252,79 +241,112 @@
             // the next set on handlers and they will be processing in
             // the correct direction.  It would be good refactor it
             // and control all of the processing here.
-            changeMessageDirection(ctx); 
+            changeMessageDirection(ctx);
             handlerProcessingAborted = true;
-            
-            //TODO: reverse chain, call handlerMessage or close            
+
+            //TODO: reverse chain, call handlerMessage or close
         }
-        return continueProcessing;        
-    }    
+        return continueProcessing;
+    }
 
     @SuppressWarnings("unchecked")
     private boolean invokeHandleFault(List<? extends Handler> handlerChain, MessageContext
ctx) {
-        
-        boolean continueProcessing = true; 
+
+        boolean continueProcessing = true;
 
         try {
             for (Handler h : handlerChain) {
                 if (invokeThisHandler(h)) {
                     closeHandlers.add(h);
+                    markHandlerInvoked(h);
                     continueProcessing = h.handleFault(ctx);
                 }
                 if (!continueProcessing) {
                     break;
                 }
-                markHandlerInvoked(h); 
+
             }
         } catch (RuntimeException e) {
             LOG.log(Level.WARNING, "HANDLER_RAISED_RUNTIME_EXCEPTION", e);
-            continueProcessing = false; 
+            continueProcessing = false;
             closed = true;
         }
         return continueProcessing;
-    } 
+    }
 
 
     @SuppressWarnings("unchecked")
-    private boolean invokeHandleMessage(List<? extends Handler> handlerChain, MessageContext
ctx) { 
+    private boolean invokeHandleMessage(List<? extends Handler> handlerChain, MessageContext
ctx) {
 
-        boolean continueProcessing = true; 
+        boolean continueProcessing = true;
         try {
             for (Handler h : handlerChain) {
                 if (invokeThisHandler(h)) {
                     closeHandlers.add(h);
+                    markHandlerInvoked(h);
                     continueProcessing = h.handleMessage(ctx);
                 }
                 if (!continueProcessing) {
                     callReversedHandlers(ctx);
                     break;
                 }
-                markHandlerInvoked(h); 
             }
         } catch (ProtocolException e) {
             LOG.log(Level.FINE, "handleMessage raised exception", e);
+            if (responseExpected) {
+                if (logicalMessageContext != null) {
+                    logicalMessageContext.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, !isOutbound());
+                }
+                if (protocolMessageContext != null) {
+                    protocolMessageContext.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY,
!isOutbound());
+                }
+                callReversedHandlesFault();
+            }
             continueProcessing = false;
+            closeHandlers();
             setFault(e);
+            throw e;
         } catch (RuntimeException e) {
             LOG.log(Level.WARNING, "HANDLER_RAISED_RUNTIME_EXCEPTION", e);
-            continueProcessing = false; 
-            closed = true;
+            continueProcessing = false;
+            closeHandlers();
+
+            throw e;
         }
         return continueProcessing;
-    } 
+    }
+
+    // REVISIT
+    // handleFault() return true\false, throw Exception.
+    private boolean callReversedHandlesFault() {
+        int index = invokedHandlers.size() - 2;
+        while (index >= 0) {
+            Handler handler = invokedHandlers.get(index);
+            if (handler instanceof LogicalHandler) {
+                if (Boolean.FALSE.equals(handler.
+                                         handleFault(logicalMessageContext))) {
+                    return false;
+                }
+            } else {
+                if (Boolean.FALSE.equals(handler.
+                                         handleFault(protocolMessageContext))) {
+                    return false;
+                }
+            }
+            index--;
+        }
+        return true;
+    }
 
     @SuppressWarnings("unchecked")
     private boolean callReversedHandlers(MessageContext ctx) {
-        int index = invokedHandlers.size() - 1;
+        int index = invokedHandlers.size() - 2;
         if (responseExpected) {
             while (index >= 0) {
-//                if (Boolean.FALSE.equals(invokedHandlers.get(index).handleMessage(ctx)))
{
-//                    return false;
-//                }
                 Handler handler = invokedHandlers.get(index);
                 if (handler instanceof LogicalHandler) {
                     if (Boolean.FALSE.equals(handler.
-                                             handleMessage(logicalMessageContext))) { 
+                                             handleMessage(logicalMessageContext))) {
                         return false;
                     }
                 } else {
@@ -336,11 +358,10 @@
                 index--;
             }
         }
-        closeHandlers(ctx);
         return true;
     }
 
-    private void closeHandlers(MessageContext ctx) {
+    private void closeHandlers() {
         int index = invokedHandlers.size() - 1;
         while (index >= 0) {
             Handler handler = invokedHandlers.get(index);
@@ -349,10 +370,12 @@
             } else {
                 handler.close(protocolMessageContext);
             }
+            invokedHandlers.remove(index);
             index--;
         }
+        closed = true;
     }
-    
+
     private boolean invokeThisHandler(Handler h) {
         boolean ret = true;
         // when handler processing has been aborted, only invoked on
@@ -364,34 +387,34 @@
         if (ret && LOG.isLoggable(Level.FINE)) {
             LOG.log(Level.FINE, "invoking handler of type " + h.getClass().getName());
         }
-        return ret; 
+        return ret;
     }
 
 
     private void markHandlerInvoked(Handler h) {
-        if (!invokedHandlers.contains(h)) { 
+        if (!invokedHandlers.contains(h)) {
             invokedHandlers.add(h);
         }
     }
 
-    private void changeMessageDirection(MessageContext context) { 
+    private void changeMessageDirection(MessageContext context) {
         outbound = !outbound;
         setMessageOutboundProperty(context);
-        // context.put(ObjectMessageContext.MESSAGE_INPUT, Boolean.TRUE);   
+        // context.put(ObjectMessageContext.MESSAGE_INPUT, Boolean.TRUE);
     }
-    
+
     private void setMessageOutboundProperty(MessageContext context) {
         context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, this.outbound);
     }
-    
+
     private <T extends Handler> List<T> reverseHandlerChain(List<T> handlerChain)
{
         List<T> reversedHandlerChain = new ArrayList<T>();
         reversedHandlerChain.addAll(handlerChain);
         Collections.reverse(reversedHandlerChain);
         return reversedHandlerChain;
     }
-    
-    protected final void setFault(Exception ex) { 
+
+    protected final void setFault(Exception ex) {
         /*
         context.put(ObjectMessageContext.METHOD_FAULT, ex);
         context.setScope(ObjectMessageContext.METHOD_FAULT, MessageContext.Scope.HANDLER);

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java?view=diff&rev=502515&r1=502514&r2=502515
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java
Thu Feb  1 22:05:36 2007
@@ -46,7 +46,6 @@
     Message message = new MessageImpl();
     LogicalMessageContext lmc = new LogicalMessageContextImpl(message);
     MessageContext pmc = new WrappedMessageContext(message);
-    StreamMessageContext smc = new StreamMessageContextImpl(message);
 
     TestLogicalHandler[] logicalHandlers = new TestLogicalHandler[HANDLER_COUNT];
     TestProtocolHandler[] protocolHandlers = new TestProtocolHandler[HANDLER_COUNT];
@@ -151,7 +150,7 @@
         ret = invoker.invokeLogicalHandlers(false, lmc);
         assertTrue(ret);
         assertFalse(invoker.isClosed());
-        assertEquals(1, logicalHandlers[0].getHandleMessageCount());
+        assertEquals(2, logicalHandlers[0].getHandleMessageCount());
         assertEquals(0, logicalHandlers[1].getHandleMessageCount());
         assertTrue(invoker.isInbound());
     }
@@ -181,16 +180,23 @@
         ProtocolException pe = new ProtocolException("banzai");
         logicalHandlers[1].setException(pe);
 
-        boolean continueProcessing = invoker.invokeLogicalHandlers(false, lmc);
-        assertFalse(continueProcessing);
+        boolean continueProcessing = true;
+        try {
+            continueProcessing = invoker.invokeLogicalHandlers(false, lmc);
+            fail("did not get expected exception");
+        } catch (ProtocolException e) {
+            assertEquals("banzai", e.getMessage());
+        }
         assertTrue(invoker.faultRaised());
 
         assertEquals(1, logicalHandlers[0].getHandleMessageCount());
         assertEquals(1, logicalHandlers[1].getHandleMessageCount());
+
         continueProcessing = invoker.invokeLogicalHandlers(false, lmc);
-        assertTrue(continueProcessing);
+
+        assertFalse(continueProcessing);
         assertTrue(invoker.faultRaised());
-        assertFalse(invoker.isClosed());
+        assertTrue(invoker.isClosed());
         assertSame(pe, invoker.getFault());
 
         assertEquals(1, logicalHandlers[0].getHandleMessageCount());
@@ -210,8 +216,13 @@
         RuntimeException re = new RuntimeException("banzai");
         logicalHandlers[1].setException(re);
 
-        boolean continueProcessing = invoker.invokeLogicalHandlers(false, lmc);
-        assertFalse(continueProcessing);
+        boolean continueProcessing = true;
+        try {
+            continueProcessing = invoker.invokeLogicalHandlers(false, lmc);
+            fail("did not get expected exception");
+        } catch (RuntimeException e) {
+            assertEquals("banzai", e.getMessage());
+        }
         assertFalse(invoker.faultRaised());
         assertTrue(invoker.isClosed());
 
@@ -322,8 +333,8 @@
         doInvokeProtocolHandlers(true);
         invoker.invokeLogicalHandlers(true, lmc);
 
-        assertEquals(2, invoker.getInvokedHandlers().size());
-        assertTrue(!invoker.getInvokedHandlers().contains(logicalHandlers[1]));
+        assertEquals(3, invoker.getInvokedHandlers().size());
+//        assertTrue(!invoker.getInvokedHandlers().contains(logicalHandlers[1]));
         assertTrue(invoker.getInvokedHandlers().contains(protocolHandlers[0]));
         assertTrue(invoker.getInvokedHandlers().contains(protocolHandlers[1]));
         assertEquals(0, logicalHandlers[0].getHandleMessageCount());
@@ -335,10 +346,10 @@
         // now, invoke handlers on outbound leg
         invoker.invokeLogicalHandlers(true, lmc);
 
-        assertEquals(1, logicalHandlers[1].getHandleMessageCount());
+        assertEquals(2, logicalHandlers[1].getHandleMessageCount());
         assertEquals(0, logicalHandlers[0].getHandleMessageCount());
-        assertEquals(2, protocolHandlers[0].getHandleMessageCount());
-        assertEquals(2, protocolHandlers[1].getHandleMessageCount());
+        assertEquals(3, protocolHandlers[0].getHandleMessageCount());
+        assertEquals(3, protocolHandlers[1].getHandleMessageCount());
 
     }
 

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java?view=diff&rev=502515&r1=502514&r2=502515
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
Thu Feb  1 22:05:36 2007
@@ -198,7 +198,7 @@
     }
 
     //TODO: commented out due to CXF-333
-    public void xtestLogicalHandlerThrowsProtocolExceptionClientSide() throws Exception {
+    public void testLogicalHandlerThrowsProtocolExceptionClientSide() throws Exception {
 
         final String clientHandlerMessage = "handler1 client side";
 
@@ -219,6 +219,7 @@
             assertEquals(clientHandlerMessage, e.getMessage());
         }
         assertTrue(!handler2.isHandleFaultInvoked());
+        
         assertTrue(handler1.isCloseInvoked());
         assertTrue(!handler2.isCloseInvoked());
     }



Mime
View raw message