Announcement Announcement Module
Collapse
No announcement yet.
Using session-scoped beans with CommonsHttpInvokerRequestExecutor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using session-scoped beans with CommonsHttpInvokerRequestExecutor

    I'm having a frustrating time trying to get a session-scoped bean working with my application. I am developing a Spring-based server app that is being served via Tomcat with a Swing-based client. So far, here's the relevant config...

    web.xml:
    Code:
    <web-app>
    	<!-- the context specified to the web-app -->
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/BaselineServiceBeans.xml</param-value>
    	</context-param>
    
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    
        <listener>
            <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
        </listener>
      
    	<servlet>
    		<servlet-name>remoting</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    	
    	<servlet-mapping>
    		<servlet-name>remoting</servlet-name>
    		<url-pattern>/remoting/*</url-pattern>
    	</servlet-mapping>
    </web-app>
    BaselineServiceBeans.xml (server-side):

    Code:
    <beans default-lazy-init="true">
    	<bean id="baselineService"
    		class="iwp.baseline.services.impl.BaselineServiceImpl"
    		scope="singleton" />
    
    	<bean id="hibernateAuthAdapter"
    		class="iwp.baseline.services.spring.util.HibernateAuthAdapter"
    		scope="session">
    		<aop:scoped-proxy />
    	</bean>
    
    	<bean id="baselineClientService"
    		class="iwp.baseline.services.impl.BaselineClientServiceImpl"
    		scope="singleton">
    		<property name="baselineService" ref="baselineService"/>
    		<property name="authAdapter" ref="hibernateAuthAdapter"/>
    	</bean>
    
            <!-- other beans -->
    </beans>
    applicationContext.xml:
    Code:
    <beans default-lazy-init="true">
        <!-- hibernate stuff and other beans -->
    	<bean id="baselineAuthAdapter" class="iwp.baseline.services.spring.util.HibernateAuthAdapter">
    	</bean>
    BaselineServiceBeans.xml on the client side:
    Code:
    <beans default-lazy-init="true">
    	<bean id="remoteBaselineClientService"
    		class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
    		<property name="serviceInterface"
    			value="iwp.baseline.services.BaselineClientService" />
    		<property name="serviceUrl" value="/url/to/baselineClientService" />
    		<property name="httpInvokerRequestExecutor">
    			<ref bean="httpInvokerExecutor" />
    		</property>
    	</bean>
    
    	<bean id="localBaselineClientService"
    		class="iwp.baseline.services.impl.BaselineClientServiceImpl" />
    
    	<alias name="remoteBaselineClientService"
            alias="baselineClientService" />
    
    <!-- Remoting -->
    
    	<bean id="httpInvokerExecutor"
    		class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor">
    		<property name="readTimeout" value="0" />
    	</bean>
    	
    </beans>
    The issue:

    The hibernateAuthAdapter bean stores the currently logged-in user, thus why it should be session-scoped. Logging in works fine; however, when I go back later to query it for the user, it comes back as null, which likely means a new hibernateAuthAdapter instance was created for the getUser() call some time after the log in. So what I'm guessing is that the session-scoped bean is not properly hooked up to a session with the client. To try to address that, I added the RequestContextListener to web.xml as you can see above, but I got the same result. Reading the Javadoc for RCL, it seems it really isn't meant for the purpose of keeping track of sessions.

    This seems like a pretty basic problem: connect a session between a client and the server to keep semi-persistent data around during the lifetime of the application. What am I missing in my configuration?

    Thanks a bunch!

    (P.S.: I cut out bean definitions that are irrelevant to the auth adapter - if any of you need to see more, let me know.)
    Last edited by aarestad; Oct 15th, 2008, 11:02 AM. Reason: editing error
Working...
X