Using the Broadcaster in combination with SessionScope throws ScopeNotActiveException

I tried adding the Broadcaster example into one of my pages. Then take the result and add it to my UserSession service, which is Session scoped. Then I get a ScopeNotActiveException. What am I doing wrong? Thanks in advance for your time.

Please share the example you have tried.

`@Override
protected void onAttach(AttachEvent attachEvent) {
UI ui = attachEvent.getUI();
// broadcast: react to coordinates
broadcasterRegistration = Broadcaster.register(newMessage → {
ui.access(() → {
String imageUrls = encounterService.clearEncounter();

            String[] coordinates = ((String) newMessage).split(";");
            String x = coordinates[0];
            String y = coordinates[1];
            imageUrls[Integer.valueOf(x)][Integer.valueOf(y)] = "icons/token.png";

            // PROBLEM
            // userSession.setCurrentEncounter(imageUrls);
        });
    });
}`

the userSession is session scoped annotated

I’m just guessing here. So you are talking about https://vaadin.com/docs/v14/flow/advanced/tutorial-push-broadcaster which creates a Broadcaster class. This Broadcaster uses an Executor to execute the calls in another thread and therefore the session is not available because it’s not propagated by default

yes broadcaster example you are right

https://vaadin.com/docs/latest/advanced/server-push

ah ok i am checking those collabo… views now

hm seems your article talks about broadcaster just like my link. mine may be newer

Yes you won’t find more information about it. It’s a basic example to be adopted for more advanced use-cases. Because you are using spring, it’s probably better to change the whole broadcaster static stuff to a proper singleton and go from there. You still have find a way to transfer the needed information to the service nevertheless, like using propagated security contexts, passing the userId and retrieve it or just pass the user :sweat_smile: hard to say which works best for you

by singleton i guess you mean a @SpringComponent ? i could do this. but the basic broadcaster example itself worked. its just now that i am trying to reach for a user scoped bean within a lambda. i am using the same usersession inside this class, but outside this lambda, and there it worked.

i would have to google propagated security context first :sweat_smile:

thanks for your hints knoobie

this sounds like my problem

https://vaadin.com/forum/thread/4103455/push-with-session-scoped-beans-not-working

long polling doesnt work, xhr doesnt work,…

https://github.com/vaadin/framework/issues/8967

uiscope diesnt work

I hope someone has a tip here?

posted this on stackoverflow: https://stackoverflow.com/questions/74843369/how-to-use-sessionscope-beans-with-vaadin-broadcaster