Java 请求调度程序执行命令
我正在尝试使用dropwizard实现一个RequestDispatcher,它应该在帖子中查看主体中的实体并计算某些统计数据 因此,我实现了一个Java 请求调度程序执行命令,java,jersey,jetty,dropwizard,Java,Jersey,Jetty,Dropwizard,我正在尝试使用dropwizard实现一个RequestDispatcher,它应该在帖子中查看主体中的实体并计算某些统计数据 因此,我实现了一个ResourceMethodDispatchAdapter和ResourceMethodDispatchProvider,并且我能够成功地注入和调用我的RequestDispatcher private static class InspectRequestDispatcher implements RequestDispatcher {
ResourceMethodDispatchAdapter
和ResourceMethodDispatchProvider
,并且我能够成功地注入和调用我的RequestDispatcher
private static class InspectRequestDispatcher implements RequestDispatcher {
private final RequestDispatcher dispatcher;
private InspectRequestDispatcher(RequestDispatcher dispatcher) {
this.dispatcher = dispatcher;
}
@Override
public void dispatch(final Object resource, final HttpContext context) {
final Saying day = context.getRequest().getEntity(Saying.class);
dispatcher.dispatch(resource, context); // this throws ConstraintViolationException
}
}
上面的代码抛出异常,因为我已经读取了主体(这是可以理解的),我可以重置流,但是我将为读取主体两次支付罚款
注入参数后是否可以拦截方法调用?不知怎么安排这个拦截器是最后一个
使用dropwizard 7版本若您要使用一个而不是请求分派器
,那个么您可以利用它来实现这一目的
绑定HTTP请求中的缓存实体,用于缓存从适应的容器请求中获得的实体实例
如果筛选器需要特定类型的实体,并且资源方法也将使用相同类型的实体,则可以使用此类
您基本上会这样使用它:
@Provider
public class StatsFilter implements ContainerRequestFilter {
@Override
public ContainerRequest filter(ContainerRequest request) {
final CachedEntityContainerRequest cachedRequest
= new CachedEntityContainerRequest(request);
final Saying saying = cachedRequest.getEntity(Saying.class);
return cachedRequest;
}
}
然后只需注册过滤器