访问PostProcessInterceptor中的资源类字段?

时间:2013-08-27 17:07:41

标签: java java-ee dependency-injection jax-rs resteasy

我有一个资源类

@Path("secure")
@RequestScoped
// @SecurityChecked
public class SecureResource {

    @Context
    private HttpServletRequest request;

    @GET
    @SecurityChecked
    public Response getUser() {
        return Response.ok("authenticated successfully!").build();
    }

    @POST
    public Response login(@FormParam("user") @Nonnull final String user,
                          @FormParam("password") @Nonnull final String password) {
        final String authToken = TokenUtils.createToken(user);
        return Response.ok().header(AUTH_TOKEN, authToken).build();
    }

    @PUT
    public Response updateUser() {
        return Response.ok("updating user").build();
    }
}

我有PostProcessInterceptor我希望访问标题类的request

@Interceptor
@Provider
@ServerInterceptor
@SecurityChecked
public class SecurityCheckInterceptor implements PostProcessInterceptor {
    private static final Pattern PATTERN = Pattern.compile(":");
    private static final Logger LOGGER = LoggerFactory.getLogger(SecurityCheckInterceptor.class);
    @Override
    public void postProcess(final ServerResponse response) {
        // access the Resource class request object

    }
}

我不知道如何在此处访问请求对象

请帮忙

谢谢

1 个答案:

答案 0 :(得分:0)

为什么要在PostProcessInterceptor中访问请求?你确定你不能使用

public static class MyInterceptor implements PreProcessInterceptor{
...
@Override
public ServerResponse preProcess(HttpRequest request, ResourceMethod method){...}
}

这里吗?