Jaxb JAX-RS过滤器调用序列
我对JAX-RS过滤器的实现如下: 请求筛选器为:Jaxb JAX-RS过滤器调用序列,jaxb,jax-rs,marshalling,unmarshalling,Jaxb,Jax Rs,Marshalling,Unmarshalling,我对JAX-RS过滤器的实现如下: 请求筛选器为: public class AuthorizationRequestFilter implements ContainerRequestFilter { public static long entryTime; @Override public void filter(ContainerRequestContext requestContext)
public class AuthorizationRequestFilter implements ContainerRequestFilter {
public static long entryTime;
@Override
public void filter(ContainerRequestContext requestContext)
throws IOException {
/*some preprocessing before unmarshalling*/
}
}
响应过滤器为:-
公共类ResponseFilter实现ContainerResponseFilter{
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
if (!requestContext.getMethod().equalsIgnoreCase("Head")) {
/*Some processing after Marshalling*/
}
}
我的经纪人是:-
@POST
@Path("abc")
@Produces(MediaType.APPLICATION_XML)
public Response createABC(App app){
/*lines of code*/
return Response.status(Status.CRETED).entity(abc).build();
}
我的问题是在封送和解封后调用的过滤器,即在调用响应过滤器之前封送方法AuthorizationRequestFilter和abc之后创建的应用程序对象是否在解封前调用请求过滤器。这应该是显而易见的,因为您仍然可以访问实体输入流(意味着它还没有被读取)。您可以通过编写一个简单的
MessageBodyReader
来轻松测试这一点。在请求筛选器中设置一个任意头,然后您就可以从readersreadFrom
方法中提取相同的头
在编组之前将调用响应筛选器。同样,这可以通过编写一个简单的MessageBodyWriter
来轻松测试。在筛选器中设置一个任意头,您应该能够通过编写器的writeTo
方法访问它
如果要在封送处理后执行某些操作,可以使用,它将调用包装为编写器的封送处理方法
@Provider
public class SimpleIntercetor implements WriterInterceptor{
@Override
public void aroundWriteTo(WriterInterceptorContext context)
throws IOException, WebApplicationException {
// Processing before marshalling
context.proceed(); // marshal
// Processing after marshalling
}
}
一些资源: