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?
JAX-RS is a standard defined in Java Specification Request 311 (JSR-311) and Jersey / RESTEasy are implementations of it.
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.
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.
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.
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
META-INF/services/javax.ws.rs.client.ClientBuilder
javax.ws.rs.client.ClientBuilder
into ${java.home}/lib/jaxrs.properties
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With