[英]Handle Jersey/JAX-RS REST manually
I'm building an application where I'd like to intercept HTTP requests and decide whether or not to pass them to a JAX-RS implementation for processing. 我正在构建一个应用程序,我想拦截HTTP请求并决定是否将它们传递给JAX-RS实现进行处理。
I basically have a single filter-and-front-controller-servlet combination and would like the servlet to delegate routing either to Jersey or to my "standard" router. 我基本上有一个filter-and-front-controller-servlet组合,并希望servlet将路由委托给Jersey或我的“标准”路由器。
I can see lots of examples of using Jersey as a servlet, or of starting up an HTTP server, but there doesn't seem to be a handy way to take an HttpServletRequest/HttpServletResponse pair and say "here you go Jersey, route this for me". 我可以看到很多使用Jersey作为servlet或启动HTTP服务器的例子,但似乎没有一种方便的方法来接受一个HttpServletRequest / HttpServletResponse对并说“在这里你去泽西,路由此我”。
Am I missing something obvious? 我错过了一些明显的东西吗
In this case, I think a RequestDispatcher might helps 在这种情况下,我认为RequestDispatcher可能会有所帮助
A RequestDispatcher object can be used to forward a request to another resource, so you can try something like the following: RequestDispatcher对象可用于将请求转发到另一个资源,因此您可以尝试以下操作:
public class FrontServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
ServletContext sc = this.getServletContext();
if (someCondition) {
sc.getRequestDispatcher("/jersey/servlet").forward(req, resp);
}else{
sc.getRequestDispatcher("/standard/router").forward(req, resp);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.