cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r471449 - in /incubator/cxf/trunk/rt/frontend/jaxws/src: main/java/org/apache/cxf/jaxws/handler/soap/ test/java/org/apache/cxf/jaxws/handler/soap/ test/java/org/apache/cxf/jaxws/handler/soap/resources/
Date Sun, 05 Nov 2006 15:51:23 GMT
Author: jliu
Date: Sun Nov  5 07:51:22 2006
New Revision: 471449

URL: http://svn.apache.org/viewvc?view=rev&rev=471449
Log:
* Read and modify SOAPHeader both inbound and outbound.

Added:
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespWithHeader.xml
  (with props)
Modified:
    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/handler/soap/SOAPHandlerInterceptorTest.java

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=471449&r1=471448&r2=471449
==============================================================================
--- 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
Sun Nov  5 07:51:22 2006
@@ -39,6 +39,8 @@
 import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.handler.soap.SOAPHandler;
 
+import org.w3c.dom.Element;
+
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.interceptor.SoapInterceptor;
@@ -156,6 +158,13 @@
                 }
                 reader.next();
                 message.setContent(XMLStreamReader.class, reader);
+                
+                //replace header element if necessary
+                if (message.hasHeaders(Element.class)) {
+                    Element headerElements = message.getHeaders(Element.class);
+                    headerElements = soapMessage.getSOAPHeader();    
+                    message.setHeaders(Element.class, headerElements);
+                }
             } catch (IOException ioe) {
                 throw new SoapFault(new org.apache.cxf.common.i18n.Message(
                         "SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), ioe,

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=471449&r1=471448&r2=471449
==============================================================================
--- 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
Sun Nov  5 07:51:22 2006
@@ -22,7 +22,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-// import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -108,14 +107,10 @@
         IMocksControl control = createNiceControl();
         Binding binding = control.createMock(Binding.class);
         Exchange exchange = control.createMock(Exchange.class);
-        SoapMessage message = new SoapMessage(new MessageImpl());
-        message.setExchange(exchange);
-
-        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
+        SoapMessage message = new SoapMessage(new MessageImpl());
+        message.setExchange(exchange);        
+        // This is to set direction to outbound
         expect(exchange.getOutMessage()).andReturn(message).anyTimes();
         CachedStream originalEmptyOs = new CachedStream();
         message.setContent(OutputStream.class, originalEmptyOs);
@@ -153,7 +148,7 @@
     // SAAJ tree is created on if SOAPMessageContext.getMessage() is
     // called. Any changes to SOAPMessage should be streamed back to
     // outputStream
-    public void xtestSOAPBodyChangedOutBound() throws Exception {
+    public void testChangeSOAPBodyOutBound() throws Exception {
         List<Handler> list = new ArrayList<Handler>();
         list.add(new SOAPHandler<SOAPMessageContext>() {
             public boolean handleMessage(SOAPMessageContext smc) {
@@ -185,14 +180,10 @@
         IMocksControl control = createNiceControl();
         Binding binding = control.createMock(Binding.class);
         Exchange exchange = control.createMock(Exchange.class);
+        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
         SoapMessage message = new SoapMessage(new MessageImpl());
         message.setExchange(exchange);
-
-        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
+        // This is to set direction to outbound
         expect(exchange.getOutMessage()).andReturn(message).anyTimes();
         CachedStream originalEmptyOs = new CachedStream();
         message.setContent(OutputStream.class, originalEmptyOs);
@@ -238,23 +229,26 @@
         NodeList elem3NodeList = outElement
             .getElementsByTagNameNS("http://apache.org/hello_world_rpclit/types", "elem3");
         Node elem3Element = elem3NodeList.item(0);
-        assertNotNull("100", elem3Element.getTextContent());
+        assertEquals("100", elem3Element.getTextContent());
     }
 
-    public void xtestGetSOAPHeaderInBound() throws Exception {
+    public void testChangeSOAPHeaderInBound() throws Exception {
         List<Handler> list = new ArrayList<Handler>();
         list.add(new SOAPHandler<SOAPMessageContext>() {
             public boolean handleMessage(SOAPMessageContext smc) {
                 try {
-                    // change mustUnderstand to false
-                    SOAPMessage message = smc.getMessage();
-                    SOAPHeader soapHeader = message.getSOAPHeader();
-                    Iterator it = soapHeader.getChildElements();
-                    SOAPHeaderElement headerElementNew = (SOAPHeaderElement)it.next();
-
-                    SoapVersion soapVersion = Soap11.getInstance();
-                    headerElementNew.setAttributeNS(soapVersion.getNamespace(), "SOAP-ENV:mustUnderstand",
-                                                    "false");
+                    Boolean outboundProperty = (Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+                    if (!outboundProperty.booleanValue()) {
+                        // change mustUnderstand to false
+                        SOAPMessage message = smc.getMessage();
+                        SOAPHeader soapHeader = message.getSOAPHeader();
+                        Iterator it = soapHeader.getChildElements();
+                        SOAPHeaderElement headerElementNew = (SOAPHeaderElement)it.next();
+
+                        SoapVersion soapVersion = Soap11.getInstance();
+                        headerElementNew.setAttributeNS(soapVersion.getNamespace(),
+                                                        "SOAP-ENV:mustUnderstand", "false");
+                    }
                 } catch (Exception e) {
                     throw new Fault(e);
                 }
@@ -280,17 +274,14 @@
         expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
         // This is to set direction to inbound
         expect(exchange.getOutMessage()).andReturn(null);
-
         SoapMessage message = new SoapMessage(new MessageImpl());
         message.setExchange(exchange);
-
         XMLStreamReader reader = preparemXMLStreamReader("resources/greetMeRpcLitReq.xml");
         message.setContent(XMLStreamReader.class, reader);
         Element headerElement = preparemSOAPHeader();
         message.setHeaders(Element.class, headerElement);
         message.put(Element.class, headerElement);
 
-        // message.setContent(Element.class, preparemSOAPHeader());
         control.replay();
 
         SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
@@ -299,20 +290,108 @@
 
         // Verify SOAPMessage header
         SOAPMessage soapMessageNew = message.getContent(SOAPMessage.class);
-
         SOAPHeader soapHeader = soapMessageNew.getSOAPHeader();
         Iterator itNew = soapHeader.getChildElements();
         SOAPHeaderElement headerElementNew = (SOAPHeaderElement)itNew.next();
         SoapVersion soapVersion = Soap11.getInstance();
         assertEquals("false", headerElementNew.getAttributeNS(soapVersion.getNamespace(),
"mustUnderstand"));
 
-        // Verify the XMLStreamReader
+        // Verify XMLStreamReader
         XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
         QName qn = xmlReader.getName();
         assertEquals("sendReceiveData", qn.getLocalPart());
+        
+        // Verify Header Element
+        Element element = message.getHeaders(Element.class);      
+        NodeList headerNodeList = element.getElementsByTagNameNS(
+            "http://apache.org/hello_world_rpclit/types", "header1");
+        Element headerElementNew1 = (Element)headerNodeList.item(0);
+        assertEquals("false", headerElementNew1.getAttributeNS(soapVersion.getNamespace(),
"mustUnderstand"));
+    }
+
+    public void testChangeSOAPHeaderOutBound() throws Exception {
+        List<Handler> list = new ArrayList<Handler>();
+        list.add(new SOAPHandler<SOAPMessageContext>() {
+            public boolean handleMessage(SOAPMessageContext smc) {
+                try {
+                    Boolean outboundProperty = (Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+                    if (outboundProperty.booleanValue()) {
+                        // change mustUnderstand to false
+                        SOAPMessage message = smc.getMessage();
+                         
+                        SOAPHeader soapHeader = message.getSOAPHeader();
+                        Iterator it = soapHeader.getChildElements(new QName(
+                            "http://apache.org/hello_world_rpclit/types", "header1"));
+                        SOAPHeaderElement headerElementNew = (SOAPHeaderElement)it.next();
+
+                        SoapVersion soapVersion = Soap11.getInstance();
+                        headerElementNew.setAttributeNS(soapVersion.getNamespace(),
+                                                        "SOAP-ENV:mustUnderstand", "false");
+                    }
+                } catch (Exception e) {
+                    throw new Fault(e);
+                }
+                return true;
+            }
+
+            public boolean handleFault(SOAPMessageContext smc) {
+                return true;
+            }
+
+            public Set<QName> getHeaders() {
+                return null;
+            }
+
+            public void close(MessageContext messageContext) {
+            }
+        });
+        HandlerChainInvoker invoker = new HandlerChainInvoker(list);
+
+        IMocksControl control = createNiceControl();
+        Binding binding = control.createMock(Binding.class);
+        Exchange exchange = control.createMock(Exchange.class);
+        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
+        SoapMessage message = new SoapMessage(new MessageImpl());
+        message.setExchange(exchange);
+        // This is to set direction to outbound
+        expect(exchange.getOutMessage()).andReturn(message).anyTimes();
+        CachedStream originalEmptyOs = new CachedStream();
+        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/greetMeRpcLitRespWithHeader.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();
+
+        // Verify SOAPMessage header
+        SOAPMessage soapMessageNew = message.getContent(SOAPMessage.class);
+
+        SOAPHeader soapHeader = soapMessageNew.getSOAPHeader();
+        Iterator itNew = soapHeader.getChildElements(new QName("http://apache.org/hello_world_rpclit/types",
+            "header1"));
+        SOAPHeaderElement headerElementNew = (SOAPHeaderElement)itNew.next();
+        SoapVersion soapVersion = Soap11.getInstance();
+        assertEquals("false", headerElementNew.getAttributeNS(soapVersion.getNamespace(),
"mustUnderstand"));
     }
 
-    public void xtestGetSOAPMessageInBound() throws Exception {
+    public void testGetSOAPMessageInBound() throws Exception {
         List<Handler> list = new ArrayList<Handler>();
         list.add(new SOAPHandler<SOAPMessageContext>() {
             public boolean handleMessage(SOAPMessageContext smc) {
@@ -368,7 +447,7 @@
         assertEquals("sendReceiveData", qn.getLocalPart());
     }
 
-    public void xtestgetUnderstoodHeadersReturnsNull() {
+    public void testgetUnderstoodHeadersReturnsNull() {
         List<Handler> list = new ArrayList<Handler>();
         list.add(new SOAPHandler<SOAPMessageContext>() {
             public boolean handleMessage(SOAPMessageContext smc) {

Added: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespWithHeader.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespWithHeader.xml?view=auto&rev=471449
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespWithHeader.xml
(added)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespWithHeader.xml
Sun Nov  5 07:51:22 2006
@@ -0,0 +1,37 @@
+<?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:Header>
+	<ns2:header1 xmlns:ns2="http://apache.org/hello_world_rpclit/types" SOAP-ENV:mustUnderstand="true">
+	</ns2:header1>
+    </SOAP-ENV:Header>
+    <SOAP-ENV:Body>
+	<ns1:sendReceiveDataResponse xmlns:ns1="http://apache.org/hello_world_rpclit">
+	    <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>
+	    </ns5:out>
+	</ns1:sendReceiveDataResponse>
+    </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>
+

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespWithHeader.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespWithHeader.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/resources/greetMeRpcLitRespWithHeader.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message