是否可以使用Jersey 2.x和RESTEasy依赖项的项目? [英] Is a project with Jersey 2.x AND RESTEasy dependencies possible?

查看:134
本文介绍了是否可以使用Jersey 2.x和RESTEasy依赖项的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目,该项目使用各种客户端应用程序作为maven依赖项来与不同的REST API进行通信.

I'm working on a project which uses various client apps as maven dependencies to talk to different REST APIs.

但是,当包含使用Jersey 2.x实现的客户端和使用RESTEasy的任何其他客户端时,会出现问题.

But there's a problem when including a client which is implemented using Jersey 2.x and any other client which is using RESTEasy.

一旦我添加了使用RESTEasy的依赖项,我将得到如下错误:

As soon as I add the dependency which is using RESTEasy I'll get errors like this:

原因:javax.ws.rs.ProcessingException:无法找到 内容类型为application/json和类型类的MessageBodyReader de.fhg.ipa.vfk.docker.dockerregistry.restclient.entity.SearchResult 在 org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:39) 在 org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73) 在 org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:50) 在 org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:245) 在 org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:179) 在 org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:211) 在 org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:104) ...还有4个

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

或者这个:

由以下原因引起:javax.ws.rs.ProcessingException:找不到以下内容的编写器: 内容类型应用程序/tar类型:java.io.FileInputStream,位于 org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40) 在 org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:138) 在 org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:117) 在 org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.writeRequestBody(ClientInvocation.java:341) 在 org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.writeRequestBodyToOutputStream(ApacheHttpClient4Engine.java:558) 在 org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.buildEntity(ApacheHttpClient4Engine.java:524) 在 org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:423) 在 org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:281) ...还有7个

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

是否可以同时使用这两个库或配置Maven,以使该应用程序不会尝试使用RESTEasy依赖项而不是Jersey 2.x依赖项,反之亦然?

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?

谢谢

丹尼尔

推荐答案

您可以尝试使用Maven配置文件来激活Jersey或RESTEasy,但是您不能在同一平面类路径中的同一位置上同时使用两个JAX-RS实现时间.

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.

如果必须在一个应用程序中同时使用这两种实现,则需要由OSGi或JBoss Modules等模块系统提供的类加载器隔离.

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.

最好的方法可能是将代码重构为仅使用JAX-RS 2.0客户端API,并为出现以下情况的特殊情况解决 Jersey RESTEasy需要特定于实现的API.

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.

这篇关于是否可以使用Jersey 2.x和RESTEasy依赖项的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