Problems with Atmosphere and jQuery plugin

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with Atmosphere and jQuery plugin

stuart.roebuck
I'm having quite a bit of difficulty getting Atmosphere up and running and finding any documentation.

Is there anything equivalent to a Google group where people discuss issues?

On my web page I include the latest jquery.atmosphere.js plugin downloaded from the atmosphere git repository.

Once the page has loaded it tries to establish a socket connection with the server using this code:

var atmosphereResponse
var windowOrigin = window.location.protocol + "//" + window.location.host;

if (CONNECTION_METHOD == "ATMOSPHERE") {
    $(function() {
        if (DEBUG_MODE) $.atmosphere.request.logLevel = 'debug';
        $.atmosphere.subscribe(
            windowOrigin + "/atmosphere/connect/" + document.body.id.toString(),
            atmosphereCallback,
            $.atmosphere.request = {transport: "websocket", method: "POST"}
            );
        atmosphereResponse = $.atmosphere.response;
    });
};

function atmosphereCallback(response) {
    if (DEBUG_MODE) console.log("response.transport = " + response.transport);
    if (DEBUG_MODE) console.log("response.status = " + response.status);
    if (response.status = 200) {
        var message = response.responseBody;
        handleMessage(message);
    }
}

function atmosphereSend(x) {
    atmosphereResponse.push(
        windowOrigin + "/atmosphere/connect/" + document.body.id.toString(),
        atmosphereCallback,
        $.atmosphere.request = {data: "message=" + x} );
}

This appears to function, outputting the following to the browser console:

IN DEBUG MODE
CONNECTION_METHOD = ATMOSPHERE
Invoking executeWebSocket
Invoking 1 callbacks
response.transport = websocket
response.status = 200
Message = undefined
Invoking 1 callbacks
response.transport = websocket
response.status = 200
Message = undefined

On the server side the following Scala Scalatra code should received the "post" request and establish the 'suspended' connection:

class AtmosphereServlet extends ScalatraServlet with Logging {

  post("/connect/:pageId") {
    val pageId = params("pageId")
    logger.info("pageId = " + pageId)
    val m: Meteor = Meteor.build(request)
    m.addListener(EventsLogger)
    val b = new DefaultBroadcaster(pageId)
    b.setScope(Broadcaster.SCOPE.REQUEST)
    m.setBroadcaster(b)
    m.suspend(-1, false)
    ""
  }

}

I then have a somewhat longer EventsLogger object which extends AtmosphereResourceEventListener and logs anything and everything.

The server side is running under Jetty 7.4.x which appears to require Atmosphere 0.8-SNAPSHOT as it produced some other errors with 0.7.x which I traced to another post somewhere on the web.  So it is running 0.8-SNAPSHOT.

Here is the logging output:

30/164320 I      main          AtmosphereServlet| initializing atmosphere framework: 0.8-SNAPSHOT
30/164320 I      main          AtmosphereServlet| using default broadcaster class: class org.atmosphere.cpr.DefaultBroadcaster
30/164320 I      main          AtmosphereServlet| Atmosphere is using comet support: org.atmosphere.container.Jetty7CometSupport running under container: jetty/7.x.y-SNAPSHOT
30/164320 I      main          AtmosphereServlet| using broadcaster class: org.atmosphere.cpr.DefaultBroadcaster
30/164320 I      main  ReflectorServletProcessor| Installing Servlet com.proinnovate.webfunction.AtmosphereServlet
30/164320 I      main          AtmosphereServlet| started atmosphere framework: 0.8-SNAPSHOT
2011-08-30 16:43:20.590:INFO::Started [hidden email] STARTING
30/164321 I  Thread-5             AtmospherePing| AtmospherePing sent for project statistics: 404. Remove WEB-INF/lib/atmosphere-ping.jar to remove that message or exclude the jar in your pom.xml
30/164321 I  Thread-4             AtmospherePing| AtmospherePing sent for project statistics: 404. Remove WEB-INF/lib/atmosphere-ping.jar to remove that message or exclude the jar in your pom.xml
30/164348 I 829092-21          AtmosphereServlet| WebSocket upgrade requested
30/164348 D 829092-21      JettyWebSocketHandler| WebSocket.onHandshake
30/164348 I 829092-21         WebSocketProcessor| Atmosphere detected WebSocketSupport: org.atmosphere.websocket.container.Jetty8WebSocketSupport
30/164348 D 829092-21      AsynchronousProcessor| (suspend) invoked:
 HttpServletRequest: org.atmosphere.websocket.JettyWebSocketHandler$JettyRequestFix@5da631c2
 HttpServletResponse: org.atmosphere.websocket.WebSocketHttpServletResponse@4a0ce796

This, on the face of it appears to be okay.

But when I try to send anything to the server with the
atmosphereSend (above) I find that there is absolutely no sign of any message being received at the Server and no logging messages produced.

This is running under Safari and Chrome on Mac OS X.

Running under Firefox and Opera it selects the 'streaming' transport and creates a different error as it appears to try to re-establish the socket every time a message is sent rather than sending on the established socket.


I suspect that I simply don't understand what I should be doing here.

I would expect that once a connection has been made (using whatever transport is available) any calls to the `push` method would transmit a message on the established 'socket' and this would be received by the server side callback object on the `onBroadcast` method.  It appears that calling the `push` method is actually either doing nothing at all (under Websockets) or trying to do an ordinary POST (under streaming).

Any thoughts or suggestions.

Many thanks,

Stuart.

Reply | Threaded
Open this post in threaded view
|

Re: Problems with Atmosphere and jQuery plugin

java.net
Hi Stuart,

you have come to the right place to discuss your issues. You might want to consider joining the mailinglist.
Jean Francois is currently not active on the list, but he will come back to assist the users soon again.
Perhaps someone else with some experience on the jQuery client could help you out in the meantime.
(My experience is with the GWT module)
Pierre

On 30-8-2011 18:05, Stuart Roebuck wrote:
I'm having quite a bit of difficulty getting Atmosphere up and running and finding any documentation.

Is there anything equivalent to a Google group where people discuss issues?

On my web page I include the latest jquery.atmosphere.js plugin downloaded from the atmosphere git repository.

Once the page has loaded it tries to establish a socket connection with the server using this code:

var atmosphereResponse
var windowOrigin = window.location.protocol + "//" + window.location.host;

if (CONNECTION_METHOD == "ATMOSPHERE") {
    $(function() {
        if (DEBUG_MODE) $.atmosphere.request.logLevel = 'debug';
        $.atmosphere.subscribe(
            windowOrigin + "/atmosphere/connect/" + document.body.id.toString(),
            atmosphereCallback,
            $.atmosphere.request = {transport: "websocket", method: "POST"}
            );
        atmosphereResponse = $.atmosphere.response;
    });
};

function atmosphereCallback(response) {
    if (DEBUG_MODE) console.log("response.transport = " + response.transport);
    if (DEBUG_MODE) console.log("response.status = " + response.status);
    if (response.status = 200) {
        var message = response.responseBody;
        handleMessage(message);
    }
}

function atmosphereSend(x) {
    atmosphereResponse.push(
        windowOrigin + "/atmosphere/connect/" + document.body.id.toString(),
        atmosphereCallback,
        $.atmosphere.request = {data: "message=" + x} );
}

This appears to function, outputting the following to the browser console:

IN DEBUG MODE
CONNECTION_METHOD = ATMOSPHERE
Invoking executeWebSocket
Invoking 1 callbacks
response.transport = websocket
response.status = 200
Message = undefined
Invoking 1 callbacks
response.transport = websocket
response.status = 200
Message = undefined

On the server side the following Scala Scalatra code should received the "post" request and establish the 'suspended' connection:

class AtmosphereServlet extends ScalatraServlet with Logging {

  post("/connect/:pageId") {
    val pageId = params("pageId")
    logger.info("pageId = " + pageId)
    val m: Meteor = Meteor.build(request)
    m.addListener(EventsLogger)
    val b = new DefaultBroadcaster(pageId)
    b.setScope(Broadcaster.SCOPE.REQUEST)
    m.setBroadcaster(b)
    m.suspend(-1, false)
    ""
  }

}

I then have a somewhat longer EventsLogger object which extends AtmosphereResourceEventListener and logs anything and everything.

The server side is running under Jetty 7.4.x which appears to require Atmosphere 0.8-SNAPSHOT as it produced some other errors with 0.7.x which I traced to another post somewhere on the web.  So it is running 0.8-SNAPSHOT.

