Domanda

I have multiple filters in my application, with one at the root.

<filter>
    <filter-name>root</filter-name>
    <filter-class>
        my.own.classpath.RootFilter
    </filter-class>
</filter>

<filter>
    <filter-name>root</filter-name>
    <filter-class>
        my.own.classpath.SubFilter
    </filter-class>
</filter>

<filter-mapping>
    <filter-name>root</filter-name>
    <url-pattern>/</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>sub</filter-name>
    <url-pattern>/sub/*</url-pattern>
</filter-mapping>

In Scalatra 2.0.0 this worked fine. If RootFilter (which extends ScalatraFilter) had a binding for a url it would handle it, otherwise it would pass on to the other filters. However, in later versions of Scalatra it does not work the same. When I supply a url handled by SubFilter, the correct filter is still called, but the resulting text is not displayed. Instead, a blank page (with no HTML) is returned.

Is this a bug in Scalatra, or am I doing something wrong?

È stato utile?

Soluzione

I'm not sure, Scalatra does not move at Java pace, so things change.

Here's an a snippet from the Scalatra Book v2.0 on ScalatraServlet vs. ScalatraFilter; there may be some clue here as to where the problem lies, particularly in regard to Not Found and ScalatraFilter delegating to the next filter in the chain (in your case, there is no next filter after sub)

The main difference is the default behavior when a route is not found. A ScalatraFilter will delegate to the next filter or servlet in the chain (as configured by web.xml), whereas a ScalatraServlet will return a 404 response.

Another difference is that ScalatraFilter matches routes relative to the WAR's context path. ScalatraServlet matches routes relative to the servlet path. This allows you to mount multiple servlets under in different namespaces in the same WAR.

Use ScalatraFilter if:

You are migrating a legacy application inside the same URL space
You want to serve static content from the WAR rather than a dedicated web server    

Use ScalatraServlet if:

You want to match routes with a prefix deeper than the context path.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top