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

camel-karaf 4.8.2: broken JAXBContext #595

Open
ivan-ra opened this issue Feb 24, 2025 · 6 comments
Open

camel-karaf 4.8.2: broken JAXBContext #595

ivan-ra opened this issue Feb 24, 2025 · 6 comments
Assignees

Comments

@ivan-ra
Copy link

ivan-ra commented Feb 24, 2025

this code causes ClassNotFoundException (org.glassfish.jaxb.runtime.v2.ContextFactory not found) for routes deployed on karaf environment (works well in standalone routes):

import jakarta.xml.bind.JAXBContext;
...
JAXBContext ctx = JAXBContext.newInstance(ArrayList.class);

because camel-karaf has 2 incompatible features jaxb-runtime, and loads only 3.0.2 jaxb bundles:

    <feature name="jaxb-runtime" version="3.0.2">
        <feature version="[3,4)">jakarta-xml-bind</feature>
        <bundle dependency="true">mvn:com.sun.xml.bind/jaxb-core/3.0.2</bundle>
        <bundle dependency="true">mvn:com.sun.xml.bind/jaxb-impl/3.0.2</bundle>
        <bundle dependency="true">mvn:com.sun.xml.bind/jaxb-osgi/3.0.2</bundle>
    </feature>
    <feature name="jaxb-runtime" version="4.0.5">
        <feature version="[4,5)">jakarta-xml-bind</feature>
        <bundle dependency="true">mvn:com.sun.istack/istack-commons-runtime/4.1.2</bundle>
        <bundle dependency="true">mvn:org.glassfish.jaxb/jaxb-core/4.0.5</bundle>
        <bundle dependency="true">mvn:org.glassfish.jaxb/jaxb-runtime/4.0.5</bundle>
        <bundle>mvn:org.glassfish.hk2/osgi-resource-locator/2.5.0-b42</bundle>
    </feature>
karaf@root()> feature:list|grep jaxb-runtime
jaxb-runtime                             | 3.0.2            |          | Uninstalled | camel-4.8.2                       |
jaxb-runtime                             | 4.0.5            |          | Started     | camel-4.8.2                       |

and loads only packages v 3.0.2:

karaf@root()> list|grep JAXB
113 | Active |  50 | 4.8.2              | Apache Camel :: Karaf :: Core :: XML JAXB
131 | Active |  80 | 3.0.2              | JAXB OSGI
karaf@root()> package:exports -p org.glassfish.jaxb.runtime.v2
Package Name                                       | Version | ID  | Bundle Name
---------------------------------------------------+---------+-----+---------------------------
org.glassfish.jaxb.runtime.v2.model.annotation     | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2.model.impl           | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2.model.runtime        | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2.runtime.output       | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2.runtime.property     | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2.runtime.reflect.opt  | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2.runtime.reflect      | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2.runtime.unmarshaller | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2.runtime              | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2.schemagen.xmlschema  | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2.schemagen            | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2.util                 | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi
org.glassfish.jaxb.runtime.v2                      | 3.0.2   | 131 | com.sun.xml.bind.jaxb-osgi

I have tried to change 4.0.5 bundle dependency value to "false", but it does not work because camel-blueprint requires jaxb bundles version 3.

@ivan-ra
Copy link
Author

ivan-ra commented Feb 24, 2025

I think camel-blueprint needs to exclude jaxb3 dependencies (com.sun.xml.fastinfoset.* packages) and use jaxb v4*

@ivan-ra
Copy link
Author

ivan-ra commented Feb 24, 2025

please remove unused imports from camel-blueprint manifest!
I removed this packages: com.sun.xml.* , org.jvnet.* from manifest, changed axb-runtime feature (dependency="false"), and now all works well (except camel-cxf, I think there are some unused imports too)

    <feature name="jaxb-runtime" version="4.0.5">
        <feature version="[4,5)">jakarta-xml-bind</feature>
        <bundle dependency="true">mvn:com.sun.istack/istack-commons-runtime/4.1.2</bundle>
        <bundle dependency="false">mvn:org.glassfish.jaxb/jaxb-core/4.0.5</bundle>
        <bundle dependency="false">mvn:org.glassfish.jaxb/jaxb-runtime/4.0.5</bundle>
        <bundle>mvn:org.glassfish.hk2/osgi-resource-locator/2.5.0-b42</bundle>
    </feature>

@essobedo
Copy link
Contributor

Hi, thx for the ticket. If you don't mind, let's focus first on the problem before focusing on the solution knowing that the 2 versions of the feature were proposed for good reasons. So please provide steps to reproduce your issue with a simple camel route and/or propose a PR with a test case.

@jbonofre jbonofre self-assigned this Feb 24, 2025
@jbonofre
Copy link
Member

Thanks for the report. Do you have a simple reproducer ?

@ivan-ra
Copy link
Author

ivan-ra commented Feb 24, 2025

in any route/bundle just add this code and try to install it:

JAXBContext ctx = JAXBContext.newInstance(ArrayList.class); //any class here

(bundle should use camel feature)

More precisely, route/bundle must use camel-blueprint (this requires jaxb v3) and contain java code like this (this requires jaxb v4):

JAXBContext ctx = JAXBContext.newInstance();

@ivan-ra
Copy link
Author

ivan-ra commented Feb 24, 2025

for me works this solution:

  • exclude unused imports from camel-blueprint manifest ( com.sun.xml.* , org.jvnet.* )
  • change both jaxb-runtime features like this
    <feature name="jaxb-runtime" version="3.0.2">
        <feature version="[3,4)">jakarta-xml-bind</feature>
        <bundle dependency="false">mvn:com.sun.xml.bind/jaxb-core/3.0.2</bundle>
        <bundle dependency="false">mvn:com.sun.xml.bind/jaxb-impl/3.0.2</bundle>
        <bundle dependency="false">mvn:com.sun.xml.bind/jaxb-osgi/3.0.2</bundle>
    </feature>
    <feature name="jaxb-runtime" version="4.0.5">
        <feature version="[4,5)">jakarta-xml-bind</feature>
        <bundle dependency="true">mvn:com.sun.istack/istack-commons-runtime/4.1.2</bundle>
        <bundle dependency="false">mvn:org.glassfish.jaxb/jaxb-core/4.0.5</bundle>
        <bundle dependency="false">mvn:org.glassfish.jaxb/jaxb-runtime/4.0.5</bundle>
        <bundle>mvn:org.glassfish.hk2/osgi-resource-locator/2.5.0-b42</bundle>
    </feature>

after this route works well and camel-cxf starts too

karaf@root()> feature:list|grep jaxb-runtime
jaxb-runtime                             | 3.0.2            |          | Started     | camel-4.8.2                       |
jaxb-runtime                             | 4.0.5            |          | Started     | camel-4.8.2                       |
karaf@root()> list|grep JAXB
110 | Active |  50 | 4.8.2              | Apache Camel :: Karaf :: Core :: XML JAXB
128 | Active |  80 | 3.0.2              | Old JAXB Core
129 | Active |  80 | 3.0.2              | Old JAXB Runtime
130 | Active |  80 | 3.0.2              | JAXB OSGI
308 | Active |  80 | 4.0.5              | JAXB Core
309 | Active |  80 | 4.0.5              | JAXB Runtime

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

3 participants