cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r833075 - in /cxf/trunk/rt/bindings/soap/src: main/java/org/apache/cxf/binding/soap/interceptor/ test/java/org/apache/cxf/binding/soap/ test/resources/org/apache/cxf/binding/soap/
Date Thu, 05 Nov 2009 16:31:11 GMT
Author: dkulp
Date: Thu Nov  5 16:30:39 2009
New Revision: 833075

URL: http://svn.apache.org/viewvc?rev=833075&view=rev
Log:
[CXF-1536] If schemavalidation is enabled, also check to make sure the
soap body/envelope are properly closed so the structure of the soap
message is correct as well.

Added:
    cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-no-endenv.xml
  (with props)
Modified:
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
    cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ReadHeaderInterceptorTest.java
    cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/TestBase.java

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java?rev=833075&r1=833074&r2=833075&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
Thu Nov  5 16:30:39 2009
@@ -50,12 +50,41 @@
 import org.apache.cxf.headers.HeaderManager;
 import org.apache.cxf.headers.HeaderProcessor;
 import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.staxutils.PartialXMLStreamReader;
 import org.apache.cxf.staxutils.StaxUtils;
 
 
 public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
+    /**
+     * 
+     */
+    public static class CheckClosingTagsInterceptor extends AbstractSoapInterceptor {
+        public CheckClosingTagsInterceptor() {
+            super(Phase.POST_LOGICAL);
+        }
+        
+        /** {@inheritDoc}*/
+        public void handleMessage(SoapMessage message) throws Fault {
+            XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
+            if (xmlReader != null) {
+                try {
+                    while (xmlReader.hasNext()) {
+                        if (xmlReader.next() == XMLStreamReader.END_DOCUMENT) {
+                            return;
+                        }
+                    }
+                } catch (XMLStreamException e) {
+                    throw new SoapFault(e.getMessage(), e, 
+                                        message.getVersion().getSender());
+                }
+            }
+        }
+
+    }
+
     private static final Logger LOG = LogUtils.getL7dLogger(ReadHeadersInterceptor.class);
 
     private Bus bus;
@@ -183,6 +212,11 @@
                         hel = DOMUtils.getNextElement(hel);
                     }
                 }
+                if (MessageUtils.getContextualBoolean(message, 
+                                                      SoapMessage.SCHEMA_VALIDATION_ENABLED,
+                                                      false)) {
+                    message.getInterceptorChain().add(new CheckClosingTagsInterceptor());
+                }
             }
         } catch (XMLStreamException e) {
             throw new SoapFault(new Message("XML_STREAM_EXC", LOG), e, message.getVersion().getSender());

Modified: cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ReadHeaderInterceptorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ReadHeaderInterceptorTest.java?rev=833075&r1=833074&r2=833075&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ReadHeaderInterceptorTest.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ReadHeaderInterceptorTest.java
Thu Nov  5 16:30:39 2009
@@ -41,6 +41,9 @@
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.interceptor.StaxInInterceptor;
 import org.apache.cxf.message.Attachment;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.staxutils.StaxUtils;
+
 import org.junit.Before;
 import org.junit.Test;
 
@@ -79,6 +82,17 @@
     }
 
     @Test
+    public void testNoClosingEnvTage() throws Exception {
+        soapMessage = TestUtil.createEmptySoapMessage(Soap12.getInstance(), chain);
+        InputStream in = getClass().getResourceAsStream("test-no-endenv.xml");
+        assertNotNull(in);
+        soapMessage.put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
+        soapMessage.setContent(XMLStreamReader.class, StaxUtils.createXMLStreamReader(in));
+
+        soapMessage.getInterceptorChain().doIntercept(soapMessage);
+        assertNotNull(soapMessage.getContent(Exception.class));
+    }
+    @Test
     public void testHandleHeader() {
         try {
             prepareSoapMessage("test-soap-header.xml");

Modified: cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/TestBase.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/TestBase.java?rev=833075&r1=833074&r2=833075&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/TestBase.java (original)
+++ cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/TestBase.java Thu
Nov  5 16:30:39 2009
@@ -69,7 +69,8 @@
         phases.add(phase2);
         phases.add(phase3);
         phases.add(phase4);
-        phases.add(new Phase(Phase.INVOKE, 5));
+        phases.add(new Phase(Phase.POST_LOGICAL, 5));
+        phases.add(new Phase(Phase.INVOKE, 6));
         chain = new PhaseInterceptorChain(phases);
 
         soapMessage = TestUtil.createEmptySoapMessage(Soap11.getInstance(), chain);

Added: cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-no-endenv.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-no-endenv.xml?rev=833075&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-no-endenv.xml
(added)
+++ cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-no-endenv.xml
Thu Nov  5 16:30:39 2009
@@ -0,0 +1,42 @@
+<!--
+    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.
+-->
+<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
+    <env:Body>
+        <!-- boyd test for processing comment here -->
+        <p:itinerary xmlns:p="http://travelcompany.example.org/reservation/travel">
+            <p:departure>
+                <p:departing>New York</p:departing>
+                <p:arriving>Los Angeles</p:arriving>
+                <p:departureDate>2001-12-14</p:departureDate>
+                <p:departureTime>late afternoon</p:departureTime>
+                <p:seatPreference>aisle</p:seatPreference>
+            </p:departure>
+            <p:return>
+                <p:departing>Los Angeles</p:departing>
+                <p:arriving>New York</p:arriving>
+                <p:departureDate>2001-12-20</p:departureDate>
+                <p:departureTime>mid-morning</p:departureTime>
+                <p:seatPreference />
+            </p:return>
+        </p:itinerary>
+        <q:lodging xmlns:q="http://travelcompany.example.org/reservation/hotels">
+            <q:preference>none</q:preference>
+        </q:lodging>
+    </env:Body>
+

Propchange: cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-no-endenv.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-no-endenv.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-no-endenv.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message