Author: thomas.diesler(a)jboss.com
Date: 2008-02-29 15:30:31 -0500 (Fri, 29 Feb 2008)
New Revision: 5874
Added:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/LoggingErrorHandler.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/SchemaValidationHelper.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/StrictlyValidErrorHandler.java
Removed:
stack/native/trunk/src/main/java/org/jboss/ws/core/utils/SchemaValidationHelper.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/ValidationErrorHandler.java
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/annotation/SchemaValidation.java
stack/native/trunk/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java
stack/native/trunk/src/main/java/org/jboss/ws/feature/SchemaValidationFeature.java
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1172/JBWS1172TestCase.java
Log:
[JBWS-1172] Support schema validation for incoming/outgoing messages
Modified: stack/native/trunk/src/main/java/org/jboss/ws/annotation/SchemaValidation.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/annotation/SchemaValidation.java 2008-02-29
20:13:20 UTC (rev 5873)
+++
stack/native/trunk/src/main/java/org/jboss/ws/annotation/SchemaValidation.java 2008-02-29
20:30:31 UTC (rev 5874)
@@ -28,7 +28,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.jboss.ws.extensions.validation.ValidationErrorHandler;
+import org.jboss.ws.extensions.validation.StrictlyValidErrorHandler;
/**
* This feature represents the use of schema validation with a
@@ -53,5 +53,5 @@
* Optional property for the error handler.
* If this is not specified the @{ValidationErrorHandler} will be used.
*/
- Class errorHandler() default ValidationErrorHandler.class;
+ Class errorHandler() default StrictlyValidErrorHandler.class;
}
Modified: stack/native/trunk/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java 2008-02-29
20:13:20 UTC (rev 5873)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java 2008-02-29
20:30:31 UTC (rev 5874)
@@ -32,8 +32,8 @@
import org.jboss.ws.WSException;
import org.jboss.ws.core.CommonMessageContext;
import org.jboss.ws.core.soap.SOAPContent.State;
-import org.jboss.ws.core.utils.SchemaValidationHelper;
import org.jboss.ws.extensions.validation.SchemaExtractor;
+import org.jboss.ws.extensions.validation.SchemaValidationHelper;
import org.jboss.ws.feature.SchemaValidationFeature;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.wsf.common.DOMUtils;
Deleted:
stack/native/trunk/src/main/java/org/jboss/ws/core/utils/SchemaValidationHelper.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/utils/SchemaValidationHelper.java 2008-02-29
20:13:20 UTC (rev 5873)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/utils/SchemaValidationHelper.java 2008-02-29
20:30:31 UTC (rev 5874)
@@ -1,90 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.ws.core.utils;
-
-// $Id$
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.net.URL;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.jboss.ws.extensions.validation.ValidationErrorHandler;
-import org.jboss.wsf.common.DOMWriter;
-import org.w3c.dom.Element;
-import org.xml.sax.ErrorHandler;
-
-/**
- * [JBWS-1172] Support schema validation for incoming messages
- *
- * @author Thomas.Diesler(a)jboss.com
- * @since 28-Feb-2008
- */
-public class SchemaValidationHelper
-{
- private URL xsdURL;
- private ErrorHandler errorHandler = new ValidationErrorHandler();
-
- public SchemaValidationHelper(URL xsdURL)
- {
- this.xsdURL = xsdURL;
- }
-
- public SchemaValidationHelper setErrorHandler(ErrorHandler errorHandler)
- {
- this.errorHandler = errorHandler;
- return this;
- }
-
- public void validateDocument(String inxml) throws Exception
- {
- ByteArrayInputStream bais = new ByteArrayInputStream(inxml.getBytes());
- validateDocument(bais);
- }
-
- public void validateDocument(Element inxml) throws Exception
- {
- String xmlStr = DOMWriter.printNode(inxml, false);
- validateDocument(xmlStr);
- }
-
- public void validateDocument(InputStream inxml) throws Exception
- {
- DocumentBuilder builder = getDocumentBuilder();
- builder.parse(inxml);
- }
-
- private DocumentBuilder getDocumentBuilder() throws ParserConfigurationException
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setValidating(true);
- factory.setNamespaceAware(true);
-
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schema...;,
"http://www.w3.org/2001/XMLSchema");
-
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schema...;,
xsdURL.toExternalForm());
- DocumentBuilder builder = factory.newDocumentBuilder();
- builder.setErrorHandler(errorHandler);
- return builder;
- }
-}
Added:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/LoggingErrorHandler.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/LoggingErrorHandler.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/LoggingErrorHandler.java 2008-02-29
20:30:31 UTC (rev 5874)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.extensions.validation;
+
+//$Id$
+
+import org.jboss.logging.Logger;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * An error handler that logs a @{SAXException} on error.
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 29-Feb-2008
+ */
+public class LoggingErrorHandler implements ErrorHandler
+{
+ // provide logging
+ private static Logger log = Logger.getLogger(LoggingErrorHandler.class);
+
+ public void error(SAXParseException ex) throws SAXException
+ {
+ log.error(ex.toString());
+ }
+
+ public void fatalError(SAXParseException ex) throws SAXException
+ {
+ log.fatal(ex.toString());
+ }
+
+ public void warning(SAXParseException ex) throws SAXException
+ {
+ log.warn(ex.toString());
+ }
+}
Property changes on:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/LoggingErrorHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/SchemaValidationHelper.java
(from rev 5873,
stack/native/trunk/src/main/java/org/jboss/ws/core/utils/SchemaValidationHelper.java)
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/SchemaValidationHelper.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/SchemaValidationHelper.java 2008-02-29
20:30:31 UTC (rev 5874)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.extensions.validation;
+
+// $Id$
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.wsf.common.DOMWriter;
+import org.w3c.dom.Element;
+import org.xml.sax.ErrorHandler;
+
+/**
+ * [JBWS-1172] Support schema validation for incoming messages
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 28-Feb-2008
+ */
+public class SchemaValidationHelper
+{
+ private URL xsdURL;
+ private ErrorHandler errorHandler = new StrictlyValidErrorHandler();
+
+ public SchemaValidationHelper(URL xsdURL)
+ {
+ this.xsdURL = xsdURL;
+ }
+
+ public SchemaValidationHelper setErrorHandler(ErrorHandler errorHandler)
+ {
+ this.errorHandler = errorHandler;
+ return this;
+ }
+
+ public void validateDocument(String inxml) throws Exception
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(inxml.getBytes());
+ validateDocument(bais);
+ }
+
+ public void validateDocument(Element inxml) throws Exception
+ {
+ String xmlStr = DOMWriter.printNode(inxml, false);
+ validateDocument(xmlStr);
+ }
+
+ public void validateDocument(InputStream inxml) throws Exception
+ {
+ DocumentBuilder builder = getDocumentBuilder();
+ builder.parse(inxml);
+ }
+
+ private DocumentBuilder getDocumentBuilder() throws ParserConfigurationException
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(true);
+ factory.setNamespaceAware(true);
+
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schema...;,
"http://www.w3.org/2001/XMLSchema");
+
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schema...;,
xsdURL.toExternalForm());
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setErrorHandler(errorHandler);
+ return builder;
+ }
+}
Copied:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/StrictlyValidErrorHandler.java
(from rev 5869,
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/ValidationErrorHandler.java)
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/StrictlyValidErrorHandler.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/StrictlyValidErrorHandler.java 2008-02-29
20:30:31 UTC (rev 5874)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.extensions.validation;
+
+//$Id$
+
+import org.jboss.logging.Logger;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * An error handler that throws a @{SAXException} on error and fatal error.
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 29-Feb-2008
+ */
+public class StrictlyValidErrorHandler implements ErrorHandler
+{
+ // provide logging
+ private static Logger log = Logger.getLogger(StrictlyValidErrorHandler.class);
+
+ public void error(SAXParseException ex) throws SAXException
+ {
+ log.error(ex.toString());
+ throw new SAXException(ex.getMessage());
+ }
+
+ public void fatalError(SAXParseException ex) throws SAXException
+ {
+ log.fatal(ex.toString());
+ throw new SAXException(ex.getMessage());
+ }
+
+ public void warning(SAXParseException ex) throws SAXException
+ {
+ log.warn(ex.toString());
+ }
+}
Deleted:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/ValidationErrorHandler.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/ValidationErrorHandler.java 2008-02-29
20:13:20 UTC (rev 5873)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/validation/ValidationErrorHandler.java 2008-02-29
20:30:31 UTC (rev 5874)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.ws.extensions.validation;
-
-//$Id$
-
-import org.jboss.logging.Logger;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-/**
- * Extracts the schema from a given WSDL
- *
- * @author Thomas.Diesler(a)jboss.com
- * @since 29-Feb-2008
- */
-public class ValidationErrorHandler implements ErrorHandler
-{
- // provide logging
- private static Logger log = Logger.getLogger(ValidationErrorHandler.class);
-
- public void error(SAXParseException ex) throws SAXException
- {
- log.error(ex.toString());
- throw new SAXException(ex.getMessage());
- }
-
- public void fatalError(SAXParseException ex) throws SAXException
- {
- log.fatal(ex.toString());
- throw new SAXException(ex.getMessage());
- }
-
- public void warning(SAXParseException ex) throws SAXException
- {
- log.warn(ex.toString());
- }
-}
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/feature/SchemaValidationFeature.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/feature/SchemaValidationFeature.java 2008-02-29
20:13:20 UTC (rev 5873)
+++
stack/native/trunk/src/main/java/org/jboss/ws/feature/SchemaValidationFeature.java 2008-02-29
20:30:31 UTC (rev 5874)
@@ -26,7 +26,7 @@
import javax.xml.ws.WebServiceFeature;
import org.jboss.ws.Constants;
-import org.jboss.ws.extensions.validation.ValidationErrorHandler;
+import org.jboss.ws.extensions.validation.StrictlyValidErrorHandler;
import org.xml.sax.ErrorHandler;
/**
@@ -55,7 +55,7 @@
* Optional property for the error handler.
* If this is not specified the @{ValidationErrorHandler} will be used.
*/
- protected ErrorHandler errorHandler = new ValidationErrorHandler();
+ protected ErrorHandler errorHandler = new StrictlyValidErrorHandler();
/**
* Create an <code>SchemaValidationFeature</code>.
Modified:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1172/JBWS1172TestCase.java
===================================================================
---
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1172/JBWS1172TestCase.java 2008-02-29
20:13:20 UTC (rev 5873)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1172/JBWS1172TestCase.java 2008-02-29
20:30:31 UTC (rev 5874)
@@ -33,8 +33,8 @@
import junit.framework.Test;
import org.jboss.test.ws.jaxws.jbws1172.types.MyTest;
-import org.jboss.ws.core.utils.SchemaValidationHelper;
import org.jboss.ws.extensions.validation.SchemaExtractor;
+import org.jboss.ws.extensions.validation.SchemaValidationHelper;
import org.jboss.ws.feature.SchemaValidationFeature;
import org.jboss.wsf.test.JBossWSTest;
import org.jboss.wsf.test.JBossWSTestSetup;