Here is the logging output:

30/164320 I      main          AtmosphereServlet| initializing atmosphere framework: 0.8-SNAPSHOT
30/164320 I      main          AtmosphereServlet| using default broadcaster class: class org.atmosphere.cpr.DefaultBroadcaster
30/164320 I      main          AtmosphereServlet| Atmosphere is using comet support: org.atmosphere.container.Jetty7CometSupport running under container: jetty/7.x.y-SNAPSHOT
30/164320 I      main          AtmosphereServlet| using broadcaster class: org.atmosphere.cpr.DefaultBroadcaster
30/164320 I      main  ReflectorServletProcessor| Installing Servlet com.proinnovate.webfunction.AtmosphereServlet
30/164320 I      main          AtmosphereServlet| started atmosphere framework: 0.8-SNAPSHOT
2011-08-30 16:43:20.590:INFO::Started [hidden email] STARTING
30/164321 I  Thread-5             AtmospherePing| AtmospherePing sent for project statistics: 404. Remove WEB-INF/lib/atmosphere-ping.jar to remove that message or exclude the jar in your pom.xml
30/164321 I  Thread-4             AtmospherePing| AtmospherePing sent for project statistics: 404. Remove WEB-INF/lib/atmosphere-ping.jar to remove that message or exclude the jar in your pom.xml
30/164348 I 829092-21          AtmosphereServlet| WebSocket upgrade requested
30/164348 D 829092-21      JettyWebSocketHandler| WebSocket.onHandshake
30/164348 I 829092-21         WebSocketProcessor| Atmosphere detected WebSocketSupport: org.atmosphere.websocket.container.Jetty8WebSocketSupport
30/164348 D 829092-21      AsynchronousProcessor| (suspend) invoked:
 HttpServletRequest: org.atmosphere.websocket.JettyWebSocketHandler$JettyRequestFix@5da631c2
 HttpServletResponse: org.atmosphere.websocket.WebSocketHttpServletResponse@4a0ce796

This, on the face of it appears to be okay.

But when I try to send anything to the server with the
atmosphereSend (above) I find that there is absolutely no sign of any message being received at the Server and no logging messages produced.

This is running under Safari and Chrome on Mac OS X.

Running under Firefox and Opera it selects the 'streaming' transport and creates a different error as it appears to try to re-establish the socket every time a message is sent rather than sending on the established socket.


I suspect that I simply don't understand what I should be doing here.

I would expect that once a connection has been made (using whatever transport is available) any calls to the `push` method would transmit a message on the established 'socket' and this would be received by the server side callback object on the `onBroadcast` method.  It appears that calling the `push` method is actually either doing nothing at all (under Websockets) or trying to do an ordinary POST (under streaming).

Any thoughts or suggestions.

Many thanks,

Stuart.

Reply | Threaded
Open this post in threaded view
|

Re: Re: Problems with Atmosphere and jQuery plugin

stuart.roebuck
In reply to this post by stuart.roebuck
Pierre,

Thanks for responding. I have joined the list.

I have a feeling that my problems could be as much to do with the
server side code as the jQuery atmosphere plugin code.

Could anyone confirm where I should expect to receive the messages on
the server after the socket connection has been established?  Should
they go straight to the callback or am I misunderstanding this?

Many thanks,

Stuart.
Reply | Threaded
Open this post in threaded view
|

[[atmosphere-users]] Re: Problems with Atmosphere and jQuery plugin

Jeanfrancois Arcand-4
In reply to this post by java.net
Hi Stuart,

your code look fine. Do you think you can share a test case? I'm not familair with Scalatra, but I suspect the issue is on the client side. One test you can try is to not subscribe but instead publish first and see if the server code gets invoked.

Thanks!

- Jeanfrancois

On 11-08-31 12:24 AM, [hidden email] wrote:
Hi Stuart,

you have come to the right place to discuss your issues. You might want to consider joining the mailinglist.
Jean Francois is currently not active on the list, but he will come back to assist the users soon again.
Perhaps someone else with some experience on the jQuery client could help you out in the meantime.
(My experience is with the GWT module)
Pierre

On 30-8-2011 18:05, Stuart Roebuck wrote:
I'm having quite a bit of difficulty getting Atmosphere up and running and finding any documentation.

Is there anything equivalent to a Google group where people discuss issues?

On my web page I include the latest jquery.atmosphere.js plugin downloaded from the atmosphere git repository.

Once the page has loaded it tries to establish a socket connection with the server using this code:

var atmosphereResponse
var windowOrigin = window.location.protocol + "//" + window.location.host;

if (CONNECTION_METHOD == "ATMOSPHERE") {
    $(function() {
        if (DEBUG_MODE) $.atmosphere.request.logLevel = 'debug';
        $.atmosphere.subscribe(
            windowOrigin + "/atmosphere/connect/" + document.body.id.toString(),
            atmosphereCallback,
            $.atmosphere.request = {transport: "websocket", method: "POST"}
            );
        atmosphereResponse = $.atmosphere.response;
    });
};

function atmosphereCallback(response) {
    if (DEBUG_MODE) console.log("response.transport = " + response.transport);
    if (DEBUG_MODE) console.log("response.status = " + response.status);
    if (response.status = 200) {
        var message = response.responseBody;
        handleMessage(message);
    }
}

function atmosphereSend(x) {
    atmosphereResponse.push(
        windowOrigin + "/atmosphere/connect/" + document.body.id.toString(),
        atmosphereCallback,
        $.atmosphere.request = {data: "message=" + x} );
}

This appears to function, outputting the following to the browser console:

IN DEBUG MODE
CONNECTION_METHOD = ATMOSPHERE
Invoking executeWebSocket
Invoking 1 callbacks
response.transport = websocket
response.status = 200
Message = undefined
Invoking 1 callbacks
response.transport = websocket
response.status = 200
Message = undefined

On the server side the following Scala Scalatra code should received the "post" request and establish the 'suspended' connection:

class AtmosphereServlet extends ScalatraServlet with Logging {

  post("/connect/:pageId") {
    val pageId = params("pageId")
    logger.info("pageId = " + pageId)
    val m: Meteor = Meteor.build(request)
    m.addListener(EventsLogger)
    val b = new DefaultBroadcaster(pageId)
    b.setScope(Broadcaster.SCOPE.REQUEST)
    m.setBroadcaster(b)
    m.suspend(-1, false)
    ""
  }

}

I then have a somewhat longer EventsLogger object which extends AtmosphereResourceEventListener and logs anything and everything.

The server side is running under Jetty 7.4.x which appears to require Atmosphere 0.8-SNAPSHOT as it produced some other errors with 0.7.x which I traced to another post somewhere on the web.  So it is running 0.8-SNAPSHOT.

Here is the logging output:

30/164320 I      main          AtmosphereServlet| initializing atmosphere framework: 0.8-SNAPSHOT
30/164320 I      main          AtmosphereServlet| using default broadcaster class: class org.atmosphere.cpr.DefaultBroadcaster
30/164320 I      main          AtmosphereServlet| Atmosphere is using comet support: org.atmosphere.container.Jetty7CometSupport running under container: jetty/7.x.y-SNAPSHOT
30/164320 I      main          AtmosphereServlet| using broadcaster class: org.atmosphere.cpr.DefaultBroadcaster
30/164320 I      main  ReflectorServletProcessor| Installing Servlet com.proinnovate.webfunction.AtmosphereServlet
30/164320 I      main          AtmosphereServlet| started atmosphere framework: 0.8-SNAPSHOT
2011-08-30 16:43:20.590:INFO::Started [hidden email] STARTING
30/164321 I  Thread-5             AtmospherePing| AtmospherePing sent for project statistics: 404. Remove WEB-INF/lib/atmosphere-ping.jar to remove that message or exclude the jar in your pom.xml
30/164321 I  Thread-4             AtmospherePing| AtmospherePing sent for project statistics: 404. Remove WEB-INF/lib/atmosphere-ping.jar to remove that message or exclude the jar in your pom.xml
30/164348 I 829092-21          AtmosphereServlet| WebSocket upgrade requested
30/164348 D 829092-21      JettyWebSocketHandler| WebSocket.onHandshake
30/164348 I 829092-21         WebSocketProcessor| Atmosphere detected WebSocketSupport: org.atmosphere.websocket.container.Jetty8WebSocketSupport
30/164348 D 829092-21      AsynchronousProcessor| (suspend) invoked:
 HttpServletRequest: org.atmosphere.websocket.JettyWebSocketHandler$JettyRequestFix@5da631c2
 HttpServletResponse: org.atmosphere.websocket.WebSocketHttpServletResponse@4a0ce796

