6 Replies Latest reply on May 3, 2010 12:21 PM by Andreas Trappe

    XSD-Validation does not work under fuse-esb-, but under ...

    Andreas Trappe Newbie



      ...fuse-esb- it's working.

      I receive the following exception:

      Validation: Error - File is NOT valid to Businesscase_Export_v6_9.xsd

      Exception: java.lang.Exception: java.lang.Exception: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'businesscases'


      The same xml valiation works in windows fuse esb and in the same version for unix i get an exception.  Why?

      I run fuse esb under suse linux enterprise 11, java Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_15-b04), Java HotSpot(TM) 64-Bit Server VM.

      ...The xml document is valid and the xsd file should be found, because the name is printed in the exception snipped.


      Follwing my custom code. The inputstream is a xml document (attached: XMLinputStream.xml) and it is validated against the schema (attached: Businesscase_Export_v6_9.xsd).


      Custom code:


      238        public synchronized static void validateXML(InputStream xmlInputStream, String xsdPathesProperty) throws Exception {[239|https://www2.hosted-projects.com/trac/renehelbig/ESB/browser/sources/branch/soliver-R2/Sources/sportscheck_utils/src/main/java/de/mmsdresden/sportscheck/utils/XMLUtils.java#L239]                // get path from property //

      240                PropertyLoaderImpl props = (PropertyLoaderImpl) new PathPropertyFactory().getImplementation();

      241                String path = props.getValueAbsolute(xsdPathesProperty);

      242                // check for an xsd at given path //

      243                File xsd = IOUtils.CheckForXSD(new File(path));

      244                if (xsd != null) {

      245                        // validate the InputStream //

      246                        LOGGER.info("Validation: Starting Validation with " + xsd.getName());

      247                        try {

      248                                DocumentBuilder parser;

      249                                // DOM tree //

      250                                parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();

      251                                org.w3c.dom.Document document = parser.parse(xmlInputStream);

      252                                // remove in xml file given schema declaration

      253                                document.getDocumentElement().removeAttribute("xsi:noNamespaceSchemaLocation");

      254                                // SchemaFactory for WXS schemas //

      255                                SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

      256                                // load the WXS schema //

      257                                Source schemaFile = new StreamSource(xsd);

      258                                Schema schema = factory.newSchema(schemaFile);

      259                                // validate //

      260                                Validator validator = schema.newValidator();

      261                                validator.validate(new DOMSource(document));

      262                        } catch (Exception e) {

      263                                LOGGER.info("Validation: Error - File is NOT valid to " + xsd.getName());

      264                                throw new Exception(e);

      265                        }

      266                        LOGGER.info("Validation: Done - File is valid to " + xsd.getName())

      ;[267|https://www2.hosted-projects.com/trac/renehelbig/ESB/browser/sources/branch/soliver-R2/Sources/sportscheck_utils/src/main/java/de/mmsdresden/sportscheck/utils/XMLUtils.java#L267]                } else {

      268                        LOGGER.info("Validation: Skipping - No XSD found at given Path");

      269                }

      270        }

      Thanks for helping,



      Edited by: misterbab on Apr 29, 2010 5:08 PM

        • 1. Re: XSD-Validation does not work under fuse-esb-, but under ...
          Freeman(Yue) Fang Master



          Could you add a print out after code

          SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);


          to see what's the SchemaFactory actually is.


          You can know if windows and linux use same ShemaFactory class, that's may explain the different behavior



          • 2. Re: XSD-Validation does not work under fuse-esb-, but under ...
            Andreas Trappe Newbie



            Indeed, there are several classes instanciated.

            the output says:


                 ########### schemafactory-name: org.apache.xerces.jaxp.validation.XMLSchemaFactory

                 ########### schemafactory-package: org.apache.xerces.jaxp.validation



               ########### schemafactory-name: com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaFactoryImpl

                 ########### schemafactory-package: com.sun.org.apache.xerces.internal.jaxp.validation.xs


            Do I have any options to control which class should be loaded? The packages might be different in both esb, fuse unix and fuse windows?


            Or should I change my custom code to a generic implementation, that works independently ?




            • 3. Re: XSD-Validation does not work under fuse-esb-, but under ...
              Freeman(Yue) Fang Master



              This is java spi mechanism, you can set system property in your code before you get SchemaFactory to specify which SchemaFactoryImpl you want to use

              Something like

              System.setPorperties("javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema",  the_factory_impl_class_you_want);



              • 4. Re: XSD-Validation does not work under fuse-esb-, but under ...
                Andreas Trappe Newbie

                Ok. I have set the system prop. to "com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaFactoryImpl and that works for win and unix same way.


                But changing that property I get other exception handling XML data in unix So setting those property in the XSD validation case works, but other components get corrupted. A fix for that problem could be, reset the validation property after validation. But doing so, I think some parallel excecuted threads in the esb will be influenced by the temporar property change.


                So, changing the property does not work in that case.


                For me the general question is, why does the FUSE ESB WINDOWS behaves different to FUSE ESB UNIX ? Why are different libraries (jars) are loaded.

                I can never be save, that my custom code behaves in the same way!


                How the the general solution should look like ?




                • 5. Re: XSD-Validation does not work under fuse-esb-, but under ...
                  Freeman(Yue) Fang Master


                  Sorry, I make a simple mistake from my previous post so just edit it.

                  The spi mechanism should be looking for impl from classpath first, if not there, will use the default one from jdk itself.


                  I still think the difference should come from the JDK versions used are different with your windows/unix platform.


                  I believe you are using jdk5 on windows, for some jdk5 version, there's a bug for looking for xercesimpl, please see , so even we ship apache xercesImpl.jar with servicemix, it can't load apache version SchemaFactoryImpl, it always load the one from jdk.


                  But for your Unix, the jdk version you're using maynot have that problem, so it load the one from xercesImpl.jar which we ship with smx.






                  Edited by: ffang on Apr 30, 2010 1:56 PM

                  • 6. Re: XSD-Validation does not work under fuse-esb-, but under ...
                    Andreas Trappe Newbie



                    sorry, my former comments where not really correct, because I mixed up my fuse server sources on my computer.

                    I compared fuse_windows_3.4.0.4 with fuse_unix_3.4.0.5. For that reason, the validation does work under windows, but not under unix.


                    But with fuse_3.4.0.5 I still have the validation problem.


                    Unfortunately, I could not fix my custom code to work with fuse_3.4.0.5.


                    Could anyone give recommendations what should be changed ?


                    I have seen the additional parameter in the startup script "servicemix": "-Djavax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema=org.apache.xerces.jaxp.validation.XMLSchemaFactory".

                    If I delete those parameter, validation works fine. But with the param. I could not get my custom validation run.

                    What I should change ? Is upgrade to jdk 6 an option ?


                    Regards !


                    Edited by: misterbab on May 3, 2010 4:21 PM