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.

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 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

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

long polling doesnt work, xhr doesnt work,…

uiscope diesnt work

I hope someone has a tip here?

posted this on stackoverflow: