Change in scalatra filter behavior

Go To StackoverFlow.com

1

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?

2012-04-04 23:20
by schmmd
what version of Scalatra are you on? 2.10 develop, 2.0.4 stable, or, something else? (reads like a recorded message ;-) - virtualeyes 2012-04-05 08:38
My site "works" on Scalatra 2.0.0. My site "does not work" on Scalatra 2.0.1 and 2.0.4. I put those phrases in quotes because I'm not sure if I'm leveraging a bug or a feature--although I think it's the latter - schmmd 2012-04-05 15:37


1

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.
2012-04-05 15:56
by virtualeyes
Yes, so the first part suggests what I'm doing should work (delegate to the next filter) and the second part suggests that it should not work (match deeper prefix) - schmmd 2012-04-05 15:58
;-) I love Scalatra, but some digging required, none of the maintainers are paid (directly). The documentation is good, but not great. IMHO, it's the most accessible/hit-the-ground-running Scala micro framework around (Spray & Unfiltered have the stateless REST niche well covered, but Scalatra generally gets out of your way, gives you state if you want it, and is super easy to morph into an MVC stack). Anyway, glad to have been of some assistance - virtualeyes 2012-04-05 16:29
Ads