cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r540898 - in /incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws: handler/ handler/logical/ handler/soap/ support/
Date Wed, 23 May 2007 09:19:10 GMT
Author: jliu
Date: Wed May 23 02:19:09 2007
New Revision: 540898

URL: http://svn.apache.org/viewvc?view=rev&rev=540898
Log:
code clean up in handler related area.

Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerInInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerOutInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultInInterceptor.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/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.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=540898&r1=540897&r2=540898
==============================================================================
--- 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
Wed May 23 02:19:09 2007
@@ -52,7 +52,7 @@
 import org.apache.cxf.message.Message;
 
 /**
- * invoke invoke the handlers in a registered handler chain
+ * invoke the handlers in a registered handler chain
  */
 public class HandlerChainInvoker {
 
@@ -68,7 +68,6 @@
     private boolean isRequestor;
     private boolean responseExpected = true;
     private boolean faultExpected;
-    //private boolean handlerProcessingAborted;
     private boolean closed;
     private boolean messageDirectionReversed;
     private Exception fault;
@@ -121,30 +120,22 @@
     }
 
     public boolean invokeLogicalHandlers(boolean requestor, LogicalMessageContext context)
{
-        // objectCtx.setRequestorRole(requestor);
         context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, isOutbound());
         return invokeHandlerChain(logicalHandlers, context);
     }
 
     public boolean invokeLogicalHandlersHandleFault(boolean requestor, LogicalMessageContext
context) {
-        // objectCtx.setRequestorRole(requestor);
         context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, isOutbound());
         return invokeHandlerChainHandleFault(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());
 
         return invokeHandlerChain(protocolHandlers, context);
     }
 
     public boolean invokeProtocolHandlersHandleFault(boolean requestor, MessageContext context)
{
-        // WrappedMessageContext context = new WrappedMessageContext(message);
-        // bindingContext.put(ObjectMessageContext.REQUESTOR_ROLE_PROPERTY,
-        // requestor);
         context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, isOutbound());
 
         return invokeHandlerChainHandleFault(protocolHandlers, context);
@@ -167,9 +158,9 @@
     }
 
     /**
-     * We need HandlerChainInvoker behaves differently on client and server
-     * side. For client side, as we do not have a faultChain, we need to call
-     * handleFault and close on within HandlerChainInvoker directly.
+     * We need HandlerChainInvoker behaves differently on the client and server
+     * side. For the client side, as there is no inbound faultChain, we need to call
+     * handleFault and close within HandlerChainInvoker directly.
      */
     public boolean isRequestor() {
         return isRequestor;
@@ -220,7 +211,6 @@
 
     /**
      * Indicates that the invoker is closed. When closed, only
-     * 
      * @see #mepComplete may be called. The invoker will become closed if during
      *      a invocation of handlers, a handler throws a runtime exception that
      *      is not a protocol exception and no futher handler or message
@@ -244,33 +234,8 @@
     List getInvokedHandlers() {
         return Collections.unmodifiableList(invokedHandlers);
     }
-    
-/*
-    private <T extends Handler> void invokeClose(List<T> handlers, MessageContext
context) {
-        if (isOutbound()) {
-            handlers = reverseHandlerChain(handlers);
-        }
-        if (messageDirectionReversed) {
-            handlers = reverseHandlerChain(handlers);            
-        }
 
-        // handlers = reverseHandlerChain(handlers);
-        for (Handler h : handlers) {
-            if (closeHandlers.contains(h)) {
-                System.out.println("===========invokeClose " + h.toString());
-                h.close(context);
-            }
-        }
-    }*/
-    
-    //REVISIT
-    /*
-     * the logic of current implemetation is if the exception is thrown from
-     * previous handlers, we only invoke handleFault if it is ProtocolException
-     * (per spec), if the exception is thrown from other places other than
-     * handlers, we always invoke handleFault.
-     */
-    private boolean invokeHandlerChainHandleFault(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");
             return true;
@@ -279,12 +244,6 @@
         if (isClosed()) {
             return false;
         }
-        
-        //The fault is raised from previous handlers, in this case, we only invoke handleFault
-        //if the fault is a ProtocolException
-        if (fault != null && !(fault instanceof ProtocolException)) {
-            return true;
-        }
 
         if (LOG.isLoggable(Level.FINE)) {
             LOG.log(Level.FINE, "invoking handlers, direction: " + (outbound ? "outbound"
: "inbound"));
@@ -296,18 +255,19 @@
         }
 
         boolean continueProcessing = true;
-
         WebServiceContextImpl.setMessageContext(ctx);
+        continueProcessing = invokeHandleMessage(handlerChain, ctx);
 
-        continueProcessing = invokeHandleFault(handlerChain, ctx);
-
-/*        if (!continueProcessing) {
-            handlerProcessingAborted = true;
-        }*/
         return continueProcessing;
     }
 
-    private boolean invokeHandlerChain(List<? extends Handler> handlerChain, MessageContext
ctx) {
+    /*
+     * REVISIT: the logic of current implemetation is if the exception is thrown
+     * from previous handlers, we only invoke handleFault if it is
+     * ProtocolException (per spec), if the exception is thrown from other
+     * places other than handlers, we always invoke handleFault.
+     */
+    private boolean invokeHandlerChainHandleFault(List<? extends Handler> handlerChain,
MessageContext ctx) {
         if (handlerChain.isEmpty()) {
             LOG.log(Level.FINEST, "no handlers registered");
             return true;
@@ -316,6 +276,12 @@
         if (isClosed()) {
             return false;
         }
+        
+        //The fault is raised from previous handlers, in this case, we only invoke handleFault
+        //if the fault is a ProtocolException
+        if (fault != null && !(fault instanceof ProtocolException)) {
+            return true;
+        }
 
         if (LOG.isLoggable(Level.FINE)) {
             LOG.log(Level.FINE, "invoking handlers, direction: " + (outbound ? "outbound"
: "inbound"));
@@ -327,21 +293,12 @@
         }
 
         boolean continueProcessing = true;
-
         WebServiceContextImpl.setMessageContext(ctx);
+        continueProcessing = invokeHandleFault(handlerChain, ctx);
 
-        if (!faultRaised()) {
-            continueProcessing = invokeHandleMessage(handlerChain, ctx);
-        } else {
-            continueProcessing = invokeHandleFault(handlerChain, ctx);
-        }
-
-/*        if (!continueProcessing) {
-            handlerProcessingAborted = true;
-        }*/
         return continueProcessing;
     }
-
+    
     @SuppressWarnings("unchecked")
     private boolean invokeHandleFault(List<? extends Handler> handlerChain, MessageContext
ctx) {
         boolean continueProcessing = true;
@@ -367,10 +324,6 @@
         return continueProcessing;
     }
 
-    private boolean isTheLastInvokedHandler(Handler h) {
-        return invokedHandlers.contains(h) && invokedHandlers.indexOf(h) == (invokedHandlers.size()
- 1);
-    }
-
     @SuppressWarnings("unchecked")
     private boolean invokeHandleMessage(List<? extends Handler> handlerChain, MessageContext
ctx) {
         boolean continueProcessing = true;
@@ -386,7 +339,6 @@
                     if (responseExpected) {
                         changeMessageDirection(ctx);
                         messageDirectionReversed = true;
-                        //invokeReversedClose();
                     }
 
                     break;
@@ -394,12 +346,10 @@
             }
         } catch (ProtocolException e) {
             LOG.log(Level.FINE, "handleMessage raised exception", e);
-            messageDirectionReversed = true;
-            
+             
             if (responseExpected) {
                 changeMessageDirection(ctx);
                 messageDirectionReversed = true;
-                //invokeReversedClose();
             }
 
             //special case for client side, this is because we do nothing in client fault
@@ -483,13 +433,7 @@
             // do nothing
         }
     }
-
-    /*
-     * The message direction is reversed, if the message is not already a fault
-     * message then it is replaced with a fault message, and the runtime invokes
-     * handleFault on the next handler or dispatches the message if there are no
-     * further handlers.
-     */    
+ 
     @SuppressWarnings("unchecked")
     private boolean invokeReversedHandleFault(MessageContext ctx) {
         boolean continueProcessing = true;
@@ -521,14 +465,6 @@
         }
         invokeReversedClose();
         return continueProcessing;
-        /*
-         * 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;
-         */
     }
 
     /*
@@ -567,6 +503,10 @@
         return ret;
     }
 
+    private boolean isTheLastInvokedHandler(Handler h) {
+        return invokedHandlers.contains(h) && invokedHandlers.indexOf(h) == (invokedHandlers.size()
- 1);
+    }
+    
     private void markHandlerInvoked(Handler h) {
         if (!invokedHandlers.contains(h)) {
             invokedHandlers.add(h);
@@ -576,7 +516,6 @@
     private void changeMessageDirection(MessageContext context) {
         outbound = !outbound;
         setMessageOutboundProperty(context);
-        // context.put(ObjectMessageContext.MESSAGE_INPUT, Boolean.TRUE);
     }
 
     private void setMessageOutboundProperty(MessageContext context) {
@@ -597,11 +536,6 @@
     }
 
     protected final void setFault(Exception ex) {
-        /*
-         * context.put(ObjectMessageContext.METHOD_FAULT, ex);
-         * context.setScope(ObjectMessageContext.METHOD_FAULT,
-         * MessageContext.Scope.HANDLER);
-         */
         fault = ex;
     }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerInInterceptor.java?view=diff&rev=540898&r1=540897&r2=540898
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerInInterceptor.java
Wed May 23 02:19:09 2007
@@ -59,6 +59,7 @@
         boolean requestor = isRequestor(message);
         if (!invoker.invokeLogicalHandlers(requestor, lctx)) {
             if (!requestor) {
+                //server side 
                 handleAbort(message, null);
             } else {
                 //Client side inbound, thus no response expected, do nothing, the close will
 
@@ -76,11 +77,10 @@
         message.getInterceptorChain().abort();
 
         if (!message.getExchange().isOneWay()) {
+            //server side inbound
             Endpoint e = message.getExchange().get(Endpoint.class);
             Message responseMsg = e.getBinding().createMessage();            
 
-            //server side inbound
-
             message.getExchange().setOutMessage(responseMsg);
             XMLStreamReader reader = message.getContent(XMLStreamReader.class);
             if (reader == null && writer != null) {
@@ -91,9 +91,7 @@
                 .getOutInterceptorChain(message.getExchange());
             responseMsg.setInterceptorChain(chain);
             responseMsg.put("LogicalHandlerInterceptor.INREADER", reader);
-            //so the idea of starting interceptor chain from any specified point does not
work
-            //well for outbound case, as many outbound interceptors have their ending interceptors.
-            //For example, we can not skip MessageSenderInterceptor.               
+              
             chain.doIntercept(responseMsg);
         }        
     }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerOutInterceptor.java?view=diff&rev=540898&r1=540897&r2=540898
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerOutInterceptor.java
Wed May 23 02:19:09 2007
@@ -43,7 +43,9 @@
 
 public class LogicalHandlerOutInterceptor<T extends Message> 
     extends AbstractJAXWSHandlerInterceptor<T> {
-
+    
+    public static final String ORIGINAL_WRITER = "original_writer";
+    
     public LogicalHandlerOutInterceptor(Binding binding) {
         super(binding);
         setPhase(Phase.PRE_MARSHAL);
@@ -61,13 +63,11 @@
             W3CDOMStreamWriter writer = new W3CDOMStreamWriter(XMLUtils.newDocument());
         
             // Replace stax writer with DomStreamWriter
-            message.setContent(XMLStreamWriter.class, writer);
-        
-        
+            message.setContent(XMLStreamWriter.class, writer);        
+            message.put(ORIGINAL_WRITER, origWriter);
+            
             message.getInterceptorChain().add(new LogicalHandlerOutEndingInterceptor<T>(
-                    getBinding(),
-                    origWriter,
-                    writer));
+                    getBinding()));
         } catch (ParserConfigurationException e) {
             throw new Fault(e);
         }
@@ -77,20 +77,18 @@
     private class LogicalHandlerOutEndingInterceptor<X extends Message> 
         extends AbstractJAXWSHandlerInterceptor<X> {
     
-        XMLStreamWriter origWriter;
-        W3CDOMStreamWriter domWriter;
-    
-        public LogicalHandlerOutEndingInterceptor(Binding binding,
-                                           XMLStreamWriter o,
-                                           W3CDOMStreamWriter n) {
+        public LogicalHandlerOutEndingInterceptor(Binding binding) {
             super(binding);
-            origWriter = o;
-            domWriter = n; 
-       
+            
             setPhase(Phase.POST_MARSHAL);
         }
     
         public void handleMessage(X message) throws Fault {
+            W3CDOMStreamWriter domWriter = (W3CDOMStreamWriter)message.getContent(XMLStreamWriter.class);
+            XMLStreamWriter origWriter = (XMLStreamWriter)message
+                .get(LogicalHandlerOutInterceptor.ORIGINAL_WRITER);  
+            
+            
             HandlerChainInvoker invoker = getInvoker(message);
             LogicalMessageContextImpl lctx = new LogicalMessageContextImpl(message);
             invoker.setLogicalMessageContext(lctx);
@@ -107,8 +105,7 @@
                 message.setContent(Source.class, source);
                 message.setContent(XMLStreamReader.class, 
                                    StaxUtils.createXMLStreamReader(domWriter.getDocument()));
-            }
-            
+            }            
             
             if (!invoker.invokeLogicalHandlers(requestor, lctx)) {
                 if (requestor) {
@@ -121,19 +118,17 @@
                                 .get(MessageObserver.class);
                     if (observer != null) {
                         //client side outbound, the request message becomes the response
message
-                        responseMsg.setContent(XMLStreamReader.class,
-                                               message.getContent(XMLStreamReader.class));
-                        
+                        responseMsg.setContent(XMLStreamReader.class, message
+                            .getContent(XMLStreamReader.class));                        
                         
                         message.getExchange().setInMessage(responseMsg);
                         responseMsg.put(PhaseInterceptorChain.STARTING_AT_INTERCEPTOR_ID,
                                         LogicalHandlerInInterceptor.class.getName());
                         observer.onMessage(responseMsg);
-                        //invoker.mepComplete(responseMsg);
                     }
                 } else {
                     // server side - abort
-                    System.out.println("Logical handler server side aborting");
+                    //System.out.println("Logical handler server side aborting");
                 }
                 return;
             }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultInInterceptor.java?view=diff&rev=540898&r1=540897&r2=540898
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultInInterceptor.java
Wed May 23 02:19:09 2007
@@ -103,7 +103,7 @@
                 // stops, but the inbound interceptor chain still continues, dispatch the
message
                 //By onCompletion here, we can skip rest Logical handlers 
                 onCompletion(message);
-                System.out.println("SOAP Handler handleMessage returns false on client inbound,
aborting");
+                //System.out.println("SOAP Handler handleMessage returns false on client
inbound, aborting");
             }
         } else {
             if (!getInvoker(message).isOutbound()) {

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=540898&r1=540897&r2=540898
==============================================================================
--- 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
Wed May 23 02:19:09 2007
@@ -70,7 +70,7 @@
 
     public Set<URI> getRoles() {
         Set<URI> roles = new HashSet<URI>();
-        // TODO
+        //TODO
         return roles;
     }
 
@@ -124,15 +124,6 @@
         MessageContext context = createProtocolMessageContext(message);
         HandlerChainInvoker invoker = getInvoker(message);
         invoker.setProtocolMessageContext(context);
-
-/*        if (!invoker.invokeProtocolHandlers(isRequestor(message), context)) {
-            handleAbort(message, context);
-        } else {
-            //if message processing ends normally, close previously invoked handlers.
-            if (isOutbound(message)) {
-                onCompletion(message);
-            }
-        }*/
         
         if (!invoker.invokeProtocolHandlers(isRequestor(message), context)) {
             handleAbort(message, context);
@@ -175,11 +166,10 @@
                 // stops, but the inbound interceptor chain still continues, dispatch the
message
                 //By onCompletion here, we can skip following Logical handlers 
                 onCompletion(message);
-                System.out.println("SOAP Handler handleMessage returns false on client inbound,
aborting");
+                //System.out.println("SOAP Handler handleMessage returns false on client
inbound, aborting");
             }
         } else {
             if (!getInvoker(message).isOutbound()) {
-
                 // server side inbound
                 message.getInterceptorChain().abort();
                 Endpoint e = message.getExchange().get(Endpoint.class);
@@ -204,7 +194,7 @@
             } else {
                 // server side outbound - Normal handler message processing
                 // stops, but still continue the outbound interceptor chain, dispatch the
message
-                System.out.println("SOAP Handler handleMessage returns false on server outbound,
aborting");
+                //System.out.println("SOAP Handler handleMessage returns false on server
outbound, aborting");
             }
         }
     }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java?view=diff&rev=540898&r1=540897&r2=540898
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java
Wed May 23 02:19:09 2007
@@ -76,9 +76,7 @@
         
         LogicalHandlerFaultOutInterceptor lh = new LogicalHandlerFaultOutInterceptor(binding);
         fault.add(lh);
-        //fault.add(new LogicalHandlerOutInterceptor(binding));
         if (getBinding() instanceof SoapBinding) {
-            //fault.add(soap);
             SOAPHandlerFaultOutInterceptor sh = new SOAPHandlerFaultOutInterceptor(binding);
             fault.add(sh);
         }



Mime
View raw message