Author: bimargulies
Date: Wed Jun 10 19:14:40 2009
New Revision: 783457
URL: http://svn.apache.org/viewvc?rev=783457&view=rev
Log:
Arrange to return a clean fault for a schema validation error.
Added:
cxf/trunk/common/wstx-msv-validation/src/main/resources/org/
cxf/trunk/common/wstx-msv-validation/src/main/resources/org/apache/
cxf/trunk/common/wstx-msv-validation/src/main/resources/org/apache/cxf/
cxf/trunk/common/wstx-msv-validation/src/main/resources/org/apache/cxf/wstx_msv_validation/
cxf/trunk/common/wstx-msv-validation/src/main/resources/org/apache/cxf/wstx_msv_validation/Messages.properties
(with props)
Modified:
cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
cxf/trunk/parent/pom.xml
cxf/trunk/pom.xml
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/SchemaValidationTest.java
cxf/trunk/rt/databinding/aegis/src/test/resources/org/apache/cxf/aegis/integration/invalidArrayMessage.xml
Modified:
cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java?rev=783457&r1=783456&r2=783457&view=diff
==============================================================================
---
cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
(original)
+++
cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
Wed Jun 10 19:14:40 2009
@@ -30,31 +30,37 @@
import org.w3c.dom.Element;
+import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.service.model.SchemaInfo;
import org.apache.cxf.service.model.ServiceInfo;
import org.apache.cxf.staxutils.DepthXMLStreamReader;
import org.apache.ws.commons.schema.XmlSchema;
import org.codehaus.stax2.XMLStreamReader2;
import org.codehaus.stax2.XMLStreamWriter2;
+import org.codehaus.stax2.validation.ValidationProblemHandler;
+import org.codehaus.stax2.validation.XMLValidationException;
+import org.codehaus.stax2.validation.XMLValidationProblem;
import org.codehaus.stax2.validation.XMLValidationSchema;
/**
- * This class touches stax2 API, so it is kept separate to allow graceful
- * fallback.
+ * This class touches stax2 API, so it is kept separate to allow graceful
fallback.
*/
class Stax2ValidationUtils {
private static final Logger LOG =
LogUtils.getL7dLogger(Stax2ValidationUtils.class);
-
+
public Stax2ValidationUtils() {
- new W3CMultiSchemaFactory(); // will throw if wrong woodstox.
+ new W3CMultiSchemaFactory(); // will throw if wrong woodstox.
}
-
- /** {...@inheritdoc}
- * @throws XMLStreamException */
- public void setupValidation(XMLStreamReader reader,
- ServiceInfo serviceInfo) throws
XMLStreamException {
- // Gosh, this is bad, but I don't know a better solution, unless we're
willing
+
+ /**
+ * {...@inheritdoc}
+ *
+ * @throws XMLStreamException
+ */
+ public void setupValidation(XMLStreamReader reader, ServiceInfo
serviceInfo) throws XMLStreamException {
+ // Gosh, this is bad, but I don't know a better solution, unless we're
willing
// to require the stax2 API no matter what.
XMLStreamReader effectiveReader = reader;
if (effectiveReader instanceof DepthXMLStreamReader) {
@@ -62,17 +68,31 @@
}
final XMLStreamReader2 reader2 = (XMLStreamReader2)effectiveReader;
XMLValidationSchema vs = getValidator(serviceInfo);
+ reader2.setValidationProblemHandler(new ValidationProblemHandler() {
+
+ public void reportProblem(XMLValidationProblem problem) throws
XMLValidationException {
+ throw new Fault(new Message("READ_VALIDATION_ERROR", LOG,
problem.getMessage()),
+ Fault.FAULT_CODE_CLIENT);
+ }
+ });
reader2.validateAgainst(vs);
}
public void setupValidation(XMLStreamWriter writer, ServiceInfo
serviceInfo) throws XMLStreamException {
XMLStreamWriter2 writer2 = (XMLStreamWriter2)writer;
XMLValidationSchema vs = getValidator(serviceInfo);
+ writer2.setValidationProblemHandler(new ValidationProblemHandler() {
+
+ public void reportProblem(XMLValidationProblem problem) throws
XMLValidationException {
+ throw new Fault(problem.getMessage(), LOG);
+ }
+ });
writer2.validateAgainst(vs);
}
/**
* Create woodstox validator for a schema set.
+ *
* @param schemas
* @return
* @throws XMLStreamException
@@ -93,12 +113,11 @@
if (null == schemaSystemId) {
schemaSystemId = sch.getTargetNamespace();
}
-
- EmbeddedSchema embeddedSchema =
- new EmbeddedSchema(schemaSystemId, serialized);
+
+ EmbeddedSchema embeddedSchema = new EmbeddedSchema(schemaSystemId,
serialized);
sources.put(sch.getTargetNamespace(), embeddedSchema);
}
-
+
W3CMultiSchemaFactory factory = new W3CMultiSchemaFactory();
XMLValidationSchema vs;
// I don't think that we need the baseURI.
@@ -106,5 +125,4 @@
return vs;
}
-
}
Added:
cxf/trunk/common/wstx-msv-validation/src/main/resources/org/apache/cxf/wstx_msv_validation/Messages.properties
URL:
http://svn.apache.org/viewvc/cxf/trunk/common/wstx-msv-validation/src/main/resources/org/apache/cxf/wstx_msv_validation/Messages.properties?rev=783457&view=auto
==============================================================================
---
cxf/trunk/common/wstx-msv-validation/src/main/resources/org/apache/cxf/wstx_msv_validation/Messages.properties
(added)
+++
cxf/trunk/common/wstx-msv-validation/src/main/resources/org/apache/cxf/wstx_msv_validation/Messages.properties
Wed Jun 10 19:14:40 2009
@@ -0,0 +1,20 @@
+#
+#
+# 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.
+#
+READ_VALIDATION_ERROR = Schema validation error on message from client: {0}.
\ No newline at end of file
Propchange:
cxf/trunk/common/wstx-msv-validation/src/main/resources/org/apache/cxf/wstx_msv_validation/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/common/wstx-msv-validation/src/main/resources/org/apache/cxf/wstx_msv_validation/Messages.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cxf/trunk/parent/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/parent/pom.xml?rev=783457&r1=783456&r2=783457&view=diff
==============================================================================
--- cxf/trunk/parent/pom.xml (original)
+++ cxf/trunk/parent/pom.xml Wed Jun 10 19:14:40 2009
@@ -1190,7 +1190,7 @@
<properties>
<stax.impl.groupId>org.codehaus.woodstox</stax.impl.groupId>
<stax.impl.artifactId>woodstox-core-asl</stax.impl.artifactId>
- <stax.impl.version>4.0.3</stax.impl.version>
+ <stax.impl.version>4.1.0-SNAPSHOT</stax.impl.version>
</properties>
</profile>
<profile>
Modified: cxf/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/pom.xml?rev=783457&r1=783456&r2=783457&view=diff
==============================================================================
--- cxf/trunk/pom.xml (original)
+++ cxf/trunk/pom.xml Wed Jun 10 19:14:40 2009
@@ -57,6 +57,17 @@
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
</repository>
+ <repository>
+ <id>codehaus snapshots</id>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <name>Java.net Repository for Maven</name>
+ <url>http://snapshots.repository.codehaus.org</url>
+ </repository>
</repositories>
<distributionManagement>
Modified:
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/SchemaValidationTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/SchemaValidationTest.java?rev=783457&r1=783456&r2=783457&view=diff
==============================================================================
---
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/SchemaValidationTest.java
(original)
+++
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/SchemaValidationTest.java
Wed Jun 10 19:14:40 2009
@@ -19,12 +19,18 @@
package org.apache.cxf.aegis.integration;
+import java.io.StringWriter;
+
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.w3c.dom.Node;
import org.apache.cxf.aegis.AbstractAegisTest;
import org.apache.cxf.aegis.services.ArrayService;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.message.Message;
+import org.apache.cxf.staxutils.StaxUtils;
import org.junit.Before;
import org.junit.Test;
@@ -48,6 +54,13 @@
@Test
public void testInvalidArray() throws Exception {
- invoke("Array",
"/org/apache/cxf/aegis/integration/invalidArrayMessage.xml");
+ Node r = invoke("Array",
"/org/apache/cxf/aegis/integration/invalidArrayMessage.xml");
+ assertNotNull(r);
+ StringWriter out = new StringWriter();
+ XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
+ StaxUtils.writeNode(r, writer, true);
+ writer.flush();
+ String m = out.toString();
+ assertTrue(m.contains("Fault"));
}
}
Modified:
cxf/trunk/rt/databinding/aegis/src/test/resources/org/apache/cxf/aegis/integration/invalidArrayMessage.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/resources/org/apache/cxf/aegis/integration/invalidArrayMessage.xml?rev=783457&r1=783456&r2=783457&view=diff
==============================================================================
---
cxf/trunk/rt/databinding/aegis/src/test/resources/org/apache/cxf/aegis/integration/invalidArrayMessage.xml
(original)
+++
cxf/trunk/rt/databinding/aegis/src/test/resources/org/apache/cxf/aegis/integration/invalidArrayMessage.xml
Wed Jun 10 19:14:40 2009
@@ -27,7 +27,7 @@
<jns0:anyType><penguin
xmlns='uri:linux'>emperor</penguin></jns0:anyType>
<jns0:anyType><moon xmlns='uri:planets'>blue</moon></jns0:anyType>
</jns0:anything>
- <jns0:after>after items</jns0:after>
+ <jns0:laughter>after items</jns0:laughter>
</jns0:submitW3CArray>
</soap-env:Body>
</soap-env:Envelope>