Author: ffang Date: Thu Aug 15 06:35:58 2013 New Revision: 1514176 URL: http://svn.apache.org/r1514176 Log: Merged revisions 1514167 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes
................ r1514167 | ffang | 2013-08-15 13:59:30 +0800 (四, 15 8 2013) | 9 lines 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.6.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralReqWithExceedMaxLength.xml - copied unchanged from r1514167, cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralReqWithExceedMaxLength.xml Modified: cxf/branches/2.6.x-fixes/ (props changed) cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java cxf/branches/2.6.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java Propchange: cxf/branches/2.6.x-fixes/ ------------------------------------------------------------------------------ Merged /cxf/branches/2.7.x-fixes:r1514167 Merged /cxf/trunk:r1514144 Propchange: cxf/branches/2.6.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java?rev=1514176&r1=1514175&r2=1514176&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java (original) +++ cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java Thu Aug 15 06:35:58 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.6.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java?rev=1514176&r1=1514175&r2=1514176&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java (original) +++ cxf/branches/2.6.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java Thu Aug 15 06:35:58 2013 @@ -54,13 +54,13 @@ 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; import org.apache.cxf.helpers.XMLUtils; import org.apache.cxf.jaxws.DispatchImpl; import org.apache.cxf.message.Message; +import org.apache.cxf.staxutils.StaxUtils; import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; import org.apache.cxf.testutil.common.AbstractBusTestServerBase; import org.apache.cxf.testutil.common.TestUtil; @@ -72,6 +72,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; @@ -682,6 +683,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 { @@ -885,6 +925,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)); }
