Announcement Announcement Module
Collapse
No announcement yet.
BlazeDS Servlet in web.xml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BlazeDS Servlet in web.xml

    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
    Last edited by con19m31; Apr 25th, 2010, 12:41 PM. Reason: Title became a little misleading

  • #2
    Update

    Hi,

    Thanks to anyone that has read about my issue.

    In my flex-servlet.xml I had the following:

    <flex:message-broker>
    <flex:secured />
    </flex:message-broker>

    If I remove <flex:secured /> everything works fine. At this point, I do not know why this is the case, but I'm looking into it and hope to find out

    I'll post a reply if/when I find the problem.

    Thanks,

    Larry

    Comment


    • #3
      Another Update

      If I remove the Spring security filter chain, everything works fine as well, ie. by removing:

      Code:
      <filter>
      	<filter-name>springSecurityFilterChain</filter-name>
      	<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
      	</filter>
      
      <filter-mapping>
      		<filter-name>springSecurityFilterChain</filter-name>
      		<url-pattern>/*</url-pattern>
      </filter-mapping>
      I guess that makes sense since it would disable the security functionality, but I'd really appreciate if anyone has any theory on why this doesn't play nicely with Grails etc.

      Thanks,

      Larry

      Comment


      • #4
        Update

        I tried reverting to SpringSecurity 2 just in case there would be some difference, and same result.

        Guess its time to dig into how everything gets initialized to figure out why I'm seeing a ServletRequestAttributes instead of a GrailsWebRequest in the referenced part of code.

        If you happen to know that area of the Grails/Spring code, help!

        Comment


        • #5
          Glad you were able to make some progress. I'm not familiar enough with Grails to be sure of what is required there. You might try posting on the Grails list to see if someone there can point you in the right direction.

          Comment


          • #6
            Thanks......I'm gradually adding sources so I can try and see what is going on behind the scenes.

            It seems to center around the springSecurityFilterChain in web.xml. If I change the url-pattern to something else, like *.html, then I can browse via Grails controllers just fine and request/response for Flex are also fine.

            If I remove flex:secured all is well also, but I guess in both these cases I'm bypassing the offending area in the security filter chain so doesn't tell me too much.

            The upside is I have no choice but to learn some of the internals which isn't a bad thing

            Comment


            • #7
              Fixed

              Hi,

              It turns out that in DefaultUrlMappingInfo class, method evaluateNameForValue(Object value), the code below has an instance of ServletRequestAttributes instead of a GrailsWebRequest, when the Spring filters are in use (not sure if this is only when flex:secured is specified).

              Code:
              protected String evaluateNameForValue(Object value) {
                   GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.getRequestAttributes();
                   return evaluateNameForValue(value, webRequest);
              }
              However, I found a tweak that has resolved this issue. The SpringSecurity pdf says that the filters ordering should have Spring ones first, before others like sitemesh, Wicket etc.

              I had the filter and filter-mapping for the springSecurityFilterChain after the other filter and filter-mapping entries. This now works if I move only the filter-mapping entry for Spring such that it is first. Moving the filter entry to be first does not fix the issue, and in fact I've read on a couple of blogs that having the Spring filter first causes other issues if there are other Grails filters defined.

              So, I've now got my filter for Spring last, and my filter-mapping for Spring first, and things are working fine. Onto the next phase now and thanks for any advice/thinking.

              Larry

              Comment


              • #8
                cool, thank you this is very nice

                Comment


                • #9
                  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.

                  Comment

                  Working...
                  X