You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "Justin Bertram (Jira)" <ji...@apache.org> on 2019/10/31 16:23:00 UTC

[jira] [Updated] (ARTEMIS-2536) Using artemis-server-osgi can not load JsonLoader.loadProvider()

     [ https://issues.apache.org/jira/browse/ARTEMIS-2536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Justin Bertram updated ARTEMIS-2536:
------------------------------------
    Description: 
I have an OSGi project set up. I am using the {{artemis-server-osgi}} bundle. Additionally I have added:
* {{javax.json.javax.json-api}}
* {{org.apache.johnzon.johnzon-core}}

While setting up a cluster environment I get the following exception:
{noformat}
Caused by: javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found 
  at javax.json.spi.JsonProvider.provider(JsonProvider.java:99) 
  at org.apache.activemq.artemis.utils.JsonLoader$1.run(JsonLoader.java:59) 
  at org.apache.activemq.artemis.utils.JsonLoader$1.run(JsonLoader.java:53) 
  at java.security.AccessController.doPrivileged(Native Method) 
  at org.apache.activemq.artemis.utils.JsonLoader.loadProvider(JsonLoader.java:53) 
  at org.apache.activemq.artemis.utils.JsonLoader.<clinit>(JsonLoader.java:49) ... 154 more
Caused by: java.lang.ClassNotFoundException: org.glassfish.json.JsonProviderImpl cannot be found by javax.json-api_1.1.4 
  at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484) 
  at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395) 
  at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387) 
  at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150) 
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) 
  at java.lang.Class.forName(Class.java:264) at javax.json.spi.JsonProvider.provider(JsonProvider.java:96) ... 159 more
{noformat}

it can easily be reproduced simple by calling {{JsonLoader.createArrayBuilder()}} in a non cluster setup. 

This is mainly due to this code in {{JsonLoader}}:
{code:java}
Thread.currentThread().setContextClassLoader(JsonLoader.class.getClassLoader());
{code}
The OSGi loads the Artemis and the Johnzon bundles separately. When {{JsonLoader.class.getClassLoader()}} is called Johnzon is not in this particular classloader. 

Something similar we get when we need to load protocol manager factory but there is an alternative to set it manually:
{code:java}
activeMQServer.addProtocolManagerFactory(new MQTTProtocolManagerFactory());
{code}

  was:
I have an osgi project set up. I am using the artemis-server-osgi bundle.

additionally i have added:

javax.json.javax.json-api

org.apache.johnzon.johnzon-core

While setting up a cluster environment i get the following exception:
{code:java}
// code placeholder

Caused by: javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not foundCaused by: javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found at javax.json.spi.JsonProvider.provider(JsonProvider.java:99) at org.apache.activemq.artemis.utils.JsonLoader$1.run(JsonLoader.java:59) at org.apache.activemq.artemis.utils.JsonLoader$1.run(JsonLoader.java:53) at java.security.AccessController.doPrivileged(Native Method) at org.apache.activemq.artemis.utils.JsonLoader.loadProvider(JsonLoader.java:53) at org.apache.activemq.artemis.utils.JsonLoader.<clinit>(JsonLoader.java:49) ... 154 moreCaused by: java.lang.ClassNotFoundException: org.glassfish.json.JsonProviderImpl cannot be found by javax.json-api_1.1.4 at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387) at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at javax.json.spi.JsonProvider.provider(JsonProvider.java:96) ... 159 more

{code}
 

it can easily be reproduced simple by calling JsonLoader.createArrayBuilder(); in a non cluster setup.

 

This is mainly due to 

Thread.currentThread().setContextClassLoader(JsonLoader.class.getClassLoader());

inside the JsonLoader, as the osgi loads the Artemis bundle and the Johnson separately.

when JsonLoader.class.getClassLoader() is called the Johnson is not in this particular classloader.

 

Something similar we get when we need to load protocol manager factory but there is an alternative to set it manually:

activeMQServer.addProtocolManagerFactory(new MQTTProtocolManagerFactory());


> Using artemis-server-osgi can not load JsonLoader.loadProvider()
> ----------------------------------------------------------------
>
>                 Key: ARTEMIS-2536
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-2536
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>            Reporter: Vilian Venkov
>            Priority: Major
>
> I have an OSGi project set up. I am using the {{artemis-server-osgi}} bundle. Additionally I have added:
> * {{javax.json.javax.json-api}}
> * {{org.apache.johnzon.johnzon-core}}
> While setting up a cluster environment I get the following exception:
> {noformat}
> Caused by: javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found 
>   at javax.json.spi.JsonProvider.provider(JsonProvider.java:99) 
>   at org.apache.activemq.artemis.utils.JsonLoader$1.run(JsonLoader.java:59) 
>   at org.apache.activemq.artemis.utils.JsonLoader$1.run(JsonLoader.java:53) 
>   at java.security.AccessController.doPrivileged(Native Method) 
>   at org.apache.activemq.artemis.utils.JsonLoader.loadProvider(JsonLoader.java:53) 
>   at org.apache.activemq.artemis.utils.JsonLoader.<clinit>(JsonLoader.java:49) ... 154 more
> Caused by: java.lang.ClassNotFoundException: org.glassfish.json.JsonProviderImpl cannot be found by javax.json-api_1.1.4 
>   at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484) 
>   at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395) 
>   at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387) 
>   at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150) 
>   at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) 
>   at java.lang.Class.forName(Class.java:264) at javax.json.spi.JsonProvider.provider(JsonProvider.java:96) ... 159 more
> {noformat}
> it can easily be reproduced simple by calling {{JsonLoader.createArrayBuilder()}} in a non cluster setup. 
> This is mainly due to this code in {{JsonLoader}}:
> {code:java}
> Thread.currentThread().setContextClassLoader(JsonLoader.class.getClassLoader());
> {code}
> The OSGi loads the Artemis and the Johnzon bundles separately. When {{JsonLoader.class.getClassLoader()}} is called Johnzon is not in this particular classloader. 
> Something similar we get when we need to load protocol manager factory but there is an alternative to set it manually:
> {code:java}
> activeMQServer.addProtocolManagerFactory(new MQTTProtocolManagerFactory());
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)