cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r535369 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/ systests/src/test/java/org/apache/cxf/systest/handlers/
Date Fri, 04 May 2007 20:01:34 GMT
Author: jliu
Date: Fri May  4 13:01:34 2007
New Revision: 535369

URL: http://svn.apache.org/viewvc?view=rev&rev=535369
Log:
CXF-632: When protocol handlers' handleMessage returns false, stop the outbound interceptor
chain, start the inbound interceptor chain, the request message becomes the response message.



Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AbstractProtocolHandlerInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.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/AbstractProtocolHandlerInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AbstractProtocolHandlerInterceptor.java?view=diff&rev=535369&r1=535368&r2=535369
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AbstractProtocolHandlerInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AbstractProtocolHandlerInterceptor.java
Fri May  4 13:01:34 2007
@@ -26,6 +26,7 @@
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
 
+
 public abstract class AbstractProtocolHandlerInterceptor<T extends Message> 
     extends AbstractJAXWSHandlerInterceptor<T> {
     
@@ -38,7 +39,8 @@
         MessageContext context = createProtocolMessageContext(message);
         HandlerChainInvoker invoker = getInvoker(message);
         invoker.setProtocolMessageContext(context);
-        invoker.invokeProtocolHandlers(isRequestor(message), context);
+        invoker.invokeProtocolHandlers(isRequestor(message), context);      
+        
         onCompletion(message);
     }
     

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=535369&r1=535368&r2=535369
==============================================================================
--- 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
Fri May  4 13:01:34 2007
@@ -33,6 +33,7 @@
 import javax.xml.ws.handler.Handler;
 import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
 
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
@@ -43,9 +44,13 @@
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.StaxOutInterceptor;
 import org.apache.cxf.jaxws.handler.AbstractProtocolHandlerInterceptor;
+import org.apache.cxf.jaxws.handler.HandlerChainInvoker;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.phase.Phase;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.transport.MessageObserver;
 
 public class SOAPHandlerInterceptor extends
         AbstractProtocolHandlerInterceptor<SoapMessage> implements
@@ -83,55 +88,76 @@
         if (getInvoker(message).getProtocolHandlers().isEmpty()) {
             return;
         }
-        
+
         if (getInvoker(message).isOutbound()) {
-            SOAPMessage saaj = message.getContent(SOAPMessage.class); 
+            SOAPMessage saaj = message.getContent(SOAPMessage.class);
             if (saaj == null) {
                 SAAJ_OUT.handleMessage(message);
             }
-            
-            final SOAPHandlerInterceptor handlerInterceptor = this;
-            message.getInterceptorChain().add(new AbstractSoapInterceptor() {
 
+            message.getInterceptorChain().add(new AbstractSoapInterceptor() {
                 @Override
                 public String getPhase() {
                     return Phase.USER_PROTOCOL;
                 }
 
                 public void handleMessage(SoapMessage message) throws Fault {
-                    handlerInterceptor.invokeSOAPHandlerInterceptors(message);
+                    MessageContext context = createProtocolMessageContext(message);
+                    HandlerChainInvoker invoker = getInvoker(message);
+                    invoker.setProtocolMessageContext(context);
+
+                    if (!invoker.invokeProtocolHandlers(isRequestor(message), context)) {
+                        message.getInterceptorChain().abort();
+                        Message responseMsg = new MessageImpl();
+                        message.getExchange().setInMessage(responseMsg);
+
+                        MessageObserver observer = (MessageObserver)message.getExchange()
+                            .get(MessageObserver.class);
+                        responseMsg.put(PhaseInterceptorChain.STARTING_AFTER_INTERCEPTOR_ID,
+                                        SOAPHandlerInterceptor.class.getName());
+                        // The request message becomes the response message
+                        if (observer != null) {
+                            SOAPMessage soapMessage = ((SOAPMessageContext)context).getMessage();
+
+                            if (soapMessage != null) {
+                                responseMsg.setContent(SOAPMessage.class, soapMessage);
+                                XMLStreamReader xmlReader = createXMLStreamReaderFromSOAPMessage(soapMessage);
+                                responseMsg.setContent(XMLStreamReader.class, xmlReader);
+                            }
+                            observer.onMessage(responseMsg);
+                        } 
+                    }
                 }
             });
         } else {
             super.handleMessage(message);
             SOAPMessage msg = message.getContent(SOAPMessage.class);
             if (msg != null) {
-                DOMSource bodySource;
-                try {
-                    bodySource = new DOMSource(msg.getSOAPPart().getEnvelope().getBody());
-                    XMLStreamReader xmlReader = StaxUtils.createXMLStreamReader(bodySource);
-                    xmlReader.nextTag();
-                    xmlReader.nextTag(); // move past body tag
-                    message.setContent(XMLStreamReader.class, xmlReader);
-                } catch (SOAPException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                } catch (XMLStreamException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                }
-
+                XMLStreamReader xmlReader = createXMLStreamReaderFromSOAPMessage(msg);
+                message.setContent(XMLStreamReader.class, xmlReader);
             }
         }
     }
-
-    protected void invokeSOAPHandlerInterceptors(SoapMessage message) {
-        super.handleMessage(message);
-    }
     
     @Override
     protected MessageContext createProtocolMessageContext(Message message) {
         return new SOAPMessageContextImpl(message);
+    }
+    
+    private XMLStreamReader createXMLStreamReaderFromSOAPMessage(SOAPMessage soapMessage)
{
+        // responseMsg.setContent(SOAPMessage.class, soapMessage);
+        XMLStreamReader xmlReader = null;
+        try {
+            DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
+            xmlReader = StaxUtils.createXMLStreamReader(bodySource);
+            xmlReader.nextTag();
+            xmlReader.nextTag(); // move past body tag
+        } catch (SOAPException e) {
+            e.printStackTrace();
+        } catch (XMLStreamException e) {
+            e.printStackTrace();
+        }
+        return xmlReader;
     }
 
     public void handleFault(SoapMessage message) {

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=535369&r1=535368&r2=535369
==============================================================================
--- 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
Fri May  4 13:01:34 2007
@@ -150,7 +150,6 @@
         // the server has encoded into the response the order in
         // which the handlers have been invoked, parse it and make
         // sure everything is ok
-
         // expected order for inbound interceptors
         String[] handlerNames = {"soapHandler4", "soapHandler3", "handler2", "handler1",
"servant",
                                  "handler1", "handler2", "soapHandler3", "soapHandler4"};
@@ -304,31 +303,53 @@
 
     @Test
     public void testSOAPHandlerHandleMessageReturnFalseClientSide() throws Exception {
+        final String clientHandlerMessage = "client side";
         TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false);
-        TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false);
+        TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false)
{
+            public boolean handleMessage(LogicalMessageContext ctx) {
+                super.handleMessage(ctx);
+                try {
+                    Boolean outbound = (Boolean)ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+                    if (outbound) {
+                        LogicalMessage msg = ctx.getMessage();
+                        assertNotNull("logical message is null", msg);
+                        JAXBContext jaxbCtx = JAXBContext.newInstance(PackageUtils
+                            .getPackageName(PingOneWay.class));
+                        PingResponse resp = new PingResponse();
+                        resp.getHandlersInfo().add(clientHandlerMessage);
+
+                        msg.setPayload(resp, jaxbCtx);
+                    }
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    fail(e.toString());
+                }
+                return true;
+            }
+        };
         TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
         TestSOAPHandler soapHandler2 = new TestSOAPHandler<SOAPMessageContext>(false)
{
             public boolean handleMessage(SOAPMessageContext ctx) {
                 super.handleMessage(ctx);
+
                 return false;
             }
         };
         addHandlersToChain((BindingProvider)handlerTest, handler1, handler2, soapHandler1,
soapHandler2);
 
-        handlerTest.ping();
-        //List<String> resp = handlerTest.ping();
-        // assertEquals(clientHandlerMessage, resp.get(0));
+        List<String> resp = handlerTest.ping();
+        assertEquals(clientHandlerMessage, resp.get(0));
 
-        assertEquals(2, handler1.getHandleMessageInvoked());
-        assertEquals(2, handler2.getHandleMessageInvoked());
+        assertEquals(3, handler1.getHandleMessageInvoked());
+        assertEquals(3, handler2.getHandleMessageInvoked());
         assertEquals(2, soapHandler1.getHandleMessageInvoked());
-        //FIXME: CXF-632:
-        //assertEquals(1, soapHandler2.getHandleMessageInvoked());
+        assertEquals(1, soapHandler2.getHandleMessageInvoked());
     }
 
     @Test
     @Ignore
-    public void testLogicalHandlerHandlerFault() {
+    public void testLogicalHandlerHandlerFaultServerSide() {
 
         TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false);
         TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false);



Mime
View raw message