This, on the face of it appears to be okay.

But when I try to send anything to the server with the
atmosphereSend (above) I find that there is absolutely no sign of any message being received at the Server and no logging messages produced.

This is running under Safari and Chrome on Mac OS X.

Running under Firefox and Opera it selects the 'streaming' transport and creates a different error as it appears to try to re-establish the socket every time a message is sent rather than sending on the established socket.


I suspect that I simply don't understand what I should be doing here.

I would expect that once a connection has been made (using whatever transport is available) any calls to the `push` method would transmit a message on the established 'socket' and this would be received by the server side callback object on the `onBroadcast` method.  It appears that calling the `push` method is actually either doing nothing at all (under Websockets) or trying to do an ordinary POST (under streaming).

Any thoughts or suggestions.

Many thanks,

Stuart.

Reply | Threaded
Open this post in threaded view
|

[[atmosphere-users]] Re: Problems with Atmosphere and jQuery plugin

Jeanfrancois Arcand-4
In reply to this post by stuart.roebuck
Salut,

On 11-08-31 1:47 PM, [hidden email] wrote:

> Pierre,
>
> Thanks for responding. I have joined the list.
>
> I have a feeling that my problems could be as much to do with the
> server side code as the jQuery atmosphere plugin code.
>
> Could anyone confirm where I should expect to receive the messages on
> the server after the socket connection has been established?  Should
> they go straight to the callback or am I misunderstanding this?
You understand it properly. The message send via the publish call should:

publish -> server -> client executes the callback.

Thanks

-- Jeanfrancois




>
> Many thanks,
>
> Stuart.
Reply | Threaded
Open this post in threaded view
|

[atmosphere-users] Re: [] Re: Problems with Atmosphere and jQuery plugin

Stuart Roebuck-2
In reply to this post by Jeanfrancois Arcand-4
Jeanfrancois,

Goodness, you've been busy this morning.

Please ignore this query as I subsequently turned this into a standalone case which you have also responded to.  I'll review that one too when I'm back in work tomorrow.

Great to know you are back! :)

Stuart

On 19 Sep 2011, at 12:00 AM, Jeanfrancois Arcand <[hidden email]> wrote:

Hi Stuart,

your code look fine. Do you think you can share a test case? I'm not familair with Scalatra, but I suspect the issue is on the client side. One test you can try is to not subscribe but instead publish first and see if the server code gets invoked.

Thanks!

- Jeanfrancois

On 11-08-31 12:24 AM, [hidden email] wrote:
Hi Stuart,

you have come to the right place to discuss your issues. You might want to consider joining the mailinglist.
Jean Francois is currently not active on the list, but he will come back to assist the users soon again.
Perhaps someone else with some experience on the jQuery client could help you out in the meantime.
(My experience is with the GWT module)
Pierre

On 30-8-2011 18:05, Stuart Roebuck wrote:
I'm having quite a bit of difficulty getting Atmosphere up and running and finding any documentation.

Is there anything equivalent to a Google group where people discuss issues?

On my web page I include the latest jquery.atmosphere.js plugin downloaded from the atmosphere git repository.

Once the page has loaded it tries to establish a socket connection with the server using this code:

var atmosphereResponse
var windowOrigin = window.location.protocol + "//" + window.location.host;

if (CONNECTION_METHOD == "ATMOSPHERE") {
    $(function() {
        if (DEBUG_MODE) $.atmosphere.request.logLevel = 'debug';
        $.atmosphere.subscribe(
            windowOrigin + "/atmosphere/connect/" + document.body.id.toString(),
            atmosphereCallback,
            $.atmosphere.request = {transport: "websocket", method: "POST"}
            );
        atmosphereResponse = $.atmosphere.response;
    });
};

function atmosphereCallback(response) {
    if (DEBUG_MODE) console.log("response.transport = " + response.transport);
    if (DEBUG_MODE) console.log("response.status = " + response.status);
    if (response.status = 200) {
        var message = response.responseBody;
        handleMessage(message);
    }
}

