You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@beehive.apache.org by Eddie O'Neil <ek...@gmail.com> on 2005/09/20 01:07:11 UTC

netui config file validation -- one last change

All--

  I've got one last change to make to the error reporting done when
validating the NetUI config file.  Today on Tomcat 5.0, Java 5
validation doesn't work in the default Tomcat install.  The result is
a big, scary-looking stack trace dumped to the console.

  Often, this stack trace isn't fatal and just indicates a need to
correclty enable Java 5 XSD validation; a NetUI warning message is
displayed for that.

  The change makes the stack trace a *debug* message and passes the
resource paths for both the XML and XSD files.  This improves the
error reporting when validation is mis configured.

  It's a very low risk change; the diff is pasted below.

  I'll check this in tonight and then branch unless anyone has any concerns.

Eddie



<snip>
Index: src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
===================================================================
--- src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
    (revision 2902
99)
+++ src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
    (working copy)

@@ -142,7 +142,8 @@
                 // Validate the XML against the schema
                 xsdInputStream = SCHEMA_RESOLVER.getInputStream();
                 SchemaValidator schemaValidator =
SchemaValidatorFactory.getInstance();
-                schemaValidator.validate(xsdInputStream, xmlInputStream);
+               
schemaValidator.validate(SCHEMA_RESOLVER.getResourcePath(),
xsdInputStream,
+                    _configFilePath, xmlInputStream);
                 try
                 {
                     if ( xmlInputStream != null )
Index: src/util/org/apache/beehive/netui/util/xml/validation/SchemaValidator.java
===================================================================
--- src/util/org/apache/beehive/netui/util/xml/validation/SchemaValidator.java
 (revision 290299)
+++ src/util/org/apache/beehive/netui/util/xml/validation/SchemaValidator.java
 (working copy)
@@ -26,5 +26,6 @@

     /**
      */
-    public abstract void validate(InputStream xsdInputStream,
InputStream xmlInputStrea);
+    public abstract void validate(String xsdResourcePath, InputStream
xsdInputStream,
+                                  String xmlResourcePath, InputStream
xmlInputStrea);
 }
Index: src/util/org/apache/beehive/netui/util/xml/validation/internal/SchemaValidatorJava5.java
===================================================================
--- src/util/org/apache/beehive/netui/util/xml/validation/internal/SchemaValidatorJava5.java
   (revision 2902
99)
+++ src/util/org/apache/beehive/netui/util/xml/validation/internal/SchemaValidatorJava5.java
   (working copy)

@@ -45,8 +45,8 @@

     private static final Logger LOGGER =
Logger.getInstance(SchemaValidatorJava5.class);

-    public void validate(InputStream xsdInputStream, InputStream
xmlInputStream) {
-
+    public void validate(String xsdResourcePath, InputStream xsdInputStream,
+                         String xmlResourcePath, InputStream xmlInputStream) {
         try {
             SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
             StreamSource xsdStreamSource = new StreamSource(xsdInputStream);
@@ -68,9 +68,16 @@
             throw new SchemaValidationException("Exception occurred
validating document.  Cause: " + e, e);
         }
         catch(TransformerFactoryConfigurationError error) {
+            String message =
+                "Beehive NetUI disabled validation on the XML file
\"" + xmlResourcePath + "\" because the XM
L TransformFactory was " +
+                "configured incorrectly.  We suggest configuring the
application runtime to enable Java 5 XML
 Schema validation as additional " +
+                "application configuration errors may occur later.  A
stack trace is available in the NetUI d
ebug log.  Cause: " + error;
+
             if(LOGGER.isWarnEnabled())
-                LOGGER.warn("Beehive NetUI disabled validation on the
given file because the XML TransformFac
tory was configured incorrectly.  " +
-                    "We suggest fixing this error as errors may occur
as a result of having an invalid XML in
stance document.  Cause: " + error, error);
+                LOGGER.warn(message);
+
+            if(LOGGER.isDebugEnabled())
+                LOGGER.debug("XML TransformFactory stack trace:" , error);
         }
     }
 }
Index: src/util/org/apache/beehive/netui/util/config/parser/NetUIConfigParser.java
===================================================================
--- src/util/org/apache/beehive/netui/util/config/parser/NetUIConfigParser.java
(revision 290299)
+++ src/util/org/apache/beehive/netui/util/config/parser/NetUIConfigParser.java
(working copy)
@@ -126,7 +126,8 @@
             xsdInputStream = SCHEMA_RESOLVER.getInputStream();
             try {
                 SchemaValidator schemaValidator =
SchemaValidatorFactory.getInstance();
-                schemaValidator.validate(xsdInputStream, xmlInputStream);
+               
schemaValidator.validate(SCHEMA_RESOLVER.getResourcePath(),
xsdInputStream,
+                    theXmlResolver.getResourcePath(), xmlInputStream);
             }
             catch(SchemaValidationException e) {
                 throw new ConfigInitializationException("Validation
errors occurred parsing the config file \
"" +
</snip>

Re: netui config file validation -- one last change

Posted by Eddie O'Neil <ek...@gmail.com>.
  The continuing saga of Schema validation.  This is something that
was *so* much easier with XMLBeans...

  As it turns out, schema validation as documented via JAXP in JDK 1.5
isn't quite sufficient and (for the situations I've run into so far)
needs to be configured as if one was just validating DOM.  I've run
into this and am just going to switch the two places NetUI does
in-server schema validation to validating DOMs which makes it work on
Tomcat 5.0 and avoids a whole slew of config problems.

  Apologies for the delay in installers; should have this in trunk/
shortly and integ'ed into branches/v1/final in a bit.

Eddie



On 9/19/05, Rich Feit <ri...@gmail.com> wrote:
> Sounds great to me -- much less scary than seeing a stacktrace when you
> start your app.  :)
> 
> Eddie O'Neil wrote:
> 
> >All--
> >
> >  I've got one last change to make to the error reporting done when
> >validating the NetUI config file.  Today on Tomcat 5.0, Java 5
> >validation doesn't work in the default Tomcat install.  The result is
> >a big, scary-looking stack trace dumped to the console.
> >
> >  Often, this stack trace isn't fatal and just indicates a need to
> >correclty enable Java 5 XSD validation; a NetUI warning message is
> >displayed for that.
> >
> >  The change makes the stack trace a *debug* message and passes the
> >resource paths for both the XML and XSD files.  This improves the
> >error reporting when validation is mis configured.
> >
> >  It's a very low risk change; the diff is pasted below.
> >
> >  I'll check this in tonight and then branch unless anyone has any concerns.
> >
> >Eddie
> >
> >
> >
> ><snip>
> >Index: src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
> >===================================================================
> >--- src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
> >    (revision 2902
> >99)
> >+++ src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
> >    (working copy)
> >
> >@@ -142,7 +142,8 @@
> >                 // Validate the XML against the schema
> >                 xsdInputStream = SCHEMA_RESOLVER.getInputStream();
> >                 SchemaValidator schemaValidator =
> >SchemaValidatorFactory.getInstance();
> >-                schemaValidator.validate(xsdInputStream, xmlInputStream);
> >+
> >schemaValidator.validate(SCHEMA_RESOLVER.getResourcePath(),
> >xsdInputStream,
> >+                    _configFilePath, xmlInputStream);
> >                 try
> >                 {
> >                     if ( xmlInputStream != null )
> >Index: src/util/org/apache/beehive/netui/util/xml/validation/SchemaValidator.java
> >===================================================================
> >--- src/util/org/apache/beehive/netui/util/xml/validation/SchemaValidator.java
> > (revision 290299)
> >+++ src/util/org/apache/beehive/netui/util/xml/validation/SchemaValidator.java
> > (working copy)
> >@@ -26,5 +26,6 @@
> >
> >     /**
> >      */
> >-    public abstract void validate(InputStream xsdInputStream,
> >InputStream xmlInputStrea);
> >+    public abstract void validate(String xsdResourcePath, InputStream
> >xsdInputStream,
> >+                                  String xmlResourcePath, InputStream
> >xmlInputStrea);
> > }
> >Index: src/util/org/apache/beehive/netui/util/xml/validation/internal/SchemaValidatorJava5.java
> >===================================================================
> >--- src/util/org/apache/beehive/netui/util/xml/validation/internal/SchemaValidatorJava5.java
> >   (revision 2902
> >99)
> >+++ src/util/org/apache/beehive/netui/util/xml/validation/internal/SchemaValidatorJava5.java
> >   (working copy)
> >
> >@@ -45,8 +45,8 @@
> >
> >     private static final Logger LOGGER =
> >Logger.getInstance(SchemaValidatorJava5.class);
> >
> >-    public void validate(InputStream xsdInputStream, InputStream
> >xmlInputStream) {
> >-
> >+    public void validate(String xsdResourcePath, InputStream xsdInputStream,
> >+                         String xmlResourcePath, InputStream xmlInputStream) {
> >         try {
> >             SchemaFactory factory =
> >SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
> >             StreamSource xsdStreamSource = new StreamSource(xsdInputStream);
> >@@ -68,9 +68,16 @@
> >             throw new SchemaValidationException("Exception occurred
> >validating document.  Cause: " + e, e);
> >         }
> >         catch(TransformerFactoryConfigurationError error) {
> >+            String message =
> >+                "Beehive NetUI disabled validation on the XML file
> >\"" + xmlResourcePath + "\" because the XM
> >L TransformFactory was " +
> >+                "configured incorrectly.  We suggest configuring the
> >application runtime to enable Java 5 XML
> > Schema validation as additional " +
> >+                "application configuration errors may occur later.  A
> >stack trace is available in the NetUI d
> >ebug log.  Cause: " + error;
> >+
> >             if(LOGGER.isWarnEnabled())
> >-                LOGGER.warn("Beehive NetUI disabled validation on the
> >given file because the XML TransformFac
> >tory was configured incorrectly.  " +
> >-                    "We suggest fixing this error as errors may occur
> >as a result of having an invalid XML in
> >stance document.  Cause: " + error, error);
> >+                LOGGER.warn(message);
> >+
> >+            if(LOGGER.isDebugEnabled())
> >+                LOGGER.debug("XML TransformFactory stack trace:" , error);
> >         }
> >     }
> > }
> >Index: src/util/org/apache/beehive/netui/util/config/parser/NetUIConfigParser.java
> >===================================================================
> >--- src/util/org/apache/beehive/netui/util/config/parser/NetUIConfigParser.java
> >(revision 290299)
> >+++ src/util/org/apache/beehive/netui/util/config/parser/NetUIConfigParser.java
> >(working copy)
> >@@ -126,7 +126,8 @@
> >             xsdInputStream = SCHEMA_RESOLVER.getInputStream();
> >             try {
> >                 SchemaValidator schemaValidator =
> >SchemaValidatorFactory.getInstance();
> >-                schemaValidator.validate(xsdInputStream, xmlInputStream);
> >+
> >schemaValidator.validate(SCHEMA_RESOLVER.getResourcePath(),
> >xsdInputStream,
> >+                    theXmlResolver.getResourcePath(), xmlInputStream);
> >             }
> >             catch(SchemaValidationException e) {
> >                 throw new ConfigInitializationException("Validation
> >errors occurred parsing the config file \
> >"" +
> ></snip>
> >
> >
> >
>

Re: netui config file validation -- one last change

Posted by Rich Feit <ri...@gmail.com>.
Sounds great to me -- much less scary than seeing a stacktrace when you
start your app.  :)

Eddie O'Neil wrote:

>All--
>
>  I've got one last change to make to the error reporting done when
>validating the NetUI config file.  Today on Tomcat 5.0, Java 5
>validation doesn't work in the default Tomcat install.  The result is
>a big, scary-looking stack trace dumped to the console.
>
>  Often, this stack trace isn't fatal and just indicates a need to
>correclty enable Java 5 XSD validation; a NetUI warning message is
>displayed for that.
>
>  The change makes the stack trace a *debug* message and passes the
>resource paths for both the XML and XSD files.  This improves the
>error reporting when validation is mis configured.
>
>  It's a very low risk change; the diff is pasted below.
>
>  I'll check this in tonight and then branch unless anyone has any concerns.
>
>Eddie
>
>
>
><snip>
>Index: src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
>===================================================================
>--- src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
>    (revision 2902
>99)
>+++ src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
>    (working copy)
>
>@@ -142,7 +142,8 @@
>                 // Validate the XML against the schema
>                 xsdInputStream = SCHEMA_RESOLVER.getInputStream();
>                 SchemaValidator schemaValidator =
>SchemaValidatorFactory.getInstance();
>-                schemaValidator.validate(xsdInputStream, xmlInputStream);
>+               
>schemaValidator.validate(SCHEMA_RESOLVER.getResourcePath(),
>xsdInputStream,
>+                    _configFilePath, xmlInputStream);
>                 try
>                 {
>                     if ( xmlInputStream != null )
>Index: src/util/org/apache/beehive/netui/util/xml/validation/SchemaValidator.java
>===================================================================
>--- src/util/org/apache/beehive/netui/util/xml/validation/SchemaValidator.java
> (revision 290299)
>+++ src/util/org/apache/beehive/netui/util/xml/validation/SchemaValidator.java
> (working copy)
>@@ -26,5 +26,6 @@
>
>     /**
>      */
>-    public abstract void validate(InputStream xsdInputStream,
>InputStream xmlInputStrea);
>+    public abstract void validate(String xsdResourcePath, InputStream
>xsdInputStream,
>+                                  String xmlResourcePath, InputStream
>xmlInputStrea);
> }
>Index: src/util/org/apache/beehive/netui/util/xml/validation/internal/SchemaValidatorJava5.java
>===================================================================
>--- src/util/org/apache/beehive/netui/util/xml/validation/internal/SchemaValidatorJava5.java
>   (revision 2902
>99)
>+++ src/util/org/apache/beehive/netui/util/xml/validation/internal/SchemaValidatorJava5.java
>   (working copy)
>
>@@ -45,8 +45,8 @@
>
>     private static final Logger LOGGER =
>Logger.getInstance(SchemaValidatorJava5.class);
>
>-    public void validate(InputStream xsdInputStream, InputStream
>xmlInputStream) {
>-
>+    public void validate(String xsdResourcePath, InputStream xsdInputStream,
>+                         String xmlResourcePath, InputStream xmlInputStream) {
>         try {
>             SchemaFactory factory =
>SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
>             StreamSource xsdStreamSource = new StreamSource(xsdInputStream);
>@@ -68,9 +68,16 @@
>             throw new SchemaValidationException("Exception occurred
>validating document.  Cause: " + e, e);
>         }
>         catch(TransformerFactoryConfigurationError error) {
>+            String message =
>+                "Beehive NetUI disabled validation on the XML file
>\"" + xmlResourcePath + "\" because the XM
>L TransformFactory was " +
>+                "configured incorrectly.  We suggest configuring the
>application runtime to enable Java 5 XML
> Schema validation as additional " +
>+                "application configuration errors may occur later.  A
>stack trace is available in the NetUI d
>ebug log.  Cause: " + error;
>+
>             if(LOGGER.isWarnEnabled())
>-                LOGGER.warn("Beehive NetUI disabled validation on the
>given file because the XML TransformFac
>tory was configured incorrectly.  " +
>-                    "We suggest fixing this error as errors may occur
>as a result of having an invalid XML in
>stance document.  Cause: " + error, error);
>+                LOGGER.warn(message);
>+
>+            if(LOGGER.isDebugEnabled())
>+                LOGGER.debug("XML TransformFactory stack trace:" , error);
>         }
>     }
> }
>Index: src/util/org/apache/beehive/netui/util/config/parser/NetUIConfigParser.java
>===================================================================
>--- src/util/org/apache/beehive/netui/util/config/parser/NetUIConfigParser.java
>(revision 290299)
>+++ src/util/org/apache/beehive/netui/util/config/parser/NetUIConfigParser.java
>(working copy)
>@@ -126,7 +126,8 @@
>             xsdInputStream = SCHEMA_RESOLVER.getInputStream();
>             try {
>                 SchemaValidator schemaValidator =
>SchemaValidatorFactory.getInstance();
>-                schemaValidator.validate(xsdInputStream, xmlInputStream);
>+               
>schemaValidator.validate(SCHEMA_RESOLVER.getResourcePath(),
>xsdInputStream,
>+                    theXmlResolver.getResourcePath(), xmlInputStream);
>             }
>             catch(SchemaValidationException e) {
>                 throw new ConfigInitializationException("Validation
>errors occurred parsing the config file \
>"" +
></snip>
>
>  
>