Spring RestEasy 拦截器
Spring RestEasy interceptor
我有一个带有 resteasy-spring-3.0.19 和 jboss-jaxrs-api_2.0_spec-1.0.0.
的 Spring 启动应用程序
我想拦截所有其余的授权调用。
拦截器未被调用。另外,如何在拦截器中获取目标方法@Path注解值。
我需要在 Spring 启动应用程序中注册吗?
@Provider
public class AuthorizationtInterceptor implements ContainerRequestFilter{
/**
*
*/
public AuthorizationtInterceptor() {
// TODO Auto-generated constructor stub
}
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
String method = requestContext.getMethod();
UriInfo uriInfo = requestContext.getUriInfo();
// Need the target method @Path annotation value ....
}
}
目标休息 class,
@Named
@Singleton
@Path(ROOT_PATH)
public class WebController {
@GET
@Path(TEST_PATH)
@Produces(MediaType.APPLICATION_JSON)
public Response getUser(@Context final HttpServletRequest request) {
}
}
在一个post匹配的过滤器中(没有@PreMatching
annotation), you can use ResourceInfo
的过滤器获取匹配的资源class和资源方法。
注入ResourceInfo
in your filter using the @Context
注释:
@Context
private ResourceInfo resourceInfo;
然后获取资源class并提取@Path
注解:
Path path = resourceInfo.getResourceClass().getAnnotation(Path.class);
获取资源方法,使用:
Path path = resourceInfo.getResourceMethod().getAnnotation(Path.class);
根据您要实现的目标,您可以考虑将过滤器绑定到一组资源 classes 或方法,而不是为了授权目的比较 @Path
注释的值.在这个 .
中查看更多详细信息
根据您设置应用程序的方式,您可能需要在 Application
subclass 或 web.xml
部署描述符中注册过滤器。
我有一个带有 resteasy-spring-3.0.19 和 jboss-jaxrs-api_2.0_spec-1.0.0.
的 Spring 启动应用程序我想拦截所有其余的授权调用。
拦截器未被调用。另外,如何在拦截器中获取目标方法@Path注解值。
我需要在 Spring 启动应用程序中注册吗?
@Provider
public class AuthorizationtInterceptor implements ContainerRequestFilter{
/**
*
*/
public AuthorizationtInterceptor() {
// TODO Auto-generated constructor stub
}
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
String method = requestContext.getMethod();
UriInfo uriInfo = requestContext.getUriInfo();
// Need the target method @Path annotation value ....
}
}
目标休息 class,
@Named
@Singleton
@Path(ROOT_PATH)
public class WebController {
@GET
@Path(TEST_PATH)
@Produces(MediaType.APPLICATION_JSON)
public Response getUser(@Context final HttpServletRequest request) {
}
}
在一个post匹配的过滤器中(没有@PreMatching
annotation), you can use ResourceInfo
的过滤器获取匹配的资源class和资源方法。
注入ResourceInfo
in your filter using the @Context
注释:
@Context
private ResourceInfo resourceInfo;
然后获取资源class并提取@Path
注解:
Path path = resourceInfo.getResourceClass().getAnnotation(Path.class);
获取资源方法,使用:
Path path = resourceInfo.getResourceMethod().getAnnotation(Path.class);
根据您要实现的目标,您可以考虑将过滤器绑定到一组资源 classes 或方法,而不是为了授权目的比较 @Path
注释的值.在这个
根据您设置应用程序的方式,您可能需要在 Application
subclass 或 web.xml
部署描述符中注册过滤器。