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

each request from the same client returns a different AtmosphereResource #488

Closed
PavelR577 opened this issue Jul 7, 2012 · 13 comments
Closed

Comments

@PavelR577
Copy link

tested on tomcat 7.0.28 64bit
windows xp/7 64bit
atmosphere 1.0.0.beta2a (0.9.4 as well)
spring 2.5.4 (spring 3 tested and got the same result)

  1. client creates a websocket and subscribes to channel1 and channel2 and we suspend the resource.
  2. client wants to unsubscribe from channel1 so he sends a POST using the same websocket - the AtmosphereResource that we get from the response is different from step1 so we can't unsubscribe him since we don't have his resource.

current work around - save the resource in a map on creation of the websocket and then we can access it later on.

To my knowledge the resource should be same for each POST from the same client (in other words it should persist per client).

@jfarcand
Copy link
Member

jfarcand commented Jul 7, 2012

The only issue I see what that approach is the AtmosphereResource has a reference to an AtmosphereRequest. The AtmosphereResource will needs to be updated on every new message with a new AtmosphereRequest instance (so you can read the message body). Looking....

@pierreh
Copy link

pierreh commented Jul 9, 2012

A better solution would be to send the AtmosphereResource UUID to the
client and that way you can use it to disconnect the connection.
The current default implementation of the WebsocketProtocol is in such a
way that it will give the same behaviour for the jquery and the gwt
client regardless of whether websockets or XHR are used to post to the
server.

On 7-7-2012 16:13, poi212003 wrote:

tested on tomcat 7.0.28 64bit
windows xp/7 64bit
atmosphere 1.0.0.beta2a (0.9.4 as well)
spring 2.5.4 (spring 3 tested and got the same result)

  1. client creates a websocket and subscribes to channel1 and channel2 and we suspend the resource.
  2. client wants to unsubscribe from channel1 so he sends a POST using the same websocket - the AtmosphereResource that we get from the response is different from step1 so we can't unsubscribe him since we don't have his resource.

current work around - save the resource in a map on creation of the websocket and then we can access it later on.

To my knowledge the resource should be same for each POST from the same client (in other words it should persist per client).


Reply to this email directly or view it on GitHub:
#488

jfarcand added a commit that referenced this issue Jul 9, 2012
@jfarcand
Copy link
Member

jfarcand commented Jul 9, 2012

@pierreh That would implies a new protocol where some information are sent back to the client after the handshake and as a WebSocket message. This is doable, but I prefer not to change anything for now.

@poi212003 Fixed, just retrieve the following attribute form any AtmosphereRequest

org.atmosphere.cpr.AtmosphereResource.webSocket.handshake

and the use the AtmosphereResourceFactory to retrieve the original AtmosphereResource.

@jfarcand jfarcand closed this as completed Jul 9, 2012
@PavelR577
Copy link
Author

working great!!
thanks!

@PavelR577
Copy link
Author

a small bug - this attribute is not passed to the events (for example in the disconnect event I can't get it - it's always null)

@jfarcand
Copy link
Member

Can you elaborate? On which Request are you setting the attribute? The first one?

@PavelR577
Copy link
Author

I'm trying to get the uuid of the original request by getting this attribute:
org.atmosphere.cpr.AtmosphereResource.webSocket.handshake

When the user performs POST on the websocket, I'm able to get this attribute and retrieve the original resource,
but when the user closes the page for example or disocnnects and the diconnect event fires:

@OverRide
public void onDisconnect(AtmosphereResourceEvent event) {
//this doesnt work - returns a different handshake compared to the POST
event.getResource().getRequest().getAttribute("org.atmosphere.cpr.AtmosphereResource.webSocket.handshake");
super.onDisconnect(event); //To change body of overridden methods use File | Settings | File Templates.
}
I cant get the original uuid.

Hope that's clear

@PavelR577
Copy link
Author

did you get to test it?

@jfarcand
Copy link
Member

@poi212003 Yes, and also responded on the mailing list. I do have a test case that works as well.

@PavelR577
Copy link
Author

ok - it looks like something else is messing it up - after I create a websocket then I refresh the page a new websocket it automatically created (I'm not doing anything at this point on the client side) and then the disconnect gets the uuid of the new websocket.

Can I control this? i dont want it to open a websocket automatically.

@PavelR577
Copy link
Author

tested on firefox

@jfarcand
Copy link
Member

@poi212003 Let's use the mailing list for questions :-) You just need to implement the onReconnect(request,response) function and close the request so no re-connect. Take a look at this

@PavelR577
Copy link
Author

works like a charm! :)

Thanks.

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

3 participants