Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Can't find parser for namespace: http://www.ehcache.org/v3 #3242

Open
Naros opened this issue Aug 20, 2024 · 4 comments
Open

Error: Can't find parser for namespace: http://www.ehcache.org/v3 #3242

Naros opened this issue Aug 20, 2024 · 4 comments

Comments

@Naros
Copy link

Naros commented Aug 20, 2024

I have a basic cache configuration, as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns='http://www.ehcache.org/v3'>
  <cache alias="mycache">
    <key-type>java.lang.String</key-type>
    <value-type>java.lang.String</value-type>
    <heap unit="entries">50</heap>
    <disk unit="bytes">10485760</disk>
  </cache>
</config>

However when this XML gets parsed, I get "Can't find parser for namespace: http://www.ehcache.org/v3":

Caused by: org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration
	at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:185)
	at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:152)
	at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:139)
Caused by: java.lang.IllegalArgumentException: Can't find parser for namespace: http://www.ehcache.org/v3
	at org.ehcache.xml.ServiceConfigurationParser.parseConfiguration(ServiceConfigurationParser.java:75)
	at org.ehcache.xml.ConfigurationParser.parseServiceConfigurations(ConfigurationParser.java:166)
	at org.ehcache.xml.ConfigurationParser.documentToConfig(ConfigurationParser.java:285)
	at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:177)
	... 16 common frames omitted

I don't see anything wrong with this configuration and I'm using 3.9.6.

@Naros
Copy link
Author

Naros commented Aug 20, 2024

Looks to have been a misconfiguration, the cache needed to be defined as:

    <persistence directory="./target/data"/>
    
    <cache alias="mycache">
        <key-type>java.lang.String</key-type>
        <value-type>java.lang.String</value-type>
        <resources>
            <heap unit="entries">50</heap>
            <disk unit="B">10485760</disk>
        </resources>
    </cache>

I would suggest that error message be improved as it was very cryptic.

@chrisdennis
Copy link
Member

chrisdennis commented Aug 20, 2024

That is weirdly cryptic. The XML failure I'm seeing locally is:

Cannot confirm XML sub-type correctness. You might be missing client side libraries.
org.ehcache.xml.exceptions.XmlConfigurationException: Cannot confirm XML sub-type correctness. You might be missing client side libraries.
	at org.ehcache.xml.ConfigurationParser$FatalErrorHandler.fatalError(ConfigurationParser.java:356)
	at org.ehcache.xml.ConfigurationParser$FatalErrorHandler.error(ConfigurationParser.java:350)
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:138)
	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:395)
	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:326)
	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:283)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:453)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3231)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1791)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:741)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2783)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:601)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:504)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:841)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:338)
	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:177)
	at org.ehcache.xml.ConfigurationParser.uriToDocument(ConfigurationParser.java:239)
	at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:115)
	at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:90)
	at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:76)
Caused by: org.xml.sax.SAXParseException; systemId: file:/Users/cdennis/src/ehcache3-master/xml/build/resources/test/configs/weird.xml; lineNumber: 7; columnNumber: 24; cvc-complex-type.2.4.a: Invalid content was found starting with element 'disk'. One of '{"http://www.ehcache.org/v3":heap-store-settings, "http://www.ehcache.org/v3":disk-store-settings, "http://www.ehcache.org/v3":service-configuration}' is expected.
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:135)

Thats maybe slightly more informative than what you saw, but could obviously be improved too. Could you let me know what JVM version and vendor you were using when you saw that error?

FTR that's with this XML:

<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns='http://www.ehcache.org/v3'>
    <cache alias="mycache">
    <key-type>java.lang.String</key-type>
    <value-type>java.lang.String</value-type>
    <heap unit="entries">50</heap>
    <disk unit="bytes">10485760</disk>
</config>

@Naros
Copy link
Author

Naros commented Aug 20, 2024

Thanks @chrisdennis, sure, here are the details:

JVM

java 21.0.3 2024-04-16 LTS
Java(TM) SE Runtime Environment (build 21.0.3+7-LTS-152)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.3+7-LTS-152, mixed mode, sharing)

And if it matters, dependencies:

        <dependency>
            <groupId>org.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>3.9.6</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.3.1</version>
        </dependency>

@chrisdennis
Copy link
Member

Okay... paying a little more attention to your stack traces I understand why you're seeing a more cryptic stack trace than me. You're passing a DOM tree to the constructor and the parsing logic is assuming it's been validated against the assembled schema (which is hasn't, and wouldn't), which means it gets deeper in the config parse than it should have done. I can modify things to validate the passed in DOM against the schema which at least gets you the same error as me, which is still somewhat cryptic... but thats limited by the streaming event nature of a SAX parser.

chrisdennis added a commit to chrisdennis/ehcache3 that referenced this issue Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants