cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r1514167 - in /cxf/branches/2.7.x-fixes: ./ rt/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/
Date Thu, 15 Aug 2013 05:59:30 GMT
Author: ffang
Date: Thu Aug 15 05:59:30 2013
New Revision: 1514167

URL: http://svn.apache.org/r1514167
Log:
Merged revisions 1514144 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1514144 | ffang | 2013-08-15 11:13:57 +0800 (四, 15  8 2013) | 1 line
  
  [CXF-5169]ensure stream is re-readable if need schema validation|add one more test
........

Added:
    cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralReqWithExceedMaxLength.xml
      - copied unchanged from r1514144, cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralReqWithExceedMaxLength.xml
Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
    cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1514144

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java?rev=1514167&r1=1514166&r2=1514167&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
Thu Aug 15 05:59:30 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/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java?rev=1514167&r1=1514166&r2=1514167&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java
Thu Aug 15 05:59:30 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;
@@ -76,6 +75,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;
 
@@ -687,6 +687,45 @@ public class DispatchClientServerTest ex
         assertNotNull(saxSourceResp3);
         assertTrue("Expected: " + expected, XMLUtils.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 {
@@ -890,6 +929,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



Mime
View raw message