BlazeDS <flex:secured /> Problem with Grails
Note: I've edited title as old one was a little misleading based on recent investigation.
I've integrated BlazeDS with Grails, using Spring under the hood techniques. When I add a new servlet and mapping to the web.xml, I receive exceptions whether it is a Flex client request or browser request.
This is little off track for this forum, but perhaps someone has seen this sort of issue. It is kind of a web.xml and DispatcherServlet question (or perhaps more about how Grails handles incoming requests)
Servlet code in web.xml
Code:
<servlet>
<servlet-name>flex</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>flex</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
There is already a GrailsDispatcherServlet (child of DispatcherServlet) by default, without an explicitly stated mapping, so I assume its defaulted somewhere in Grails:
Code:
<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>
From Flex client, I am able to call my exposed service on the server and receive an object back, but do get this exception on server side:
Code:
ERROR filter.UrlMappingsFilter - Error when matching URL mapping [/(*)/(*)?/(*)?]:org.springframework.web.context.request.ServletRequestAttributes cannot be cast to org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
java.lang.ClassCastException: org.springframework.web.context.request.ServletRequestAttributes cannot be cast to org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
at java.lang.Thread.run(Thread.java:619)
If I try and access from browser using usual URL http://localhost:8080/myAppRoot/ ... I receive an error 500 page with same kind of exception:
Code:
Error 500:
Servlet: default
URI: /myAppRoot/
Exception Message: org.springframework.web.context.request.ServletRequestAttributes cannot be cast to org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
Caused by: org.springframework.web.context.request.ServletRequestAttributes cannot be cast to org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
Class: Unknown
At Line: [-1]
Code Snippet:
Anyone have any idea how to clean this up to make both servlets play together nicely?
Thanks,
Larry
Fixe for Spring Security 3.0.4 and Grails 1.3.5
Hi, After a lot of googling and researching I found the following solution.
In the web.xml, add the GrailsWebRequestFilter and include the filter mapping before the springSecurityFilterChain filter mapping(order is important). For example:
Code:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<filter-name>grailsWebRequest</filter-name>
<filter-class>org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter</filter-class>
</filter>
<!-- Other filters... -->
<!-- filter mappings -->
<filter-mapping>
<filter-name>grailsWebRequest</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
... more mappings
Hope this helps.