function atmosphereSend(x) {
    atmosphereResponse.push(
        windowOrigin + "/atmosphere/connect/" + document.body.id.toString(),
        atmosphereCallback,
        $.atmosphere.request = {data: "message=" + x} );
}

This appears to function, outputting the following to the browser console:

IN DEBUG MODE
CONNECTION_METHOD = ATMOSPHERE
Invoking executeWebSocket
Invoking 1 callbacks
response.transport = websocket
response.status = 200
Message = undefined
Invoking 1 callbacks
response.transport = websocket
response.status = 200
Message = undefined

On the server side the following Scala Scalatra code should received the "post" request and establish the 'suspended' connection:

class AtmosphereServlet extends ScalatraServlet with Logging {

  post("/connect/:pageId") {
    val pageId = params("pageId")
    logger.info("pageId = " + pageId)
    val m: Meteor = Meteor.build(request)
    m.addListener(EventsLogger)
    val b = new DefaultBroadcaster(pageId)
    b.setScope(Broadcaster.SCOPE.REQUEST)
    m.setBroadcaster(b)
    m.suspend(-1, false)
    ""
  }

}

I then have a somewhat longer EventsLogger object which extends AtmosphereResourceEventListener and logs anything and everything.

The server side is running under Jetty 7.4.x which appears to require Atmosphere 0.8-SNAPSHOT as it produced some other errors with 0.7.x which I traced to another post somewhere on the web.  So it is running 0.8-SNAPSHOT.

Here is the logging output:

30/164320 I      main          AtmosphereServlet| initializing atmosphere framework: 0.8-SNAPSHOT
30/164320 I      main          AtmosphereServlet| using default broadcaster class: class org.atmosphere.cpr.DefaultBroadcaster
30/164320 I      main          AtmosphereServlet| Atmosphere is using comet support: org.atmosphere.container.Jetty7CometSupport running under container: jetty/7.x.y-SNAPSHOT
30/164320 I      main          AtmosphereServlet| using broadcaster class: org.atmosphere.cpr.DefaultBroadcaster
30/164320 I      main  ReflectorServletProcessor| Installing Servlet com.proinnovate.webfunction.AtmosphereServlet
30/164320 I      main          AtmosphereServlet| started atmosphere framework: 0.8-SNAPSHOT
2011-08-30 16:43:20.590:INFO::Started [hidden email] STARTING
30/164321 I  Thread-5             AtmospherePing| AtmospherePing sent for project statistics: 404. Remove WEB-INF/lib/atmosphere-ping.jar to remove that message or exclude the jar in your pom.xml
30/164321 I  Thread-4             AtmospherePing| AtmospherePing sent for project statistics: 404. Remove WEB-INF/lib/atmosphere-ping.jar to remove that message or exclude the jar in your pom.xml
30/164348 I 829092-21          AtmosphereServlet| WebSocket upgrade requested
30/164348 D 829092-21      JettyWebSocketHandler| WebSocket.onHandshake
30/164348 I 829092-21         WebSocketProcessor| Atmosphere detected WebSocketSupport: org.atmosphere.websocket.container.Jetty8WebSocketSupport
30/164348 D 829092-21      AsynchronousProcessor| (suspend) invoked:
 HttpServletRequest: org.atmosphere.websocket.JettyWebSocketHandler$JettyRequestFix@5da631c2
 HttpServletResponse: org.atmosphere.websocket.WebSocketHttpServletResponse@4a0ce796

This, on the face of it appears to be okay.

But when I try to send anything to the server with the
atmosphereSend (above) I find that there is absolutely no sign of any message being received at the Server and no logging messages produced.

This is running under Safari and Chrome on Mac OS X.

Running under Firefox and Opera it selects the 'streaming' transport and creates a different error as it appears to try to re-establish the socket every time a message is sent rather than sending on the established socket.


I suspect that I simply don't understand what I should be doing here.

I would expect that once a connection has been made (using whatever transport is available) any calls to the `push` method would transmit a message on the established 'socket' and this would be received by the server side callback object on the `onBroadcast` method.  It appears that calling the `push` method is actually either doing nothing at all (under Websockets) or trying to do an ordinary POST (under streaming).

Any thoughts or suggestions.

Many thanks,

Stuart.