Atmosphere / atmosphere

Event Driven WebSockets Framework with Cross-Browser Fallbacks
http://async-io.org/
3.69k stars 747 forks source link

Atmosphere&Jersey: Problem with using the session #242

Closed ekochnev closed 12 years ago

ekochnev commented 12 years ago

Since I have an issue with tictactoe-jersey-1 (please see README.md in the tictactoe-jersey-1) so I decided as workaround do ajax call separately:

$.ajax({ async: true, type: 'POST', url: turnUrl, });

and publish (update) game state by broadcaster.

Please note that I use @PerSession. Unfortunately it doesn't work for me too :( And yes the problem with session. Now it calls appropriate methods but when I do $.ajax() call - session doesn't have created broadcaster :( In debug I have figured out that it use the same session id but different implementation of session. By subscribing it uses org.atmosphere.container.JettyWebSocketHandler$FakeHttpSession, after by $.ajax() call it uses org.eclipse.jetty.server.session.HashedSession.

So is it bug, restriction or do I something wrong? Can we use ajax calls with the Atmosphere framework?

Of course there is workaround - don't use session and add session id (game or broadcaster id) in url (in RESTfull api). Maybe it is good idea in order to support any other clients and and so on. But anyway could you please tell can we use additional scope powered by Jersey with Atmosphere framework?

Please see https://github.com/ekochnev/atmosphere-experiments/tree/master/tictactoe-jersey-2

I use: Atmosphere 0.8.6 jetty-distribution-8.1.2.v20120308 Firefox 11.0. No java script issues is found.

jfarcand commented 12 years ago

Fixed. Thanks!

ekochnev commented 12 years ago

As far as I understand I need to use 0.9-SNAPSHOT?

Do you plan to fix it for 0.8.6?

ekochnev commented 12 years ago

I have upgraded this example to 0.9-SNAPSHOT</atmosphere.version>.

However the issue is still exist for me. I have add log which method is called. When user choice cell - contructor is called anyway. Maybe this problem is same since I do @Suspend and @Broadcast in subscribing method. I will try do it separately.

Also I have idea - can you propagate @Context AtmosphereResource - in order to we have ability to do late binding with broadcaster as we can do when use AtmosphereHandler. Let me know if it is not stupid request when I will file enhancement.

jfarcand commented 12 years ago

Salut...no more fix for 0.8.x so if there is an issue it will be in 0.9.0. Thanks

jfarcand commented 12 years ago

@context AtmosphereResource already supported so what you describe should work. I will work on the @Suspend/@Broadcast schenario and see if I can supports it. You can always return a Broadcastable with the @Suspend and that will do exactly what @Broadcast would have done BTW. Thanks!!!