Search code examples
javaajaxspringdwr

Accessing DWR post data in a Spring Interceptor


I have a DWR action with a method signature as follows:

String joinGroup(String groupId, String groupName);

This is called via a DWR AJAX request and works fine.

However, I am trying to write a Spring interceptor (works much like a ServletFilter) to do some authentication work before the DWR action is called.
The interceptor is being called correctly but I need to access the groupId and groupName data in the interceptor.

The request parameter map is empty and I've been through the entire list of request attributes in a debugger and I can't see the data anywhere.
The request's postData is null also.

Using firebug I can see the data is being passed to the server (and it's there when the joinGroup method is ultimately called).
I just can't seem to access it in my interceptor.

Is there any way I can access it at all?


Solution

  • Use org.directwebremoting.AjaxFilter

    The doFilter method of the AjaxFilter is called by DWR each time an Ajax request is made on a method that this filter is configured against. The AjaxFilterChain passed in to this method allows the filter to pass on method details to next entity in the chain.

    Typically the method would do the following:

    1. Examine the request
    2. Optionally alter the method, object or parameters
    3. Either invoke the next entity in the chain using the AjaxFilterChain or decide to take some other action instead.
    4. Optionally modify the value returned to the user
    5. Take some other action (e.g. logging)