Push with session scoped beans not working

We are developing a vaadin 7.1 application with push support which uses spring session beans. We get the following exception when trying to use the push feature:

[code]

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.

[/code]…when trying to access spring session scoped beans from within a push request.
I have already read that push with spring session scoped beans doesn’t work. But the project needs to use push and needs to use session beans.
So what could we do?
Remove Spring and use Jave EE 6?
Use another push addon?
Any help would be appretiated!

If you enable server push, vaadin will usually use WebSockets as the transport channel. This method of transportation circumvents all spring listeners responsible for getting the right session bean for the current user.

You can however tell Vaadin to use another transport channel. Just annotate your UI with @Push(transport=Transport.STREAMING)
Streaming rely on WebSockets and thus spring listeners work as expected. So you session scoped beans should work with server push this way.

I don’t know however if there are any drawbacks to using Streaming instead of WebSockets.

Thorsten, thank you for your reply!
Using @Push(transport=Transport.STREAMING) still gives the same exception. Maybe we have another problem here? The exception occures when the RequestcontextHolder tries to get the request attributes, which are null. Here is more of the stack trace:


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.
[err]
 	at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
[err]
 	at org.springframework.web.context.request.SessionScope.get(SessionScope.java:90)
[err]
 	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)

I am triggering the Push Request in a Simple Servlet by


	protected void doGet(final HttpServletRequest a_oRequest, final HttpServletResponse a_oResponse) throws ServletException, IOException
	{
		Broadcaster.broadcast("HI", a_oRequest.getRemoteAddr());
}

the broadcaster then sends the message to registered listeners, which could update the ui.

Hi Georg,

it sound to me like you are trying to refresh a users UI (or that of multiple users) every time a request is made to a custom servlet of yours that has per se nothing to do with vaadin. Did get that right?

If so, there never is a push request, that could be intercepted by your spring listeners. They only work if the user presses a button or does some other interaction on his UI.

I really don’t know enough of your setup to make any informed suggestions. However, it sounds like you might have to go stateless if you can. I have yet to see a good working solution that combines vaadin push and spring (with session beans).

Hi,

I now using Vaadin 16 with SpringBoot 2.2.8. I get the same exception.

But it is not reliable. So, sometimes it works sometimes not.

Is this still a problem?

BTW: I configure the transport to LONG_POLLING.

Thanks,
Dirk