PDA

View Full Version : Access Stateful Beans from a remoting destination



Stefano Cancedda
Aug 26th, 2009, 10:39 AM
hi, i'm using Spring flex integration in Jboss 4.3 AS. My application expose a bean as a remoting-destination. this bean look-up a stateful bean with a <jee-jndi-lookup> element:


<bean id="statisticsProvider" class="org.my.flex.services.StatisticXmlProvider">
<property name="statisticsService" ref="statistics" />
<flex:remoting-destination/>
</bean>

<jee:jndi-lookup id="statistics" jndi-name="ejb/StatisticsService" />

with this configuration my flex app respond that server throw a nullpointer 'cause cannot find the stateful bean. The refs are correctly listed inside both web.xml and jboss-web.xml descriptors.

I've tryed to add scope="session" and lazy-init="true" to statisticsProvider bean, but during the webapp startup spring tells me:


17:13:04,119 ERROR [DispatcherServlet] Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.flex.remoting.RemotingDestina tionExporter#0': Cannot resolve reference to bean 'statisticsProvider' while setting bean property 'service'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'statisticsProvider': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:315)
at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:106)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1243)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1011)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:412)
at java.security.AccessController.doPrivileged(Native Method)


i'm using DispatcherServlet integration, and I've guessed that all calls to bean would be launched from an http request. Also including RequestContextLIstener in web.xml do not solve the problem.

is there a "correct way" to do what I want?

thank for any support

jeremyg484
Aug 26th, 2009, 01:50 PM
Well, first off you probably need to configure the JNDI lookup a little differently so that it happens lazily if the object being looked up is scoped to the session. You'll probably also want to disable caching of the object reference.

Take a look at JndiObjectFactoryBean to understand what exactly the <jee:jndi-lookup> tag is configuring:
http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/jndi/JndiObjectFactoryBean.html

Secondly, to properly make statisticsProvider session scoped, you need to use a scoped-proxy as described in the Spring reference manual so that when BlazeDS invokes methods on it, the proper instance is retrieved:


<bean id="statisticsProvider" class="org.my.flex.services.StatisticXmlProvider" scope="session">
<property name="statisticsService" ref="statistics" />
<aop:scoped-proxy />
<flex:remoting-destination/>
</bean>

Stefano Cancedda
Aug 27th, 2009, 11:27 AM
Thanks for your response, the problem of looking up the stateful bean is solved, but another one is rised on! This is how I've configured my jndi-look-up:


<jee:jndi-lookup id="statistics" jndi-name="ejb/StatisticsService" cache="false"
lookup-on-startup="false"
proxy-interface="org.my.business.StatisticsService" />

every call on my <mx:remoteObject>, from the flex font-end, is now creating a new instance of the statefulbean, instead of using a session scoped one!

I'm using a flex session defined in web.xml:


<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>


I don't know if this is the right place to post about this problem, maybe it can be related to aop o spring-web configurations ...
Or my problem can be the bean exposed as remoting-destination instead of the Stateful ejb?

Stefano