Author: ffang
Date: Wed Aug 14 05:04:42 2013
New Revision: 1513727
URL: http://svn.apache.org/r1513727
Log:
Merged revisions 1513427,1513711,1513720 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1513427 | ffang | 2013-08-13 18:37:58 +0800 (二, 13 8 2013) | 1 line
[CXF-5169]DISPATCH/PROVIDER doesn't work for OUT message validation
........
r1513711 | ffang | 2013-08-14 09:53:02 +0800 (三, 14 8 2013) | 1 line
[CXF-5169]move the out message schemavalidate to source databinding
........
r1513720 | ffang | 2013-08-14 11:48:50 +0800 (三, 14 8 2013) | 1 line
[CXF-5169]add a DISPATCH side test
........
Added:
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralSOAPBodyReqExceedMaxLength.xml
- copied unchanged from r1513720,
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralSOAPBodyReqExceedMaxLength.xml
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/hello_world_with_restriction.wsdl
- copied unchanged from r1513427,
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/hello_world_with_restriction.wsdl
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/resources/GreetMeDocLiteralRespExceedLength.xml
- copied unchanged from r1513427,
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/resources/GreetMeDocLiteralRespExceedLength.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/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java
cxf/branches/2.7.x-fixes/rt/pom.xml
cxf/branches/2.7.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/source/ClientServerSourceTest.java
cxf/branches/2.7.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/source/GreeterImpl.java
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSoapMessageDocProvider.java
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/resources/XML_GreetMeDocLiteralResp.xml
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
svn:mergeinfo = /cxf/trunk:1513427,1513711-1513720
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=1513727&r1=1513726&r2=1513727&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
Wed Aug 14 05:04:42 2013
@@ -28,12 +28,15 @@ 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;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.databinding.DataWriter;
@@ -46,6 +49,8 @@ import org.apache.cxf.staxutils.W3CDOMSt
public class XMLStreamDataWriter implements DataWriter<XMLStreamWriter> {
private static final Logger LOG =
LogUtils.getL7dLogger(XMLStreamDataWriter.class);
+ private Schema schema;
+
public void write(Object obj, MessagePartInfo part, XMLStreamWriter
output) {
write(obj, output);
}
@@ -55,14 +60,24 @@ public class XMLStreamDataWriter impleme
XMLStreamReader reader = null;
if (obj instanceof DataSource) {
DataSource ds = (DataSource)obj;
+ if (schema != null) {
+ StreamSource ss = new StreamSource(ds.getInputStream());
+ schema.newValidator().validate(ss);
+ }
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));
+ }
Node nd = (Node)obj;
writeNode(nd, writer);
} else {
Source s = (Source) obj;
+ if (schema != null) {
+ schema.newValidator().validate(s);
+ }
if (s instanceof DOMSource
&& ((DOMSource) s).getNode() == null) {
return;
@@ -74,6 +89,9 @@ public class XMLStreamDataWriter impleme
e.getClass().getCanonicalName(), e.getMessage());
} catch (IOException e) {
throw new Fault(new Message("COULD_NOT_WRITE_XML_STREAM", LOG), e);
+ } catch (SAXException e) {
+ throw new Fault("COULD_NOT_WRITE_XML_STREAM_CAUSED_BY", LOG, e,
+ e.getClass().getCanonicalName(), e.getMessage());
}
}
@@ -119,6 +137,7 @@ public class XMLStreamDataWriter impleme
}
public void setSchema(Schema s) {
+ this.schema = s;
}
public void setAttachments(Collection<Attachment> attachments) {
Modified:
cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java?rev=1513727&r1=1513726&r2=1513727&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java
(original)
+++
cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeOutInterceptor.java
Wed Aug 14 05:04:42 2013
@@ -38,6 +38,7 @@ import javax.xml.transform.Source;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
+
import org.apache.cxf.attachment.AttachmentDeserializer;
import org.apache.cxf.binding.soap.Soap12;
import org.apache.cxf.binding.soap.SoapFault;
@@ -159,6 +160,7 @@ public class MessageModeOutInterceptor e
Object o = list.get(0);
if (o instanceof SOAPMessage) {
SOAPMessage soapMessage = (SOAPMessage)o;
+
if (soapMessage.countAttachments() > 0) {
message.put("write.attachments", Boolean.TRUE);
}
@@ -291,5 +293,7 @@ public class MessageModeOutInterceptor e
message.getInterceptorChain().add(SAAJOutEndingInterceptor.INSTANCE);
}
}
+
+
}
Modified: cxf/branches/2.7.x-fixes/rt/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/pom.xml?rev=1513727&r1=1513726&r2=1513727&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/pom.xml (original)
+++ cxf/branches/2.7.x-fixes/rt/pom.xml Wed Aug 14 05:04:42 2013
@@ -50,7 +50,6 @@
<module>transports/http-jetty</module>
<module>transports/http-hc</module>
<module>transports/jms</module>
- <module>transports/udp</module>
<module>ws/policy</module>
<module>ws/addr</module>
<module>ws/rm</module>
Modified:
cxf/branches/2.7.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/source/ClientServerSourceTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/source/ClientServerSourceTest.java?rev=1513727&r1=1513726&r2=1513727&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/source/ClientServerSourceTest.java
(original)
+++
cxf/branches/2.7.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/source/ClientServerSourceTest.java
Wed Aug 14 05:04:42 2013
@@ -88,7 +88,7 @@ public class ClientServerSourceTest exte
DOMSource ds = new DOMSource(doc);
DOMSource resp = port.sayHi(ds);
assertEquals("We should get the right response", "Bonjour",
- DOMUtils.getContent(getElement(resp.getNode())));
+
DOMUtils.getContent(getElement(resp.getNode().getFirstChild().getFirstChild())));
doc = XMLUtils.newDocument();
Element el =
doc.createElementNS("http://apache.org/hello_world_soap_http_source/source/types",
Modified:
cxf/branches/2.7.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/source/GreeterImpl.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/source/GreeterImpl.java?rev=1513727&r1=1513726&r2=1513727&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/source/GreeterImpl.java
(original)
+++
cxf/branches/2.7.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/source/GreeterImpl.java
Wed Aug 14 05:04:42 2013
@@ -47,9 +47,11 @@ public class GreeterImpl implements Gree
Document doc = XMLUtils.newDocument();
Element el =
doc.createElementNS("http://apache.org/hello_world_soap_http_source/source/types",
"ns1:sayHiResponse");
- el.appendChild(doc.createTextNode("Bonjour"));
+ Element el2 =
doc.createElementNS("http://apache.org/hello_world_soap_http_source/source/types",
+ "ns1:responseType");
+ el2.appendChild(doc.createTextNode("Bonjour"));
+ el.appendChild(el2);
doc.appendChild(el);
-
return new DOMSource(doc);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
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=1513727&r1=1513726&r2=1513727&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
Wed Aug 14 05:04:42 2013
@@ -63,6 +63,7 @@ import org.apache.cxf.binding.soap.saaj.
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;
@@ -863,6 +864,34 @@ public class DispatchClientServerTest ex
assertTrue("Expected: " + expected,
XMLUtils.toString(streamSourceResp3).contains(expected3));
}
+
+ @Test
+ public void testStreamSourcePAYLOADWithSchemaValidation() 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);
+ Dispatch<StreamSource> disp = service.createDispatch(PORT_NAME,
StreamSource.class,
+
Service.Mode.PAYLOAD);
+ disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+ "http://localhost:"
+ + greeterPort
+ +
"/SOAPDispatchService/SoapDispatchPort");
+ disp.getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED,
Boolean.TRUE);
+ InputStream is =
getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReqExceedMaxLength.xml");
+ StreamSource streamSourceReq = new StreamSource(is);
+ assertNotNull(streamSourceReq);
+ try {
+ disp.invoke(streamSourceReq);
+ fail("Should have thrown an exception");
+ } catch (Exception ex) {
+ // expected
+ assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
+ }
+ }
+
@Test
public void testStAXSourcePAYLOAD() throws Exception {
Modified:
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSoapMessageDocProvider.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSoapMessageDocProvider.java?rev=1513727&r1=1513726&r2=1513727&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSoapMessageDocProvider.java
(original)
+++
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSoapMessageDocProvider.java
Wed Aug 14 05:04:42 2013
@@ -50,7 +50,7 @@ import org.apache.cxf.helpers.DOMUtils;
//wsdlLocation = "/trunk/testutils/src/main/resources/wsdl/hello_world.wsdl"
@WebServiceProvider(portName = "SoapProviderPort", serviceName =
"SOAPProviderService",
targetNamespace =
"http://apache.org/hello_world_soap_http",
- wsdlLocation = "/wsdl/hello_world.wsdl")
+ wsdlLocation =
"/org/apache/cxf/systest/provider/hello_world_with_restriction.wsdl")
@ServiceMode(value = Service.Mode.MESSAGE)
public class HWSoapMessageDocProvider implements Provider<SOAPMessage> {
@@ -62,6 +62,7 @@ public class HWSoapMessageDocProvider im
private SOAPMessage sayHiResponse;
private SOAPMessage greetMeResponse;
+ private SOAPMessage greetMeResponseExceedMaxLengthRestriction;
public HWSoapMessageDocProvider() {
@@ -73,6 +74,9 @@ public class HWSoapMessageDocProvider im
is =
getClass().getResourceAsStream("resources/GreetMeDocLiteralResp.xml");
greetMeResponse = factory.createMessage(null, is);
is.close();
+ is =
getClass().getResourceAsStream("resources/GreetMeDocLiteralRespExceedLength.xml");
+ greetMeResponseExceedMaxLengthRestriction =
factory.createMessage(null, is);
+ is.close();
} catch (Exception ex) {
ex.printStackTrace();
}
@@ -103,6 +107,8 @@ public class HWSoapMessageDocProvider im
String v = DOMUtils.getContent(el);
if (v.contains("Return sayHi")) {
response = sayHiResponse;
+ } else if (v.contains("exceed maxLength")) {
+ response = greetMeResponseExceedMaxLengthRestriction;
} else if (v.contains("throwFault")) {
try {
SOAPFactory f = SOAPFactory.newInstance();
Modified:
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java?rev=1513727&r1=1513726&r2=1513727&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java
(original)
+++
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java
Wed Aug 14 05:04:42 2013
@@ -21,11 +21,17 @@ package org.apache.cxf.systest.provider;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.ws.Endpoint;
import javax.xml.ws.soap.SOAPFaultException;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.apache.cxf.message.Message;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
import org.apache.cxf.testutil.common.TestUtil;
@@ -43,7 +49,14 @@ public class ProviderClientServerTest ex
protected void run() {
Object implementor = new HWSoapMessageDocProvider();
- Endpoint.publish(ADDRESS, implementor);
+ Endpoint ep = Endpoint.create(implementor);
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
+ ep.setProperties(map);
+ ((EndpointImpl)ep).getInInterceptors().add(new
LoggingInInterceptor());
+ ((EndpointImpl)ep).getOutInterceptors().add(new
LoggingOutInterceptor());
+ ep.publish(ADDRESS);
+
}
public static void main(String[] args) {
@@ -112,4 +125,46 @@ public class ProviderClientServerTest ex
}
+
+ @Test
+ public void testSOAPMessageModeDocLitWithSchemaValidation() throws
Exception {
+
+ QName serviceName =
+ new QName("http://apache.org/hello_world_soap_http",
"SOAPProviderService");
+ QName portName =
+ new QName("http://apache.org/hello_world_soap_http",
"SoapProviderPort");
+
+ URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
+ assertNotNull(wsdl);
+
+ SOAPService service = new SOAPService(wsdl, serviceName);
+ assertNotNull(service);
+
+
+ try {
+ Greeter greeter = service.getPort(portName, Greeter.class);
+ setAddress(greeter, ADDRESS);
+ try {
+ greeter.greetMe("this is a greetMe message which length is
more "
+ + "than 30 so that I wanna a schema validation error");
+ fail("Should have thrown an exception");
+ } catch (Exception ex) {
+ //expected
+ assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
+ }
+
+ try {
+ greeter.greetMe("exceed maxLength");
+ fail("Should have thrown an exception");
+ } catch (Exception ex) {
+ //expected
+ assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
+ }
+
+ } catch (UndeclaredThrowableException ex) {
+ throw (Exception)ex.getCause();
+ }
+
+ }
+
}
Modified:
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/resources/XML_GreetMeDocLiteralResp.xml
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/resources/XML_GreetMeDocLiteralResp.xml?rev=1513727&r1=1513726&r2=1513727&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/resources/XML_GreetMeDocLiteralResp.xml
(original)
+++
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/resources/XML_GreetMeDocLiteralResp.xml
Wed Aug 14 05:04:42 2013
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8" ?>
-<ns4:greetMeResponse
xmlns:ns4="http://apache.org/hello_world_soap_http/types"><ns4:responseType>TestXMLBindingProviderMessage</ns4:responseType></ns4:greetMeResponse>
\ No newline at end of file
+<ns4:greetMeResponse
xmlns:ns4="http://apache.org/hello_world_xml_http/wrapped/types"><ns4:responseType>TestXMLBindingProviderMessage</ns4:responseType></ns4:greetMeResponse>