I'm working on a project which uses various client apps as maven dependencies to talk to different REST APIs.
But there's a problem when including a client which is implemented using Jersey 2.x and any other client which is using RESTEasy.
As soon as I add the dependency which is using RESTEasy I'll get errors like this:
Caused by: javax.ws.rs.ProcessingException: Unable to find a MessageBodyReader of content-type application/json and type class de.fhg.ipa.vfk.docker.dockerregistry.restclient.entity.SearchResult at org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:39) at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73) at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:50) at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:245) at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:179) at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:211) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:104) ... 4 more
or this:
Caused by: javax.ws.rs.ProcessingException: could not find writer for content-type application/tar type: java.io.FileInputStream at org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:138) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:117) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.writeRequestBody(ClientInvocation.java:341) at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.writeRequestBodyToOutputStream(ApacheHttpClient4Engine.java:558) at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.buildEntity(ApacheHttpClient4Engine.java:524) at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:423) at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:281) ... 7 more
Is is possible to use both libraries or configure maven somehow so that the app won't try to use the RESTEasy dependencies instead of the Jersey 2.x ones and vice versa?
Thanks
Daniel
You could try to use Maven profiles to activate either Jersey or RESTEasy, but you can't have two JAX-RS implementations in the same flat classpath at the same time.
If you have to use both implementations simultaneously in one application, you'll need classloader isolation provided by a module system like OSGi or JBoss Modules.
The best way to go might be to refactor your code to use only the JAX-RS 2.0 client API and to settle for either Jersey or RESTEasy for corner cases which require implementation-specific APIs.
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