Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAX-RS 2.0 change default implementation

Tags:

I'm trying to use RESTEasy as JAX-RS 2.0 client implementation. The problem is that I got runtime exception:

06-28 13:29:06.410: E/AndroidRuntime(5745): Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder 06-28 13:29:06.410: E/AndroidRuntime(5745):     at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:103) 

So the newBuilder() method is searching for JerseyClientBuilder if I understand it correct. How can I tell the system to use RESTEasy instead?

like image 973
Konstantin Milyutin Avatar asked Jun 28 '13 13:06

Konstantin Milyutin


People also ask

What are the implementations of JAX-RS?

JAX-RS is a standard defined in Java Specification Request 311 (JSR-311) and Jersey / RESTEasy are implementations of it.

Is a fully certified and portable implementation of the JAX-RS?

RESTEasy is a Java framework for developing RESTful Web Services. It is a fully certified and portable implementation of the JAX-RS 2.0 specification.

What is the difference between JAX-RS and Jersey?

JAX-RS is an specification (just a definition) and Jersey is a JAX-RS implementation. Jersey framework is more than the JAX-RS Reference Implementation. Jersey provides its own API that extend the JAX-RS toolkit with additional features and utilities to further simplify RESTful service and client development.

What is the latest version of JAX-RS?

JAX-RS Specification The latest version is JAX-RS 2.0 [JSR 339], which was released as part of the Java EE 7 platform. JAX-RS focuses on applying Java annotations to plain Java objects. JAX-RS has annotations to bind specific URI patterns and HTTP operations to specific methods of your Java class.


1 Answers

Well, JAX-RS relies on the Service Provider convention. On the first lines of the newBuilder method you can read:

 Object delegate = FactoryFinder.find(JAXRS_DEFAULT_CLIENT_BUILDER_PROPERTY,    JAXRS_DEFAULT_CLIENT_BUILDER);  

Where JAXRS_DEFAULT_CLIENT_BUILDER_PROPERTY is "javax.ws.rs.client.ClientBuilder"

In turn, FactoryFinder looks

  • first for the class name into META-INF/services/javax.ws.rs.client.ClientBuilder
  • then in the property javax.ws.rs.client.ClientBuilder into ${java.home}/lib/jaxrs.properties
  • finally into the System property javax.ws.rs.client.ClientBuilder.

So, to use RESTEasy, you should create a file

META-INF/services/javax.ws.rs.client.ClientBuilder 

with the text:

org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder 

which is the class name of the RESTEasy ClientBuilder

like image 189
Carlo Pellegrini Avatar answered Sep 27 '22 18:09

Carlo Pellegrini