REST client inside OSGi application

I need to integrate a REST client into an existing OSGi application implemented using Apache Felix. The REST service is based on the implementation of RESTeasy (version 2.3.2.Final) JAX-RS. I created a separate package with client dependencies, exported the necessary RESTeasy packages and imported them into the package where the client is used, but, unfortunately, I cannot get it to work inside the OSGi context.

I tried two different approaches. First use a generic client request:

ClientRequest request = new ClientRequest(MyService.URL_TEST+"/stats");
request.body(javax.ws.rs.core.MediaType.APPLICATION_XML, stats);
ClientResponse<String> response = request.post(String.class);

The error I get in this case is rather strange:

[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 am sure that ApacheHttpClient4Executor implements the ClientExecutor interface.

When I try to use my own REST client shell in RESTeasy, for example:

MyService myService = MyServiceClient.getInstance();
myService.saveStatistics(stats);

I get another exception:

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

, LinkageError, , , RESTeasy RuntimeDelegate, , , , OSGi. , java.lang.ClassCastException .

RESTeasy OSGi?

PS: RESTeasy, OSGi: java.lang.LinkageError: ClassCastException

Update: , restclient: -1.1.jar commons-codec-1.2.jar commons-httpclient-3.1.jar commons-io-2.1.jar commons-logging-1.0.4.jar flexjson-2.1.jar httpclient-4.1.2.jar httpcore-4.1.2.jar javassist-3.12.1.GA.jar jaxb-api-2.2.3.jar jaxb-impl-2.2.4.jar jaxrs-api-2.3.2.Final.jar jcip-annotations-1.0.jar jettison -1.3.1.jar jsr250-api-1.0.jar junit-4.10.jar log4j-1.2.14.jar resteasy-jaxb-provider-2.3.2.Final.jar resteasy-jaxrs-2.3.2.Final.jar resteasy -jettison-provider-2.3.2.Final.jar scannotation-1.0.3.jar slf4j-api-1.6.4.jar slf4j-log4j12-1.6.4.jar myservice-common-0.1.0.3.jar my-service- client-0.1.0.3-SNAPSHOT.jar stax-api-1.0-2.jar xmlpull-1.1.3.1.jar xpp3_min-1.1.4c.jar xstream-1.4.2.jar

restclient: javax.ws.rs, javax.ws.rs.ext, javax.ws.rs.core, org.jboss.resteasy.client, org.jboss.resteasy.client.cache, org.jboss.resteasy.client.extractors, org.jboss.resteasy.client.marshallers, org.jboss.resteasy.client.core.executors, javax.xml.bind.annotation, org.jboss.resteasy.plugins.providers, org.jboss.resteasy.plugins.providers.jaxb, org.jboss.resteasy.spi

+5
4
0

( , - OSGi, RESTeasy 3.0.16)

OSGify , , , Apache Ops4j Pax Tipi project.

Maven ( POM ), GAV- - Tipi org.apache.ops4j.pax.tipi , , OSGi.

Tipi, ( ..) / OSGi ( maven-bundle-plugin).

, .

, , , , - (, - ).

, RESTeasy, , , ​​ ( , :

'.' Import-Package.

maven-bundle-plugin 3.0.1 ( ):

[ERROR] Bundle org.ops4j.pax.tipi: org.ops4j.pax.tipi.resteasy-jaxrs: bundle: 3.0.16.Final.1: : [ERROR] (),

, , Tipi POM 1.4.0, ...

0

RESTEasy ? jersey OSGi, , .

0

RESTeasy. .

, JAX-RS .
LinkageError:

[java] java.lang.LinkageError: ClassCastException: jar: file: /D: /Development/Eclipses/eclipse_4.2_j2ee_x64/lib/jaxrs-api-2.3.2.Final.jar!/javax/ws/rs/ext/RuntimeDelegate.class ://78.0: 1/javax/ws/rs/ext/RuntimeDelegate.class

.. :

D: /Development/Eclipses/eclipse_4.2_j2ee_x64/lib/jaxrs-api-2.3.2.Final.jar

OSGI.

RuntimeDelegate, RuntimeDelegate (. Javax.ws.rs.ext.FactoryFinder).

, .

:

  • remove jaxrs-api-2.3.2.Final.jar from the system class path
  • Before loading JAX-RS, install the stream context class loader on the one in your package.
    FactoryFinder will use this to load the RuntimeDelegate.
    In order not to pollute your code with Thread.currentThread () calls. SetContextClassLoader (myBundleClassLoader), you can wrap your JAX-RS client using a proxy. for example, see the Thread Context Class Loader section at https://puredanger.imtqy.com/tech.puredanger.com/2007/06/15/classloaders/
0
source

All Articles