简体   繁体   English

球衣响应过滤器

[英]Jersey Response Filter

I am trying to create a jersey filter that filters all the server's responses of 500 error. 我试图创建一个筛选器,筛选所有服务器的500错误响应。

But I dont know much about filters so I just started some code but I have no idea how to continue...can anybody help me with this issue. 但是我对过滤器了解不多,所以我只是开始一些代码,但是我不知道如何继续...有人可以帮我解决这个问题。

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
}

and my web.xml looks like this 我的web.xml看起来像这样

<servlet>
<servlet-name>Authenticator</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
    <param-name>com.sun.jersey.spi.container.ResourceFilters</param-name>
    <param-value>com.query.displayer.Filters</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Authenticator</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

You're mixing 2 versions of Jersey in your application: Implementation of a ContainerRequestFilter from JAX-RS 2.0 (Jersey 2) and descriptor configuration (web.xml) for Jersey 1 (see prefix com.sun.jersey ). 您在应用程序中混合了两个版本的Jersey:JAX-RS 2.0(Jersey 2)的ContainerRequestFilter的实现和Jersey 1的描述符配置(web.xml)(请参阅前缀com.sun.jersey )。 The following article explains how to register providers in Jersey 2: 以下文章介绍了如何在Jersey 2中注册提供商:

It seems that you we're using ResourceFilterFactory in Jersey 1. This concept doesn't exist in Jersey 2 but there is a new concept (directly in JAX-RS 2.0) how to do that: 似乎您在Jersey 1中使用了ResourceFilterFactory 。这个概念在Jersey 2中不存在,但是有一个新概念(直接在JAX-RS 2.0中)如何实现:

When you are using Jersey-2 you must use the follow configuration to register your filter into the web.xml 使用Jersey-2时,必须使用以下配置将过滤器注册到web.xml中

jersey.config.server.provider.classnames jersey.config.server.provider.classnames

instead of 代替

com.sun.jersey.spi.container.ContainerRequestFilters (jersey-1x) com.sun.jersey.spi.container.ContainerRequestFilters (jersey-1x)

 <!-- This is the config needed -->
<servlet>    
      //...         
     <init-param>
         <param-name>jersey.config.server.provider.classnames</param-name>
         <param-value>com.your_package_path.yourClassFilter</param-value>
     </init-param>
      //...
</servlet>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM