Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atmosphere&Jersey: method of PerRequestBroadcastFilter is not called #244

Closed
ekochnev opened this issue Mar 26, 2012 · 7 comments
Closed

Comments

@ekochnev
Copy link

Please see this example.

The issue that Atmosphere calls filter(Object originalMessage, Object message) but doesn't call filter(HttpServletRequest request, HttpServletResponse response, Object message) for both assigned filters (via web.xml and programmatically) Please see log below.

Log from my console:

15:58:37.793 [qtp984103443-23] DEBUG o.a.container.JettyWebSocketUtil - WebSocket-checkOrigin request /tictactoe/restapi/game/start with origin http://localhost:8080 15:58:37.794 [qtp984103443-23] DEBUG o.a.container.JettyWebSocketUtil - WebSocket-connect request /tictactoe/restapi/game/start with protocol null 15:58:37.813 [qtp984103443-23] DEBUG o.a.websocket.WebSocketProcessor - Atmosphere detected WebSocket: org.atmosphere.container.version.Jetty8WebSocket 15:58:47.974 [qtp984103443-23] INFO o.a.t.PersonalPerRequestBroadcastFilter - PersonalPerRequestBroadcastFilter.filter(Object originalMessage, Object message) 15:58:47.977 [qtp984103443-23] INFO o.a.tictactoe4.TicTacToeGame - PerRequestBroadcastFilter.filter(Object originalMessage, Object message) 15:58:49.637 [Atmosphere-BroadcasterConfig-0] DEBUG o.atmosphere.cpr.DefaultBroadcaster - Broadcaster game doesn't have any associated resource 15:58:49.640 [qtp984103443-23] DEBUG o.atmosphere.jersey.AtmosphereFilter - Linked HttpServletRequest org.atmosphere.cpr.AtmosphereRequest@7d6c848f with ContainerResponse com.sun.jersey.spi.container.ContainerResponse@5f73089d 15:58:49.648 [qtp984103443-23] DEBUG o.a.container.JettyWebSocketUtil - Suspending response: org.atmosphere.cpr.AtmosphereResponse@3bdd6a67
15:59:03.551 [qtp984103443-21] INFO o.a.t.PersonalPerRequestBroadcastFilter - PersonalPerRequestBroadcastFilter.filter(Object originalMessage, Object message)
15:59:03.553 [qtp984103443-21] INFO o.a.tictactoe4.TicTacToeGame - PerRequestBroadcastFilter.filter(Object originalMessage, Object message)

15:59:04.959 [Atmosphere-BroadcasterConfig-0] DEBUG o.atmosphere.cpr.DefaultBroadcaster - Broadcaster game doesn't have any associated resource 15:59:04.960 [qtp984103443-21] DEBUG o.atmosphere.jersey.AtmosphereFilter - Linked HttpServletRequest org.atmosphere.cpr.AtmosphereRequest@7393e1fc with ContainerResponse com.sun.jersey.spi.container.ContainerResponse@71d9a2ab 15:59:04.962 [qtp984103443-21] DEBUG o.a.container.JettyWebSocketUtil - Suspending response: org.atmosphere.cpr.AtmosphereResponse@79095fd7
16:01:56.021 [qtp984103443-22] INFO o.a.t.PersonalPerRequestBroadcastFilter - PersonalPerRequestBroadcastFilter.filter(Object originalMessage, Object message)
16:01:56.022 [qtp984103443-22] INFO o.a.tictactoe4.TicTacToeGame - PerRequestBroadcastFilter.filter(Object originalMessage, Object message)

16:01:57.585 [Atmosphere-BroadcasterConfig-0] DEBUG o.atmosphere.cpr.DefaultBroadcaster - Broadcaster game doesn't have any associated resource 16:01:57.586 [qtp984103443-22] DEBUG o.atmosphere.jersey.AtmosphereFilter - Linked HttpServletRequest org.atmosphere.cpr.AtmosphereRequest@23b35955 with ContainerResponse com.sun.jersey.spi.container.ContainerResponse@53adedc2 16:01:57.588 [qtp984103443-22] DEBUG o.a.container.JettyWebSocketUtil - Suspending response: org.atmosphere.cpr.AtmosphereResponse@16394576

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

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

