2014-10-27 104 views
0

我们必须在我们的项目中同时支持JBoss AS 7.1.3和Wildfly。 为了提供这种可能性,我们有两个具有不同依赖关系和版本的maven配置文件,这些配置文件在AS中提供。 一切工作正常,但最近我们遇到了问题在JBoss,与Resteasy连接。Resteasy - 支持JBoss AS 7和Wildfly

我们的REST服务注释为@Consumes(MediaType.APPLICATION_JSON)

但是,如果我们例如发出PUT请求没有Content-Type头字段集,我们得到404状态的响应。 我们期望415 Unsupported Media Type的响应,所以我们编写拦截器来检查MediaType并且如果没有设置则丢弃UnsupportedMediaTypeException

在Wild this中这个问题是固定的,所以我们不需要这个拦截器。

主要问题是Resteasy主要版本与Wildfly不一样 - 3.0.8.Final(在JBoss 7.1.3中它是2.3.3.Final)并且有一些不兼容的更改。

E.g.我们的拦截器实现了org.jboss.resteasy.spi.interception.PreProcessInterceptor,它在Resteasy 3.0.8中被标记为Deprecated,并且自Resteasy 2.3.3以来它的签名是preProcess方法已经改变。

PreProcessInterceptor.preProcess为2.3.3签名:

ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure, WebApplicationException; 

和3.0.8:

ServerResponse preProcess(HttpRequest request, ResourceMethodInvoker method) throws Failure, WebApplicationException; 

因此,我们的拦截器甚至不会编译Wildfly。

现在的问题是:如何解决这个问题,以便为JBoss AS 7.1.3/Wildfly编译代码并避免在Wildfly中使用此拦截器?

通过注解注册拦截器:

@Provider 
@ServerInterceptor 
public class MyInterceptor implements PreProcessInterceptor 

P.S.我们有互操作模块来提供这些平台中不同的类,例如有不同的软件包名称。

+0

不幸的是升级Resteasy不是一种选择,因为我们没有直接访问客户的系统,而且不是唯一一个使用Resteasy的应用程序。 – dds 2014-10-28 03:46:50

回答

0

最后我想出了以下解决方案:

  1. 创建我自己的接口 public interface MyPreProcessInterceptor extends PreProcessInterceptor { //method signature for Restesy 2.3.3 ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure, WebApplicationException;

    //method signature for Restesy 3.0.8 
    ServerResponse preProcess(HttpRequest request, ResourceMethodInvoker method) 
         throws Failure, WebApplicationException; 
    

    }

  2. 在互操作创建ResourceMethod类Wildfly

  3. 在互操作为创建ResourceMethodInvoker类JBoss AS 7.1.3
  4. 修改MyInterceptor来实现n EW接口MyPreProcessInterceptor
  5. 只在Restesy 2.3.3的方法实现了必要的逻辑,只要return null;为3.0.8

所以现在它编译现在对于这两个平台的作品。