views:

82

answers:

1

Hello,

Today I upgraded our grails app from 1.0.3 to 1.3.3 and, of course, things started behaving weirdly.

The problem I'm currently asking about is as follows: the web.xml contains:

<filter>
     <filter-name>sitemesh</filter-name>
    <filter-class>org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter</filter-class>
</filter>

 <filter>
    <filter-name>charEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
      <param-name>targetBeanName</param-name>
      <param-value>characterEncodingFilter</param-value>
    </init-param>
    <init-param>
      <param-name>targetFilterLifecycle</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>


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

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

It appears to be working (at least some pages are loading), but in the logs there is:

Caused by: java.lang.ClassCastException: org.springframework.web.context.request.ServletRequestAttributes cannot be cast to org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
    at org.codehaus.groovy.grails.web.pages.GroovyPagesServlet.createResponseWriter(GroovyPagesServlet.java:211)
    at org.codehaus.groovy.grails.web.pages.GroovyPagesServlet.renderPageWithEngine(GroovyPagesServlet.java:137)
    at org.codehaus.groovy.grails.web.pages.GroovyPagesServlet.doService(GroovyPagesServlet.java:122)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)

If I get rid of the spring filter, I'm getting a NullPointerException:

java.lang.NullPointerException
    at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:136)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.obtainContent(GrailsPageFilter.java:245)
    at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.doFilter(GrailsPageFilter.java:134)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

On first look I'd guess that no one is setting the org.codehaus.groovy.grails.WEB_REQUEST request attribute which the UrlMappingsFilter is expecting. (causing the NPE)

And the spring servlet (somehow appearing not being mapped, after a spring filter is mapped) is adding the "wrong" (according to grails) ServletRequestAttributes.

Reordering the above mappings made it so as if the spring mapping didn't exist - i.e. a NPE is thrown.

So the question is - how to proceed. I guess I'm missing some essential mapping in web.xml ?

(I have the required ones)

<servlet>
    <servlet-name>grails</servlet-name>
    <servlet-class>org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- The Groovy Server Pages servlet -->
  <servlet>
    <servlet-name>gsp</servlet-name>
    <servlet-class>org.codehaus.groovy.grails.web.pages.GroovyPagesServlet</servlet-class>
 </servlet>

<servlet-mapping>
    <servlet-name>gsp</servlet-name>
    <url-pattern>*.gsp</url-pattern>
</servlet-mapping>
A: 

I got rid of the ClassCastException by adding mapping org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter to /*. Not sure whether this filter should be mapped there, though, and where is it said that it shoudl.

Bozho