How to use jetty continuations with a Filter and FORWARD dispatching?

白昼怎懂夜的黑 提交于 2020-01-03 06:14:07

问题


I have a servlet Filter that acts as the basis of my web stack. In my web.xml I have specified that I want the filter to also act as a FORWARD dispatcher.

  <filter-mapping>
    <filter-name>MyFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>  
  </filter-mapping>

This is required for another feature in my framework.

Now I am trying to add support for asynchronous continuations. The problem I've come across is that when the continuation is resumed (or when the continuation expires) jetty is never dispatching the "resumed" request to my filter. If I write a servlet, then it will get the "resumed" request. And if I remove the <dispatcher>FORWARD</dispatcher> from my web.xml file then the filter does get the "resumed" request. Is there anyway that I can have the "resumed" request dispatched to my filter even with FORWARD dispatching enabled?

After playing around a bit more, the problem arises whenever I have any <dispatcher> entries. Even if there is only a <dispatcher>REQUEST</dispatcher> entry. In order for it to work, there must be no dispatcher entries at all.


回答1:


After digging through the Jetty source code I found the answer. Turns out that Jetty supports another dispatcher type called ASYNC. So if I add any <dispatcher> lines to the <filter-mapping> section of the web.xml, I have to include an entry for ASYNC because when a "resumed" continuation is dispatched, that is the dispatcher type that is used.

<filter-mapping>
  <filter-name>MyFilter</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>ASYNC</dispatcher>
</filter-mapping>


来源:https://stackoverflow.com/questions/5123888/how-to-use-jetty-continuations-with-a-filter-and-forward-dispatching

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!