[jitsi-dev] REST client inside of Jitsi


#1

Hi all,

I need to teach Jitsi to talk to a REST service. The service is created
using RESTeasy and comprises from 3 modules: statistics-service,
statistics-client and statistics-common. Service is simply deployed in the
application container, client knows how to talk to the service and is
delivered as a JAR and common JAR contains some DTOs that have to be shared
between the former two modules. I am currently struggling to get the client
working inside of the Jitsi's OSGi context. The errors I get are very
weird, like:

[java] java.lang.RuntimeException: java.lang.ClassCastException:
org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor cannot
be cast to org.jboss.resteasy.client.ClientExecutor

where I know that ApacheHttpClient4Executor implements the ClientExecutor
interface.

Or even
[java] java.lang.LinkageError: ClassCastException: attempting to
castjar:file:/D:/Development/Eclipses/eclipse_4.2_j2ee_x64/workspace_com/Communicator/lib/installer-exclude/jaxrs-api-2.3.2.Final.jar!/javax/ws/rs/ext/RuntimeDelegate.classtobundle://78.0:1/javax/ws/rs/ext/RuntimeDelegate.class

when I try to use the client in a bit different way. As I understand they
have something to do with the OSGi's classloader messing with the RESTeasy
initialization. Unfortunately I am new to OSGi and need help in
understanding what is the right way to integrate RESTeasy (or Jersey) into
Jitsi.

What I have done so far is copying the RESTeasy (together with its
dependencies) as well as my statistics-common and statistic-client jars
into lib/install-exclude folder and adding the following to the
bundle-swing-ui ant task (bundle where I need to use RESTeasy):

<zipfileset
src="lib/installer-exclude/statistics-service-client-0.1.0.3-SNAPSHOT.jar"
prefix=""/>
<zipfileset src="lib/installer-exclude/statistics-common-0.1.0.3.jar"
prefix=""/>
<zipfileset src="lib/installer-exclude/jsr250-api-1.0.jar" prefix=""/>
<zipfileset src="lib/installer-exclude/jaxrs-api-2.3.2.Final.jar"
prefix=""/>
....
<zipfileset src="lib/installer-exclude/resteasy-jaxrs-2.3.2.Final.jar"
prefix=""/>

What should I do instead or in addition to this in order to get it working?

Regards,
Alexander Fedulov


#2

Hey Alexander,

Hi all,

I need to teach Jitsi to talk to a REST service. The service is created
using RESTeasy and comprises from 3 modules: statistics-service,
statistics-client and statistics-common. Service is simply deployed in
the application container, client knows how to talk to the service and
is delivered as a JAR and common JAR contains some DTOs that have to be
shared between the former two modules. I am currently struggling to get
the client working inside of the Jitsi's OSGi context. The errors I get
are very weird, like:

[java] java.lang.RuntimeException: java.lang.ClassCastException:
org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor
cannot be cast to org.jboss.resteasy.client.ClientExecutor

We ship apache's HTTP client within Jitsi. Could this be causing the
conflict?

where I know that ApacheHttpClient4Executor implements
the ClientExecutor interface.

Or even
[java] java.lang.LinkageError: ClassCastException: attempting to
castjar:file:/D:/Development/Eclipses/eclipse_4.2_j2ee_x64/workspace_com/Communicator/lib/installer-exclude/jaxrs-api-2.3.2.Final.jar!/javax/ws/rs/ext/RuntimeDelegate.classtobundle://78.0:1/javax/ws/rs/ext/RuntimeDelegate.class

when I try to use the client in a bit different way. As I understand
they have something to do with the OSGi's classloader messing with the
RESTeasy initialization. Unfortunately I am new to OSGi and need help in
understanding what is the right way to integrate RESTeasy (or Jersey)
into Jitsi.

What I have done so far is copying the RESTeasy (together with its
dependencies) as well as my statistics-common and statistic-client jars
into lib/install-exclude folder and adding the following to the
bundle-swing-ui ant task (bundle where I need to use RESTeasy):

<zipfileset
src="lib/installer-exclude/statistics-service-client-0.1.0.3-SNAPSHOT.jar"
prefix=""/>
<zipfileset src="lib/installer-exclude/statistics-common-0.1.0.3.jar"
prefix=""/>
<zipfileset src="lib/installer-exclude/jsr250-api-1.0.jar" prefix=""/>
<zipfileset src="lib/installer-exclude/jaxrs-api-2.3.2.Final.jar"
prefix=""/>
....
<zipfileset src="lib/installer-exclude/resteasy-jaxrs-2.3.2.Final.jar"
prefix=""/>

What should I do instead or in addition to this in order to get it working?

You have to make sure that whatever classes you are using are made
available as either system packages, part of the bundle itself, or by
being exported from another bundle (and imported by yours).

Hope this helps,
Emil

···

On 31.08.12, 18:04, Alexander Fedulov wrote:


#3

Hi Emil,

Presumably the problem is caused by the fact that RESTeasy uses
getSystemClassloader function during it's initialization phase. Apparently
this violates the constraints, imposed by the OSGi framework. Here is an
extended discussion:
http://stackoverflow.com/questions/12249407/rest-client-inside-of-osgi-application
(click
below the question post to see all comments there)

Regards,
Alex

···

2012/9/8 Emil Ivov <emcho@jitsi.org>

Hey Alexander,

On 31.08.12, 18:04, Alexander Fedulov wrote:
> Hi all,
>
> I need to teach Jitsi to talk to a REST service. The service is created
> using RESTeasy and comprises from 3 modules: statistics-service,
> statistics-client and statistics-common. Service is simply deployed in
> the application container, client knows how to talk to the service and
> is delivered as a JAR and common JAR contains some DTOs that have to be
> shared between the former two modules. I am currently struggling to get
> the client working inside of the Jitsi's OSGi context. The errors I get
> are very weird, like:
>
> [java] java.lang.RuntimeException: java.lang.ClassCastException:
> org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor
> cannot be cast to org.jboss.resteasy.client.ClientExecutor

We ship apache's HTTP client within Jitsi. Could this be causing the
conflict?

> where I know that ApacheHttpClient4Executor implements
> the ClientExecutor interface.
>
> Or even
> [java] java.lang.LinkageError: ClassCastException: attempting to
>
castjar:file:/D:/Development/Eclipses/eclipse_4.2_j2ee_x64/workspace_com/Communicator/lib/installer-exclude/jaxrs-api-2.3.2.Final.jar!/javax/ws/rs/ext/RuntimeDelegate.classtobundle://78.0:1/javax/ws/rs/ext/RuntimeDelegate.class
>
> when I try to use the client in a bit different way. As I understand
> they have something to do with the OSGi's classloader messing with the
> RESTeasy initialization. Unfortunately I am new to OSGi and need help in
> understanding what is the right way to integrate RESTeasy (or Jersey)
> into Jitsi.
>
> What I have done so far is copying the RESTeasy (together with its
> dependencies) as well as my statistics-common and statistic-client jars
> into lib/install-exclude folder and adding the following to the
> bundle-swing-ui ant task (bundle where I need to use RESTeasy):
>
> <zipfileset
>
src="lib/installer-exclude/statistics-service-client-0.1.0.3-SNAPSHOT.jar"
> prefix=""/>
> <zipfileset src="lib/installer-exclude/statistics-common-0.1.0.3.jar"
> prefix=""/>
> <zipfileset src="lib/installer-exclude/jsr250-api-1.0.jar" prefix=""/>
> <zipfileset src="lib/installer-exclude/jaxrs-api-2.3.2.Final.jar"
> prefix=""/>
> ....
> <zipfileset src="lib/installer-exclude/resteasy-jaxrs-2.3.2.Final.jar"
> prefix=""/>
>
> What should I do instead or in addition to this in order to get it
working?

You have to make sure that whatever classes you are using are made
available as either system packages, part of the bundle itself, or by
being exported from another bundle (and imported by yours).

Hope this helps,
Emil