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

mxparser cannot be found in OSGI-environment (Virgo 3.7.4) when using x-stream 1.4.16 #250

Closed
mnckstle opened this issue Apr 20, 2021 · 2 comments
Assignees
Labels

Comments

@mnckstle
Copy link

When changing xstream 1.4.14 to 1.4.16 a new parser (mxparser) was introduced. But xstream inside OSGI-Container (Virgo) does not seem to find the new parser, although packaged and residing in classpath.
This is the shortened stacktrace with the new version:

java.lang.IllegalStateException: com.thoughtworks.xstream.io.StreamException: Cannot create XmlPullParser
...
Caused by: com.thoughtworks.xstream.io.StreamException: Cannot create XmlPullParser
        at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:56)
        at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:65)
        at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1303)
...
Caused by: org.xmlpull.v1.XmlPullParserException: caused by: org.xmlpull.v1.XmlPullParserException: resource not found: /META-INF/services/org.xmlpull.v1.XmlPullParserFactory make sure that parser implementing XmlPull API is available
        at org.xmlpull.v1.XmlPullParserFactory.newInstance(XmlPullParserFactory.java:294)
        at org.xmlpull.v1.XmlPullParserFactory.newInstance(XmlPullParserFactory.java:259)
        at com.thoughtworks.xstream.io.xml.XppDriver.createDefaultParser(XppDriver.java:62)
        at com.thoughtworks.xstream.io.xml.XppDriver.createParser(XppDriver.java:68)
        at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
        at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:65)
        at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1303)

We switched from these dependencies (1.4.14)

		<dependency>
			<groupId>com.thoughtworks.xstream</groupId>
			<artifactId>xstream</artifactId>
			<version>1.4.14</version>
		</dependency>
		<dependency>
			<groupId>org.apache.servicemix.bundles</groupId>
			<artifactId>org.apache.servicemix.bundles.xpp3</artifactId>
			<version>1.1.4c_5</version>
		</dependency>

to these (1.4.16)

		<dependency>
			<groupId>com.thoughtworks.xstream</groupId>
			<artifactId>xstream</artifactId>
			<version>1.4.16</version>
		</dependency>
		<dependency>
			<groupId>io.github.x-stream</groupId>
			<artifactId>mxparser</artifactId>
			<version>1.2.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.servicemix.bundles</groupId>
			<artifactId>org.apache.servicemix.bundles.xmlpull</artifactId>
			<version>1.1.3.1_2</version>
		</dependency>

(the apache-servicemix-bundles are the osgi-fied version of the regular ones, just adding import/export stuff to the manifest)

We also checked the import/export sections of the bundles for possible problems but we couldn't find anything. We also tried different versions of the xmlpull dependency, also without any luck.

Do you have any idea/advice why this does not work?

@joehni
Copy link
Member

joehni commented Apr 24, 2021

I am no OSGi expert, all I know is, that I've missed to declare the MXParser as optional OSGI dependency. The xpp3_min also contains parts of xmlpull, therefore it might not affect the OSGI classloader.

Since XmlPull uses some kind of SPI (Service Provider Interface) to locate available XmlPull parsers, you might be affected by the problems described in this article. But be aware, that XmlPull is old and it's SPI implementation predates the Java ServiceLoader and does not follow the specification in all points. However, all of this would have to be done in the MXParser project.

XStream actually contains an own (user contributed) test module for OSGi, but I had to disable it because it breaks the release and does not run in Java 16, see #159. Any help is welcome.

What you can do instead for now: Use the MXParserDriver directly as ctor argument for XStream.

@joehni joehni self-assigned this Apr 24, 2021
@joehni
Copy link
Member

joehni commented May 14, 2021

MXParser is optional in 1.4.17 and the ITs for OSGi pass at least Java 8.

@joehni joehni closed this as completed May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants