You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by em...@apache.org on 2013/08/29 13:10:19 UTC
svn commit: r1518587 - in /cxf/trunk:
core/src/main/java/org/apache/cxf/databinding/source/
core/src/main/java/org/apache/cxf/staxutils/validation/ systests/jaxws/
systests/jaxws/src/test/java/org/apache/cxf/systest/provider/
systests/uncategorized/
Author: ema
Date: Thu Aug 29 11:10:19 2013
New Revision: 1518587
URL: http://svn.apache.org/r1518587
Log:
[CXF-5237]:Validate XMLStream with MSV validator
Modified:
cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties
cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationInInterceptor.java
cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationOutInterceptor.java
cxf/trunk/systests/jaxws/pom.xml
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java
cxf/trunk/systests/uncategorized/pom.xml
Modified: cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties?rev=1518587&r1=1518586&r2=1518587&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties Thu Aug 29 11:10:19 2013
@@ -22,3 +22,4 @@ COULD_NOT_READ_XML_STREAM = Could not pa
COULD_NOT_WRITE_XML_STREAM = Could not generate the XML stream.
COULD_NOT_READ_XML_STREAM_CAUSED_BY = Could not parse the XML stream caused by: {0}: {1}.
COULD_NOT_WRITE_XML_STREAM_CAUSED_BY = Could not generate the XML stream caused by: {0}: {1}.
+COULD_NOT_VALIDATE_XML_STREAM = Failed to initialize MSV validator and validate the XMLStream
Modified: cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java?rev=1518587&r1=1518586&r2=1518587&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java Thu Aug 29 11:10:19 2013
@@ -28,6 +28,7 @@ import javax.activation.DataSource;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
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.sax.SAXSource;
@@ -36,16 +37,11 @@ import javax.xml.validation.Schema;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.xml.sax.SAXException;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.databinding.DataReader;
-import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.StaxInEndingInterceptor;
import org.apache.cxf.io.CachedOutputStream;
@@ -56,13 +52,16 @@ import org.apache.cxf.service.model.Mess
import org.apache.cxf.staxutils.DepthXMLStreamReader;
import org.apache.cxf.staxutils.FragmentStreamReader;
import org.apache.cxf.staxutils.StaxSource;
+import org.apache.cxf.staxutils.StaxStreamFilter;
import org.apache.cxf.staxutils.StaxUtils;
import org.apache.cxf.staxutils.W3CDOMStreamReader;
+import org.apache.cxf.staxutils.validation.WoodstoxValidationImpl;
public class XMLStreamDataReader implements DataReader<XMLStreamReader> {
private static final Logger LOG = LogUtils.getL7dLogger(XMLStreamDataReader.class);
+ private static final QName XOP = new QName("http://www.w3.org/2004/08/xop/include", "Include");
private final Class<?> preferred;
private Schema schema;
@@ -157,10 +156,7 @@ public class XMLStreamDataReader impleme
} catch (XMLStreamException e) {
throw new Fault("COULD_NOT_READ_XML_STREAM_CAUSED_BY", LOG, e,
e.getClass().getCanonicalName(), e.getMessage());
- } catch (SAXException e) {
- throw new Fault("COULD_NOT_READ_XML_STREAM_CAUSED_BY", LOG, e,
- e.getClass().getCanonicalName(), e.getMessage());
- }
+ }
}
private Object createStaxSource(XMLStreamReader input, Class<?> type) {
@@ -214,32 +210,31 @@ public class XMLStreamDataReader impleme
return input;
}
- private Element validate(XMLStreamReader input)
- throws XMLStreamException, SAXException, IOException {
- DOMSource ds = read(input);
+ private Element validate(XMLStreamReader input) throws XMLStreamException {
+ DOMSource ds = read(input);
Element rootElement = null;
if (ds.getNode() instanceof Document) {
rootElement = ((Document)ds.getNode()).getDocumentElement();
} else {
rootElement = (Element)ds.getNode();
}
- NodeList includeList = rootElement.getElementsByTagNameNS("http://www.w3.org/2004/08/xop/include", "Include");
- if (includeList.getLength() > 0) {
- Element newElement = (Element)rootElement.cloneNode(true);
- NodeList nodeList = newElement.getElementsByTagNameNS("http://www.w3.org/2004/08/xop/include", "Include");
- for (int i = 0; i < nodeList.getLength(); i++) {
- Element include = (Element)nodeList.item(i);
- Node parentNode = include.getParentNode();
- parentNode.removeChild(include);
- String cid = DOMUtils.getAttribute(include, "href");
- //set the fake base64Binary to validate instead of reading the attachment from message
- parentNode.setTextContent(javax.xml.bind.DatatypeConverter.printBase64Binary(cid.getBytes()));
- }
- schema.newValidator().validate(new DOMSource(newElement));
+
+ //filter xop node
+ XMLStreamReader reader = StaxUtils.createXMLStreamReader(ds);
+ XMLStreamReader filteredReader =
+ StaxUtils.createFilteredReader(reader,
+ new StaxStreamFilter(new QName[] {XOP}));
+
+ XMLStreamWriter nullWriter = StaxUtils.createXMLStreamWriter(new NUllOutputStream());
+ //TODO: expensive to create WoodstoxValidationImpl ?
+ WoodstoxValidationImpl impl = new WoodstoxValidationImpl();
+ if (impl.canValidate()) {
+ impl.setupValidation(nullWriter, message.getExchange().getService().getServiceInfos().get(0));
+ StaxUtils.copy(filteredReader, nullWriter);
} else {
- schema.newValidator().validate(ds);
+ throw new Fault("COULD_NOT_VALIDATE_XML_STREAM", LOG);
}
- return rootElement;
+ return rootElement;
}
private InputStream getInputStream(XMLStreamReader input)
@@ -292,4 +287,14 @@ public class XMLStreamDataReader impleme
message = (Message)value;
}
}
+
+ class NUllOutputStream extends OutputStream {
+ public void write(byte[] b, int off, int len) {
+ }
+ public void write(int b) {
+ }
+
+ public void write(byte[] b) throws IOException {
+ }
+ }
}
Modified: cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationInInterceptor.java?rev=1518587&r1=1518586&r2=1518587&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationInInterceptor.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationInInterceptor.java Thu Aug 29 11:10:19 2013
@@ -55,7 +55,7 @@ public class StaxSchemaValidationInInter
if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.IN, message)) {
try {
WoodstoxValidationImpl mgr = new WoodstoxValidationImpl();
- if (mgr != null) {
+ if (mgr.canValidate()) {
mgr.setupValidation(reader, message.getExchange().getService().getServiceInfos().get(0));
}
} catch (Throwable t) {
Modified: cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationOutInterceptor.java?rev=1518587&r1=1518586&r2=1518587&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationOutInterceptor.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationOutInterceptor.java Thu Aug 29 11:10:19 2013
@@ -55,7 +55,7 @@ public class StaxSchemaValidationOutInte
if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)) {
try {
WoodstoxValidationImpl mgr = new WoodstoxValidationImpl();
- if (mgr != null) {
+ if (mgr.canValidate()) {
mgr.setupValidation(writer, message.getExchange().getService().getServiceInfos().get(0));
}
} catch (Throwable t) {
Modified: cxf/trunk/systests/jaxws/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/pom.xml?rev=1518587&r1=1518586&r2=1518587&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/pom.xml (original)
+++ cxf/trunk/systests/jaxws/pom.xml Thu Aug 29 11:10:19 2013
@@ -216,6 +216,18 @@
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
</dependency>
+ <dependency>
+ <groupId>net.java.dev.msv</groupId>
+ <artifactId>msv-core</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>net.java.dev.msv</groupId>
+ <artifactId>msv-testharness</artifactId>
+ </exclusion>
+ </exclusions>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java?rev=1518587&r1=1518586&r2=1518587&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java (original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java Thu Aug 29 11:10:19 2013
@@ -150,7 +150,7 @@ public class ProviderClientServerTest ex
fail("Should have thrown an exception");
} catch (Exception ex) {
//expected
- assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
+ assertTrue(ex.getMessage().contains("the length of the value is 96, but the required maximum is 30"));
}
try {
Modified: cxf/trunk/systests/uncategorized/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/pom.xml?rev=1518587&r1=1518586&r2=1518587&view=diff
==============================================================================
--- cxf/trunk/systests/uncategorized/pom.xml (original)
+++ cxf/trunk/systests/uncategorized/pom.xml Thu Aug 29 11:10:19 2013
@@ -359,6 +359,17 @@
<artifactId>commons-httpclient</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>net.java.dev.msv</groupId>
+ <artifactId>msv-core</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>net.java.dev.msv</groupId>
+ <artifactId>msv-testharness</artifactId>
+ </exclusion>
+ </exclusions>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>