cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r470738 - in /incubator/cxf/trunk/rt/frontend/jaxws/src: main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
Date Fri, 03 Nov 2006 09:45:20 GMT
Author: jliu
Date: Fri Nov  3 01:45:20 2006
New Revision: 470738

URL: http://svn.apache.org/viewvc?view=rev&rev=470738
Log:
CXF-205. Read and modify SOAPHeader in SOAPHandler for inbound.

Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.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/SOAPMessageContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java?view=diff&rev=470738&r1=470737&r2=470738
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java
Fri Nov  3 01:45:20 2006
@@ -93,10 +93,18 @@
                     writer.writeStartElement(soapVersion.getPrefix(), soapVersion.getEnvelope()
                         .getLocalPart(), soapVersion.getNamespace());
                     writer.writeNamespace(soapVersion.getPrefix(), soapVersion.getNamespace());
+                    
+                    //Write headers                    
+                    if (getWrappedSoapMessage().hasHeaders(Element.class)) {
+                        Element headerElements = getWrappedSoapMessage().getHeaders(Element.class);
+                        StaxUtils.writeElement(headerElements, writer, true);
+                    }
+                    
                     writer.writeStartElement(soapVersion.getPrefix(), soapVersion.getBody().getLocalPart(),
                                              soapVersion.getNamespace());
                     writer.writeNamespace(soapVersion.getPrefix(), soapVersion.getNamespace());
-
+                   
+                    //Write soap body
                     StaxUtils.copy(xmlReader, writer);
 
                     xmlReader.close();
@@ -107,16 +115,15 @@
                     MessageFactory factory = MessageFactory.newInstance();
                     MimeHeaders mhs = null;
                     message = factory.createMessage(mhs, newIs);
-
-                    /*
-                     System.out.println("------------------");
-                     PrintStream out = System.out;
-                     message.writeTo(out);
-                     out.println();
-                     System.out.println("------------------");
-                     */
                 }
 
+                
+/*                System.out.println("11111------------------");
+                PrintStream out = System.out;
+                message.writeTo(out);
+                out.println();
+                System.out.println("11111------------------");
+*/
                 getWrappedMessage().setContent(SOAPMessage.class, message);
 
             } catch (IOException 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=470738&r1=470737&r2=470738
==============================================================================
--- 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
Fri Nov  3 01:45:20 2006
@@ -22,6 +22,7 @@
 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;
@@ -29,10 +30,13 @@
 import java.util.Set;
 
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.MimeHeaders;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPBodyElement;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
@@ -50,6 +54,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.cxf.binding.soap.Soap11;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.SoapVersion;
 import org.apache.cxf.binding.soap.SoapVersionFactory;
@@ -80,7 +85,7 @@
 
     // SAAJ tree is created on demand. SAAJ wont be created without
     // the calling of SOAPMessageContext.getMessage().
-    public void testNoCallToGetMessageOutBound() throws Exception {
+    public void xtestNoCallToGetMessageOutBound() throws Exception {
         List<Handler> list = new ArrayList<Handler>();
         list.add(new SOAPHandler<SOAPMessageContext>() {
             public boolean handleMessage(SOAPMessageContext smc) {
@@ -124,7 +129,7 @@
                     CachedStream os = prepareOutputStreamFromResource("resources/greetMeRpcLitResp.xml");
                     message.setContent(OutputStream.class, os);
                 } catch (Exception e) {
-                    //do nothing
+                    // do nothing
                 }
             }
 
@@ -148,7 +153,7 @@
     // SAAJ tree is created on if SOAPMessageContext.getMessage() is
     // called. Any changes to SOAPMessage should be streamed back to
     // outputStream
-    public void testSOAPBodyChangedOutBound() throws Exception {
+    public void xtestSOAPBodyChangedOutBound() throws Exception {
         List<Handler> list = new ArrayList<Handler>();
         list.add(new SOAPHandler<SOAPMessageContext>() {
             public boolean handleMessage(SOAPMessageContext smc) {
@@ -202,7 +207,7 @@
                         "resources/greetMeRpcLitRespChanged.xml");
                     message.setContent(OutputStream.class, os);
                 } catch (Exception e) {
-                    //do nothing
+                    // do nothing
                 }
             }
 
@@ -236,7 +241,78 @@
         assertNotNull("100", elem3Element.getTextContent());
     }
 
-    public void xtestGetSOAPMessageInBound() throws Exception {
+    public void testGetSOAPHeaderInBound() 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");
+                } 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();
+        // 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);
+        li.handleMessage(message);
+        control.verify();
+
+        // 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
+        XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
+        QName qn = xmlReader.getName();
+        assertEquals("sendReceiveData", qn.getLocalPart());
+    }
+
+    public void testGetSOAPMessageInBound() throws Exception {
         List<Handler> list = new ArrayList<Handler>();
         list.add(new SOAPHandler<SOAPMessageContext>() {
             public boolean handleMessage(SOAPMessageContext smc) {
@@ -292,7 +368,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) {
@@ -370,6 +446,19 @@
             }
         }
         return xmlReader;
+    }
+
+    private Element preparemSOAPHeader() throws Exception {
+        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+        SoapVersion soapVersion = Soap11.getInstance();
+        Element headerElement = doc.createElementNS(soapVersion.getNamespace(), "SOAP-ENV:"
+                                                                                + soapVersion.getHeader()
+                                                                                    .getLocalPart());
+        Element childElement = doc.createElementNS("http://apache.org/hello_world_rpclit/types",
+                                                   "ns2:header1");
+        childElement.setAttributeNS(soapVersion.getNamespace(), "SOAP-ENV:mustUnderstand",
"true");
+        headerElement.appendChild(childElement);
+        return headerElement;
     }
 
     private SOAPMessage preparemSOAPMessage(String resouceName) throws Exception {



Mime
View raw message