Re: Q: Spring, DWR & Cayenne

From: Mike Kienenberger (mkienen..mail.com)
Date: Sun Jan 08 2006 - 21:44:39 EST

  • Next message: Pierre Gilquin: "Newbie - No DataMap found"

    I went with a servlet filter for Spring + Cayenne + cayenne-spring + JSF.

        public void doFilter(ServletRequest servletRequest,
    ServletResponse servletResponse, FilterChain chain) throws
    IOException, ServletException
        {
            requestInitialized(servletRequest, servletResponse);

            chain.doFilter(servletRequest, servletResponse);

            requestDestroyed(servletRequest, servletResponse);
        }

        public void destroy()
        {
        }

        public void requestInitialized(ServletRequest servletRequest,
    ServletResponse servletResponse)
        {
            HttpSession session =
    ((HttpServletRequest)servletRequest).getSession(true);
            DataContext dataContext = ServletUtil.getSessionContext(session);
            DataContext.bindThreadDataContext(dataContext);
        }

        public void requestDestroyed(ServletRequest servletRequest,
    ServletResponse servletResponse)
        {
            DataContext dataContext = DataContext.getThreadDataContext();

            // reportUncommittedObjects(dataContext, facesContext);
            // dataContext.rollbackChanges();

            DataContext.bindThreadDataContext(null);
        }

    This also let me do some integrity checking as my servlet is not
    supposed to leave the datacontext in a dirty state (I commented out
    that code in the example above to keep the example small). I throw in
    a rollbackChanges() as a failsafe method, but it's never been
    activated -- it'd probably be better to create a new dataContext at
    that point instead.

    On 1/8/06, chad smith <cksuta..otmail.com> wrote:
    > My problem: the Cayenne thread data context is not getting set because my
    > app (Cayenee) is configured as a web interceptor in Spring and I'm pushing
    > all DWR requests directly to the DWR servlet (in web.xml).
    > My understanding is there are two options:
    > a. try to configure spring to receive all DWR requests, that way the
    > interceptor filter code will get called or
    > b. try to set the thread data context as a servlet filter (and remove the
    > web interceptor in Spring?)
    >
    > I've tried option a. using ...
    > ----------------------------------------------------------------------
    > <bean id="urlMapping"
    > class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    > <property name="interceptors">
    > <list>
    > <ref bean="cayenneWebInterceptor"/>
    > </list>
    > </property>
    > <property name="mappings">
    > <props>
    > <prop key="/**/dwr/*">dwrController</prop>
    >
    > <prop key="/logon.x">mainEvents</prop>
    > <prop key="/logoff.x">mainEvents</prop>
    > <prop key="/mainView.x">mainEvents</prop>
    > <prop key="/menuView.x">mainEvents</prop>
    > <prop key="/test.x">mainEvents</prop>
    >
    > ----------------------------------------------------------------------------
    > ... w/ various variations of the dwr/* mapping but for some reason Spring
    > won't send request to the DWR controller under this config.
    >
    > So, do you recommend a servlet filter approach or try to find a solution w/
    > the spring configuration?
    >
    > Chad Smith
    > ~~~~~~~~~~~~~~~~~
    > Practice Director, Public Sector
    > ic2 Solutions
    > Cell: 801.230.1081
    > E-mail: Chad.Smit..c2Solutions.com
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Sun Jan 08 2006 - 21:44:42 EST