我的 TomEE Plume 7.0.2 有问题。
我以这种方式创建了一个过滤器:
package com.gfp.rest.providers;
import java.io.IOException;
import javax.annotation.Priority;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.Provider;
@PreMatching
@Provider
@Priority(value = 1)
public class AuthenticationFilter implements ContainerRequestFilter
{
public AuthenticationFilter()
{
System.out.println("AuthenticationFilter.AuthenticationFilter()");
}
@Override
public void filter(ContainerRequestContext requestContext) throws IOException
{
System.out.println("AuthenticationFilter.filter()");
String token = requestContext.getHeaderString("token");
ResponseBuilder responseBuilder = null;
Response response = null;
// check if token is empty
if (token.isEmpty()) {
responseBuilder = Response.serverError();
response = responseBuilder.status(Status.UNAUTHORIZED).build();
requestContext.abortWith(response);
}
}
}
这是我的休息申请:
package com.gfp.rest;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("api/v1")
public class RestApplication extends Application
{
}
问题是:过滤器似乎没有被调用。我已经阅读了很多文档和许多其他帖子,但我找不到任何解决方案。有什么特别的东西我错过了吗?
非常感谢 !