开发者

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

开发者 https://www.devze.com 2023-02-13 18:04 出处:网络
I have a servlet Filter that acts as the basis of my web stack.In my we开发者_运维问答b.xml I have

I have a servlet Filter that acts as the basis of my web stack. In my we开发者_运维问答b.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.


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号