You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2013/08/15 05:13:57 UTC

svn commit: r1514144 - in /cxf/trunk: core/src/main/java/org/apache/cxf/databinding/source/ systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/ systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/

Author: ffang
Date: Thu Aug 15 03:13:57 2013
New Revision: 1514144

URL: http://svn.apache.org/r1514144
Log:
[CXF-5169]ensure stream is re-readable if need schema validation|add one more test

Added:
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralReqWithExceedMaxLength.xml
Modified:
    cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java?rev=1514144&r1=1514143&r2=1514144&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java Thu Aug 15 03:13:57 2013
@@ -28,7 +28,6 @@ import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 
 import org.w3c.dom.Document;
@@ -61,12 +60,15 @@ public class XMLStreamDataWriter impleme
             if (obj instanceof DataSource) {
                 DataSource ds = (DataSource)obj;
                 if (schema != null) {
-                    StreamSource ss = new StreamSource(ds.getInputStream());
-                    schema.newValidator().validate(ss);
+                    DOMSource domSource = new DOMSource(StaxUtils.read(ds.getInputStream()));
+                    schema.newValidator().validate(domSource);
+                    StaxUtils.copy(domSource, writer);
+                } else {
+                    reader = StaxUtils.createXMLStreamReader(ds.getInputStream());
+                    StaxUtils.copy(reader, writer);
+                    reader.close();
                 }
-                reader = StaxUtils.createXMLStreamReader(ds.getInputStream());
-                StaxUtils.copy(reader, writer);
-                reader.close();
+                
             } else if (obj instanceof Node) {
                 if (schema != null) {
                     schema.newValidator().validate(new DOMSource((Node)obj));
@@ -76,6 +78,10 @@ public class XMLStreamDataWriter impleme
             } else {
                 Source s = (Source) obj;
                 if (schema != null) {
+                    if (!(s instanceof DOMSource)) {
+                        //make the source re-readable.
+                        s = new DOMSource(StaxUtils.read(s));
+                    }
                     schema.newValidator().validate(s);
                 }
                 if (s instanceof DOMSource

Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java?rev=1514144&r1=1514143&r2=1514144&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java (original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java Thu Aug 15 03:13:57 2013
@@ -57,7 +57,6 @@ import org.w3c.dom.Node;
 
 import org.xml.sax.InputSource;
 
-
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.binding.soap.saaj.SAAJUtils;
 import org.apache.cxf.helpers.DOMUtils;
@@ -75,6 +74,7 @@ import org.apache.hello_world_soap_http.
 import org.apache.hello_world_soap_http.types.GreetMe;
 import org.apache.hello_world_soap_http.types.GreetMeLater;
 import org.apache.hello_world_soap_http.types.GreetMeResponse;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -686,6 +686,45 @@ public class DispatchClientServerTest ex
         assertNotNull(saxSourceResp3);
         assertTrue("Expected: " + expected, StaxUtils.toString(saxSourceResp3).contains(expected3));
     }
+    
+    @Test
+    public void testSAXSourceMESSAGEWithSchemaValidation() throws Exception {
+
+        URL wsdl = getClass().getResource("/org/apache/cxf/systest/provider/hello_world_with_restriction.wsdl");
+        assertNotNull(wsdl);
+
+        SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
+        assertNotNull(service);
+        
+        InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
+        InputSource inputSource = new InputSource(is);
+        SAXSource saxSourceReq = new SAXSource(inputSource);
+        assertNotNull(saxSourceReq);
+
+        Dispatch<SAXSource> disp = service.createDispatch(PORT_NAME, SAXSource.class, Service.Mode.MESSAGE);
+        disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+                                     "http://localhost:" 
+                                     + greeterPort
+                                     + "/SOAPDispatchService/SoapDispatchPort");
+        disp.getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
+        SAXSource saxSourceResp = disp.invoke(saxSourceReq);
+        assertNotNull(saxSourceResp);
+        String expected = "Hello TestSOAPInputMessage";
+        assertTrue("Expected: " + expected, StaxUtils.toString(saxSourceResp).contains(expected));
+        
+        is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReqWithExceedMaxLength.xml");
+        inputSource = new InputSource(is);
+        saxSourceReq = new SAXSource(inputSource);
+        assertNotNull(saxSourceReq);
+        
+        try {
+            disp.invoke(saxSourceReq);
+            fail("Should have thrown an exception");
+        } catch (Exception ex) {
+            // expected
+            assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
+        }
+    }
 
     @Test
     public void testSAXSourcePAYLOAD() throws Exception {
@@ -889,6 +928,14 @@ public class DispatchClientServerTest ex
             // expected
             assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
         }
+        
+        is = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq.xml");
+        streamSourceReq = new StreamSource(is);
+        assertNotNull(streamSourceReq);
+        StreamSource streamSourceResp = disp.invoke(streamSourceReq);
+        assertNotNull(streamSourceResp);
+        String expected = "Hello TestSOAPInputMessage";
+        assertTrue("Expected: " + expected, StaxUtils.toString(streamSourceResp).contains(expected));
     }
     
     @Test

Added: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralReqWithExceedMaxLength.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralReqWithExceedMaxLength.xml?rev=1514144&view=auto
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralReqWithExceedMaxLength.xml (added)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralReqWithExceedMaxLength.xml Thu Aug 15 03:13:57 2013
@@ -0,0 +1,21 @@
+<?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><ns4:greetMe xmlns:ns4="http://apache.org/hello_world_soap_http/types"><ns4:requestType>TestSOAPInputMessage which length exceed the maxLength restriction so that should run into a schema validation exception</ns4:requestType></ns4:greetMe></SOAP-ENV:Body></SOAP-ENV:Envelope>