@jfarcand
Copy link
Member

This is not a bug. In your log, you can see

      11:21:44.100 [Atmosphere-BroadcasterConfig-0] DEBUG o.atmosphere.cpr.DefaultBroadcaster - Broadcaster game doesn't have any associated resource

There is no suspended connection/resource, hence the PerRequestBroadcastFilter API will never be invoked as the Broadcaster doesn't have anything to broadcast to.

@ekochnev
Copy link
Author

So, it means that I cannot do @suspend and @broadcast at the same method?

@jfarcand
Copy link
Member

You need to make sure the connection is suspended first. Add an AtmosphereResourceEventListener#onSuspend(), and from there use a BroadcasterFactory (or AtmosphereResource#getBroadcaster) to broadcast.

@ekochnev
Copy link
Author

I think we need to mark this restriction in documentation.

@jfarcand
Copy link
Member

Agree. Can you file an issue with [javadoc] in the title? Thanks a lot.

@ekochnev
Copy link
Author

Ok, I will.

So I have refactored it to use AtmosphereResourceEventListener.
Now both filters and methods are called successfully.
You can see it there: https://github.com/ekochnev/atmosphere-experiments/tree/master/tictactoe-jersey-4.2-9.x

This is current log:


2012-03-27 17:02:03.633:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080
17:02:29.256 [qtp533000440-18] DEBUG o.a.container.JettyWebSocketUtil - WebSocket-checkOrigin request /tictactoe/restapi/game/start with origin http://localhost:8080
17:02:29.258 [qtp533000440-18] DEBUG o.a.container.JettyWebSocketUtil - WebSocket-connect request /tictactoe/restapi/game/start with protocol null
17:02:29.280 [qtp533000440-18] DEBUG o.a.websocket.WebSocketProcessor - Atmosphere detected WebSocket: org.atmosphere.container.version.Jetty8WebSocket
17:02:36.891 [qtp533000440-18] INFO  o.a.t.PersonalPerRequestBroadcastFilter - PersonalPerRequestBroadcastFilter.filter(Object originalMessage, Object message)
17:02:39.197 [qtp533000440-18] INFO  o.a.tictactoe42a9x.TicTacToeGame - PerRequestBroadcastFilter.filter(HttpServletRequest request, HttpServletResponse response, Object message)
17:02:39.212 [qtp533000440-18] DEBUG o.a.container.JettyWebSocketUtil - Suspending response: AtmosphereResponse{cookies=[], headers={Content-Type=text/html; charset=ISO-8859-1}, asyncIOWriter=WSFrameConnection@17973271 l(127.0.0.1:8080)<->r(127.0.0.1:56478), status=200, statusMessage='OK', charSet='UTF-8', contentLength=-1, contentType='text/html', isCommited=false, locale=null, asyncProtocol=org.atmosphere.websocket.protocol.SimpleHttpProtocol@4770a4d0, headerHandled=false, atmosphereRequest=AtmosphereRequest{bis=null, br=null, pathInfo='/game/start', session=org.atmosphere.util.FakeHttpSession@34547854, methodType='GET', b=org.atmosphere.cpr.AtmosphereRequest$Builder@15a7eda3}, writeStatusAndHeader=false, delegateToNativeResponse=false, destroyable=false, response=org.atmosphere.cpr.Atmo
sphereResponse$DummyHttpServletResponse@43e27370}
17:02:41.833 [Atmosphere-BroadcasterConfig-0] INFO  o.a.t.PersonalPerRequestBroadcastFilter - PersonalPerRequestBroadcastFilter.filter(AtmosphereResource atmosphereResource, Object originalMessage, Object message)
17:02:43.341 [Atmosphere-BroadcasterConfig-0] INFO  o.a.tictactoe42a9x.TicTacToeGame - PerRequestBroadcastFilter.filter(AtmosphereResource atmosphereResource, Object originalMessage, Object message)

@jfarcand
Copy link
Member

Thanks for confirming! Keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants