cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r470693 - in /incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap: SOAPHandlerInterceptorTest.java resources/greetMeRpcLitReq.xml resources/greetMeRpcLitResp.xml resources/greetMeRpcLitRespChanged.xml
Date Fri, 03 Nov 2006 07:01:43 GMT
Author: jliu
Date: Thu Nov  2 23:01:42 2006
New Revision: 470693

URL: http://svn.apache.org/viewvc?view=rev&rev=470693
Log:
Refactored SOAPHandlerInterceptorTest

Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitReq.xml
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitResp.xml
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespChanged.xml

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java?view=diff&rev=470693&r1=470692&r2=470693
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
Thu Nov  2 23:01:42 2006
@@ -24,34 +24,50 @@
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPBodyElement;
 import javax.xml.soap.SOAPMessage;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
 import javax.xml.ws.Binding;
 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.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
 import junit.framework.TestCase;
 
 import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.SoapVersion;
+import org.apache.cxf.binding.soap.SoapVersionFactory;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.InterceptorChain;
 import org.apache.cxf.io.AbstractCachedOutputStream;
+import org.apache.cxf.jaxws.handler.AbstractProtocolHandlerInterceptor;
 import org.apache.cxf.jaxws.handler.HandlerChainInvoker;
 import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.phase.PhaseInterceptorChain;
+import org.apache.cxf.phase.PhaseManagerImpl;
+import org.apache.cxf.staxutils.PartialXMLStreamReader;
+import org.apache.cxf.staxutils.StaxUtils;
 
 import org.easymock.classextension.IMocksControl;
 
 import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.isA;
-import static org.easymock.EasyMock.notNull;
 import static org.easymock.classextension.EasyMock.createNiceControl;
 
 public class SOAPHandlerInterceptorTest extends TestCase {
@@ -86,34 +102,47 @@
 
         IMocksControl control = createNiceControl();
         Binding binding = control.createMock(Binding.class);
-        SoapMessage message = control.createMock(SoapMessage.class);
         Exchange exchange = control.createMock(Exchange.class);
-        InterceptorChain chain = control.createMock(InterceptorChain.class);
+        SoapMessage message = new SoapMessage(new MessageImpl());
+        message.setExchange(exchange);
 
-        expect(chain.doInterceptInSubChain(isA(Message.class))).andReturn(true);
-        expect(message.getExchange()).andReturn(exchange).anyTimes();
-        expect(message.getInterceptorChain()).andReturn(chain);
-        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker);
-        // This is to set direction to outbound
-        expect(exchange.getOutMessage()).andReturn(message);
+        XMLStreamReader reader = preparemXMLStreamReader("resources/greetMeRpcLitReq.xml");
+        message.setContent(XMLStreamReader.class, reader);
 
+        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
+        // This is to set direction to inbound
+        expect(exchange.getOutMessage()).andReturn(message).anyTimes();
         CachedStream originalEmptyOs = new CachedStream();
-        SOAPMessage soapMessage = preparemSOAPMessage("resources/greetMeRpcLitResp.xml");
-        CachedStream os = prepareOutputStreamFromSOAPMessage(soapMessage);
-        expect(message.getContent(OutputStream.class)).andReturn(
-                originalEmptyOs);
-        expect(message.getContent(OutputStream.class)).andReturn(os);
+        message.setContent(OutputStream.class, originalEmptyOs);
+
+        InterceptorChain chain = new PhaseInterceptorChain((new PhaseManagerImpl()).getOutPhases());
+        // This is to simulate interceptors followed by SOAPHandlerInterceptor
+        // write outputStream
+        chain.add(new AbstractProtocolHandlerInterceptor<SoapMessage>(binding) {
+            public void handleMessage(SoapMessage message) throws Fault {
+                try {
+                    CachedStream os = prepareOutputStreamFromResource("resources/greetMeRpcLitResp.xml");
+                    message.setContent(OutputStream.class, os);
+                } catch (Exception e) {
+                    //do nothing
+                }
+            }
+
+        });
+        message.setInterceptorChain(chain);
         control.replay();
 
         SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
         li.handleMessage(message);
         control.verify();
 
-        // the content of outputStream should remain unchanged.
+        // Verify outputStream
         CachedStream expectedOs = prepareOutputStreamFromResource("resources/greetMeRpcLitResp.xml");
-        assertTrue("the content of os should remain unchanged",
-                compareInputStream(expectedOs.getInputStream(), originalEmptyOs
-                        .getInputStream()));
+        assertTrue("The content of outputStream should remain unchanged", compareInputStream(expectedOs
+            .getInputStream(), originalEmptyOs.getInputStream()));
+        // Verify SOAPMessage
+        SOAPMessage resultedMessage = message.getContent(SOAPMessage.class);
+        assertNull(resultedMessage);
     }
 
     // SAAJ tree is created on if SOAPMessageContext.getMessage() is
@@ -123,8 +152,7 @@
         List<Handler> list = new ArrayList<Handler>();
         list.add(new SOAPHandler<SOAPMessageContext>() {
             public boolean handleMessage(SOAPMessageContext smc) {
-                Boolean outboundProperty = (Boolean) smc
-                        .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+                Boolean outboundProperty = (Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                 if (outboundProperty.booleanValue()) {
                     try {
                         SOAPMessage message = smc.getMessage();
@@ -151,46 +179,72 @@
 
         IMocksControl control = createNiceControl();
         Binding binding = control.createMock(Binding.class);
-        SoapMessage message = control.createMock(SoapMessage.class);
         Exchange exchange = control.createMock(Exchange.class);
-        InterceptorChain chain = control.createMock(InterceptorChain.class);
+        SoapMessage message = new SoapMessage(new MessageImpl());
+        message.setExchange(exchange);
 
-        expect(chain.doInterceptInSubChain(isA(Message.class))).andReturn(true);
-        expect(message.get(notNull())).andReturn(true).anyTimes();
-        expect(message.keySet()).andReturn(new HashSet()).anyTimes();
-        expect(message.getExchange()).andReturn(exchange).anyTimes();
-        expect(message.getInterceptorChain()).andReturn(chain);
-        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker)
-                .anyTimes();
-        // message.getExchange().get(HandlerChainInvoker.class);
-
-        // This is to set direction to outbound
-        expect(exchange.getOutMessage()).andReturn(message);
+        XMLStreamReader reader = preparemXMLStreamReader("resources/greetMeRpcLitReq.xml");
+        message.setContent(XMLStreamReader.class, reader);
 
+        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
+        // This is to set direction to inbound
+        expect(exchange.getOutMessage()).andReturn(message).anyTimes();
         CachedStream originalEmptyOs = new CachedStream();
-        SOAPMessage soapMessage = preparemSOAPMessage("resources/greetMeRpcLitResp.xml");
-        expect(message.getContent(SOAPMessage.class)).andReturn(soapMessage);
-        SOAPMessage soapMessageChanged = preparemSOAPMessage("resources/greetMeRpcLitRespChanged.xml");
-        expect(message.getContent(SOAPMessage.class)).andReturn(
-                soapMessageChanged);
-        expect(message.getContent(OutputStream.class)).andReturn(
-                originalEmptyOs);
+        message.setContent(OutputStream.class, originalEmptyOs);
+
+        InterceptorChain chain = new PhaseInterceptorChain((new PhaseManagerImpl()).getOutPhases());
+        // This is to simulate interceptors followed by SOAPHandlerInterceptor
+        // write outputStream
+        chain.add(new AbstractProtocolHandlerInterceptor<SoapMessage>(binding) {
+            public void handleMessage(SoapMessage message) throws Fault {
+                try {
+                    CachedStream os = prepareOutputStreamFromResource(
+                        "resources/greetMeRpcLitRespChanged.xml");
+                    message.setContent(OutputStream.class, os);
+                } catch (Exception e) {
+                    //do nothing
+                }
+            }
+
+        });
+        message.setInterceptorChain(chain);
         control.replay();
 
         SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
         li.handleMessage(message);
         control.verify();
 
-        // the content of outputStream should remain unchanged.
+        // Verify outputStream
         CachedStream expectedOs = prepareOutputStreamFromResource("resources/greetMeRpcLitRespChanged.xml");
-        assertTrue("the content of os should have changed", compareInputStream(
-                expectedOs.getInputStream(), originalEmptyOs.getInputStream()));
+        assertTrue("The content of outputStream should remain unchanged", compareInputStream(expectedOs
+            .getInputStream(), originalEmptyOs.getInputStream()));
+
+        // Verify SOAPMessage
+        SOAPMessage resultedMessage = message.getContent(SOAPMessage.class);
+        assertNotNull(resultedMessage);
+        SOAPBody bodyNew = resultedMessage.getSOAPBody();
+        Iterator itNew = bodyNew.getChildElements(new QName("http://apache.org/hello_world_rpclit",
+                                                            "sendReceiveDataResponse"));
+        SOAPBodyElement bodyElementNew = (SOAPBodyElement)itNew.next();
+        Iterator outIt = bodyElementNew
+            .getChildElements(new QName("http://apache.org/hello_world_rpclit/types", "out"));
+        Element outElement = (SOAPBodyElement)outIt.next();
+        assertNotNull(outElement);
+        NodeList elem3NodeList = outElement
+            .getElementsByTagNameNS("http://apache.org/hello_world_rpclit/types", "elem3");
+        Node elem3Element = elem3NodeList.item(0);
+        assertNotNull("100", elem3Element.getTextContent());
     }
 
-    public void xtestInterceptSuccessInBound() throws Exception {
+    public void xtestGetSOAPMessageInBound() throws Exception {
         List<Handler> list = new ArrayList<Handler>();
         list.add(new SOAPHandler<SOAPMessageContext>() {
             public boolean handleMessage(SOAPMessageContext smc) {
+                try {
+                    SOAPMessage message = smc.getMessage();
+                } catch (Exception e) {
+                    throw new Fault(e);
+                }
                 return true;
             }
 
@@ -209,33 +263,36 @@
 
         IMocksControl control = createNiceControl();
         Binding binding = control.createMock(Binding.class);
-        SoapMessage message = control.createMock(SoapMessage.class);
         Exchange exchange = control.createMock(Exchange.class);
-        InterceptorChain chain = control.createMock(InterceptorChain.class);
-        InputStream is = this.getClass().getResourceAsStream(
-                "resources/greetMeRpcLitReq.xml");
-        SOAPMessage soapMessage = null;
-        try {
-            MessageFactory factory = MessageFactory.newInstance();
-            MimeHeaders mhs = null;
-            soapMessage = factory.createMessage(mhs, is);
-        } catch (Exception e) {
-            throw e;
-        }
-
-        expect(message.getExchange()).andReturn(exchange).anyTimes();
-        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker);
+        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
         // This is to set direction to inbound
         expect(exchange.getOutMessage()).andReturn(null);
-        expect(message.getContent(SOAPMessage.class)).andReturn(soapMessage);
+
+        SoapMessage message = new SoapMessage(new MessageImpl());
+        message.setExchange(exchange);
+
+        XMLStreamReader reader = preparemXMLStreamReader("resources/greetMeRpcLitReq.xml");
+        message.setContent(XMLStreamReader.class, reader);
         control.replay();
 
         SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
         li.handleMessage(message);
         control.verify();
+
+        // Verify SOAPMessage
+        SOAPMessage soapMessageNew = message.getContent(SOAPMessage.class);
+        SOAPBody bodyNew = soapMessageNew.getSOAPBody();
+        Iterator itNew = bodyNew.getChildElements();
+        SOAPBodyElement bodyElementNew = (SOAPBodyElement)itNew.next();
+        assertEquals("sendReceiveData", bodyElementNew.getLocalName());
+
+        // Verify the XMLStreamReader
+        XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
+        QName qn = xmlReader.getName();
+        assertEquals("sendReceiveData", qn.getLocalPart());
     }
 
-    public void testgetUnderstoodHeadersReturnsNull() {
+    public void xtestgetUnderstoodHeadersReturnsNull() {
         List<Handler> list = new ArrayList<Handler>();
         list.add(new SOAPHandler<SOAPMessageContext>() {
             public boolean handleMessage(SOAPMessageContext smc) {
@@ -283,6 +340,38 @@
         return true;
     }
 
+    private XMLStreamReader preparemXMLStreamReader(String resouceName) throws Exception
{
+        InputStream is = this.getClass().getResourceAsStream(resouceName);
+        XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(is);
+
+        // skip until soap body
+        if (xmlReader.nextTag() == XMLStreamConstants.START_ELEMENT) {
+            String ns = xmlReader.getNamespaceURI();
+            SoapVersion soapVersion = SoapVersionFactory.getInstance().getSoapVersion(ns);
+            // message.setVersion(soapVersion);
+
+            QName qn = xmlReader.getName();
+            while (!qn.equals(soapVersion.getBody()) && !qn.equals(soapVersion.getHeader()))
{
+                while (xmlReader.nextTag() != XMLStreamConstants.START_ELEMENT) {
+                    // nothing to do
+                }
+                qn = xmlReader.getName();
+            }
+            if (qn.equals(soapVersion.getHeader())) {
+                XMLStreamReader filteredReader = new PartialXMLStreamReader(xmlReader, soapVersion.getBody());
+
+                Document doc = StaxUtils.read(filteredReader);
+            }
+            // advance just past body.
+            xmlReader.next();
+
+            while (xmlReader.isWhiteSpace()) {
+                xmlReader.next();
+            }
+        }
+        return xmlReader;
+    }
+
     private SOAPMessage preparemSOAPMessage(String resouceName) throws Exception {
         InputStream is = this.getClass().getResourceAsStream(resouceName);
         SOAPMessage soapMessage = null;
@@ -299,8 +388,7 @@
         return os;
     }
 
-    private CachedStream prepareOutputStreamFromSOAPMessage(
-            SOAPMessage soapMessage) throws Exception {
+    private CachedStream prepareOutputStreamFromSOAPMessage(SOAPMessage soapMessage) throws
Exception {
         CachedStream os = new CachedStream();
         soapMessage.writeTo(os);
         return os;

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitReq.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitReq.xml?view=diff&rev=470693&r1=470692&r2=470693
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitReq.xml
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitReq.xml
Thu Nov  2 23:01:42 2006
@@ -1,31 +1,13 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  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.
--->
 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 		   xmlns:xs="http://www.w3.org/2001/XMLSchema" 
 		   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <SOAP-ENV:Body>
 	<ns1:sendReceiveData xmlns:ns1="http://apache.org/hello_world_rpclit">
-	    <in xmlns:ns5="http://apache.org/hello_world_rpclit/types">
+	    <ns5:in xmlns:ns5="http://apache.org/hello_world_rpclit/types">
 		<ns5:elem1>this is element 1</ns5:elem1>
 		<ns5:elem2>this is element 2</ns5:elem2>
-	    <ns5:elem3>42</ns5:elem3></in>
+	        <ns5:elem3>42</ns5:elem3>
+	    </ns5:in>
 	</ns1:sendReceiveData>
     </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitResp.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitResp.xml?view=diff&rev=470693&r1=470692&r2=470693
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitResp.xml
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitResp.xml
Thu Nov  2 23:01:42 2006
@@ -22,11 +22,11 @@
 		   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <SOAP-ENV:Body>
 	<ns1:sendReceiveDataResponse xmlns:ns1="http://apache.org/hello_world_rpclit">
-	    <out xmlns:ns5="http://apache.org/hello_world_rpclit/types">
+	    <ns5:out xmlns:ns5="http://apache.org/hello_world_rpclit/types">
 		<ns5:elem1>return is element 1</ns5:elem1>
 		<ns5:elem2>return is element 2</ns5:elem2>
 		<ns5:elem3>42</ns5:elem3>
-	    </out>
+	    </ns5:out>
 	</ns1:sendReceiveDataResponse>
     </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespChanged.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespChanged.xml?view=diff&rev=470693&r1=470692&r2=470693
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespChanged.xml
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespChanged.xml
Thu Nov  2 23:01:42 2006
@@ -22,11 +22,11 @@
 		   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <SOAP-ENV:Body>
 	<ns1:sendReceiveDataResponse xmlns:ns1="http://apache.org/hello_world_rpclit">
-	    <out xmlns:ns5="http://apache.org/hello_world_rpclit/types">
+	    <ns5:out xmlns:ns5="http://apache.org/hello_world_rpclit/types">
 		<ns5:elem1>return is element 2</ns5:elem1>
 		<ns5:elem2>return is element 1</ns5:elem2>
 		<ns5:elem3>100</ns5:elem3>
-	    </out>
+	    </ns5:out>
 	</ns1:sendReceiveDataResponse>
     </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>



Mime
View raw message