Announcement Announcement Module
Collapse
No announcement yet.
Can you pass http session scoped messageListener to DefaultMessageListenerContainer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can you pass http session scoped messageListener to DefaultMessageListenerContainer

    Env:
    Spring Framework 2.5.4
    JSF 1.2
    ActiveMQ 5.1.0

    Problem scenario:
    When the (Text) message is posted into Topic, messageListener's onMessage gets called. However when I try to reterive the (Text) message and add it to sessionBean messages (ArrayList) I am getting the classic error message

    "Error creating bean with name 'scopedTarget.photoSearchViewer': 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."



    Yes.
    (1) I have org.springframework.web.context.request.RequestCon textListener in web.xml
    (2) I have set <aop:scoped-proxy/> for my session scope bean so that I can pass that to my scope="singleton" class.



    PLEASE HELP! WHAT I AM DOING WRONG!
    Your time is much appreciated.

    ----- Stack Trace BEGIN --------------------------


    Jun 1, 2008 9:24:37 PM org.springframework.jms.listener.AbstractMessageLi stenerContainer handleListenerException
    WARNING: Execution of JMS message listener failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.photoSearchViewer': 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.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:312 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.aop.target.SimpleBeanTargetSou rce.getTarget(SimpleBeanTargetSource.java:33)
    at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.getTarget(Cglib2AopProxy. java:666)
    at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:616)
    at SearchViewerImpl$$EnhancerByCGLIB$$6e6d5e7d.getMes sages(<generated>)
    at SearchListener.onMessage(SearchListener.java:18)
    at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doInvokeListener(AbstractMessageLi stenerContainer.java:531)
    at org.springframework.jms.listener.AbstractMessageLi stenerContainer.invokeListener(AbstractMessageList enerContainer.java:466)
    at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doExecuteListener(AbstractMessageL istenerContainer.java:435)
    at org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.doReceiveAndExecute(Abstrac tPollingMessageListenerContainer.java:319)
    at org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.receiveAndExecute(AbstractP ollingMessageListenerContainer.java:257)
    at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.invokeL istener(DefaultMessageListenerContainer.java:944)
    at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.run(Def aultMessageListenerContainer.java:868)
    at java.lang.Thread.run(Thread.java:595)
    Caused by: 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.web.context.request.RequestCon textHolder.currentRequestAttributes(RequestContext Holder.java:121)
    at org.springframework.web.context.request.SessionSco pe.get(SessionScope.java:88)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:298 )
    ... 15 more

    ------------- STACK TRACE END ---------------------


    ----------- BEAN DEFINITION BEGIN ------------
    <bean id="listenerContainer"
    class="org.springframework.jms.listener.DefaultMes sageListenerContainer">
    <property name="connectionFactory" ref="jmsConnectionFactory" />
    <property name="destination" ref="topicSearch" />
    <property name="messageListener" ref="searchListener" />
    </bean>


    <bean id="searchListener" class="SearchListener">
    <property name="pView" ref="SearchViewer"/>
    </bean>


    <bean id="searchViewer" class="SearchViewerImpl"
    scope="session">
    <aop:scoped-proxy/>
    </bean>
    ----------- BEAN DEFINITION END ------------



    ------------ WEB.XML BEGIN -----------------------------
    <!-- Spring Security Setup information BEGIN -->


    <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFil terProxy</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Spring Security Setup information END -->



    <display-name>a4jEchoText</display-name>
    <context-param>
    <param-name>org.richfaces.SKIN</param-name>
    <param-value>blueSky</param-value>
    </context-param>

    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
    </context-param>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/springContext.xml
    /WEB-INF/applicationContext-hibernate.xml
    /WEB-INF/applicationContext-security.xml
    /WEB-INF/applicationContext-activeMQ.xml
    </param-value>
    </context-param>

    <listener>
    <listener-class>
    org.springframework.web.context.request.RequestCon textListener
    </listener-class>
    </listener>

    <listener>
    <listener-class>
    org.springframework.web.context.ContextLoaderListe ner
    </listener-class>
    </listener>
    <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>

    <filter>
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
    <init-param>
    <param-name>createTempFiles</param-name>
    <param-value>true</param-value>
    </init-param>
    <init-param>
    <param-name>maxRequestSize</param-name>
    <param-value>2000000</param-value>
    </init-param>
    </filter>
    <filter>
    <display-name>Sleep Filter</display-name>
    <filter-name>sleepFilter</filter-name>
    <filter-class>UploadSleepFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>sleepFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>
    </filter-mapping>
    <filter-mapping>
    <filter-name>richfaces</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>

    ---------------- WEB.XML END ----------------------------

  • #2
    DefaultMessageListener and really any JMS listening you have going on is doing so outside the scope of an HTTP session or request, so I assume you have to do something special (as noted in the error you got), to get back to the HTTP session if that's what you want.

    Comment


    • #3
      Any suggestions? please

      Any suggestions?? on how one would solve this type of situtation

      Comment


      • #4
        What I would do is first remove the aop-proxy, and consider how you may want to manually correlate the results of the JMS message back to your web view. At first glance, it would appear you are generating some search results that you are then want to update in a search result viewer?

        In that case, you need some correlating attribute to tie the JMS results back to the actual web session that the user is connected to. One thing to consider may to pass around an ID from the session down into your JMS signalling, such that when you get the result back, you get the ID out, and then lookup the right context.

        Without using anything with Spring's context, a very simple system could be that your web request has a singleton hashmap of session ID to result sets. When you generate a search request, you give the session ID, and then when the results come back, it just gets a reference to the singleton and updates that hashmap. The servlet request is then just waiting on looking at singleton and updating the view with the results until it decides its done (e.g. showing up to 100 results at a time or something of that nature). This begs a whole bunch fo questions like how do you maintain the search results over time, who clears them out and all that fun stuff, but I think you would have probably ran into that anyway with a system like this (e.g. a JMS message arrives 5 minutes later after the user has logged out, how is that handled)?

        In terms of Spring support, I would look at the classes mentioned in the error (RequestConextListener) and see what is the best way to retrieve a context. I'm not all that familiar with the MVC side of Spring, I'm usually down in the plumbing of the application.

        Comment


        • #5
          Thank you! Jabberz

          Thank you! Jabberz for your time.

          I created the singleton class to as message listener and injected this class into my another view session bean. Also implemented another HttpSessionListener to clean up all the message received for this user on sessionDestroyed method of the interface.

          Comment

          Working...
          X