2014-04-21 111 views
3

我有一個Grails後端,帶有充當UI的Flex單頁應用程序。出於某種原因,當我提出AMF請求時,我的應用程序就會出現。用下面的錯誤(部分截斷可讀性)Grails Servlet過濾器瘋狂:... ServletRequestAttributes不能被轉換爲..GrailsWebRequest

2014-04-20 21:07:55,572 [http-bio-8080-exec-6] ERROR errors.GrailsExceptionResolver -  
ClassCastException occurred when processing request: [POST] 
/OrlandoGrails/messagebroker/amf 
org.springframework.web.context.request.ServletRequestAttributes cannot be cast to 
org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest. Stacktrace follows: 
java.lang.ClassCastException: 
org.springframework.web.context.request.ServletRequestAttributes cannot be cast to 
org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest... 
2014-04-20 21:07:55,573 [http-bio-8080-exec-6] ERROR errors.GrailsExceptionResolver - 

Unable to render errors view: 
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 
Servlet.service() for servlet [Spring MVC Dispatcher Servlet] in context with path 
[/OrlandoGrails] threw exception [Request processing failed; nested exception is 
org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: 

java.lang.ClassCastException: 
org.springframework.web.context.request.ServletRequestAttributes cannot be cast to 
org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest] with root cause... 
java.lang.ClassCastException: 
org.springframework.web.context.request.ServletRequestAttributes cannot be cast to 
org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest at 
grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53 

我讀過一些其他的解決方案在網絡上,他們說我必須先訂購我的web.xml我springSecurityFilter和它的最後一個映射。我已經做到了,並且下面是我的web.xml模板(Grails的得到它的阿霍德之前)

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" 
    metadata-complete="true" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 

<display-name>/@[email protected]</display-name> 

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/applicationContext.xml</param-value> 
</context-param> 

<context-param> 
    <param-name>webAppRootKey</param-name> 
    <param-value>@[email protected]</param-value> 
</context-param> 

<listener> 
    <listener-class>org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener</listener-class> 
</listener> 

<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> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>ERROR</dispatcher> 
</filter-mapping> 


<servlet> 
    <servlet-name>grails</servlet-name> 
    <servlet-class>org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>dispatchOptionsRequest</param-name> 
     <param-value>true</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
    <async-supported>true</async-supported> 
</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> 

<session-config> 
    <session-timeout>30</session-timeout> 
</session-config> 

<welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.jsp</welcome-file> 
    <welcome-file>index.gsp</welcome-file> 
</welcome-file-list> 

<listener> 
    <listener-class>flex.messaging.HttpFlexSession</listener-class> 
</listener> 
<servlet> 
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/config/web-application-config.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
    <url-pattern>/messagebroker/*</url-pattern> 
</servlet-mapping> 

被訪問時/胡說/ messagebroker/AMF,所以我將有網址認爲只有blazeds的messagebroker處理程序纔會知曉請求,但顯然我錯了。

對此非常感謝。

+0

似乎有點奇怪flex.messaging.MessageBrokerServlet從您的配置中丟失。我根本不是Flex專家,但我似乎想起您需要在Tomcat應用程序中使用監聽器和Servlet。與此類似:http://svn.codehaus.org/gfs/trunk/grails-flex-scaffold/trunk/FlexScaffoldGrailsPlugin.groovy或XML版本:http://www.pavlasek.sk/devel/?p=39 –

+0

你有沒有嘗試過這個問題的答案建議:http://stackoverflow.com/questions/8146498/the-correct-order-of-filters-in-web-xml-for-a-grails-application? – Saheed

回答

0

由於web.xml中的文檔排序,charEncodingFilter將始終在sitemesh過濾器之前執行。

我在猜測,但charEncodingFilter創建的ServletRequestAttribute實例在執行sitemesh過濾器時被轉換爲錯誤類型。

您是否嘗試過交換filter-mapping的位置?例如:

<filter-mapping> 
    <filter-name>sitemesh</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>ERROR</dispatcher> 
</filter-mapping> 
<filter-mapping> 
    <filter-name>charEncodingFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping>