Git Product home page Git Product logo

atmosphere-play's Introduction

Playtosphere: Atmosphere for Play!

This project brings the Atmosphere Framework to the Play! Framework.

For Play 3.0+ and Atmosphere 3.0+:

     <dependency>
         <groupId>org.atmosphere</groupId>
         <artifactId>atmosphere-play</artifactId>
         <version>3.0.0</version>
     </dependency>

For Play 2.8.x+ and Atmosphere 2.7+:

     <dependency>
         <groupId>org.atmosphere</groupId>
         <artifactId>atmosphere-play</artifactId>
         <version>2.6.0</version>
     </dependency>

Server side using atmosphere-runtime

@ManagedService(path = "/chat")
public class Chat {
    private final Logger logger = LoggerFactory.getLogger(Chat.class);

    /**
     * Invoked when the connection as been fully established and suspended, e.g ready for receiving messages.
     *
     * @param r
     */
    @Ready
    public void onReady(final AtmosphereResource r) {
        logger.info("Browser {} connected.", r.uuid());
    }

    /**
     * Invoked when the client disconnect or when an unexpected closing of the underlying connection happens.
     *
     * @param event
     */
    @Disconnect
    public void onDisconnect(AtmosphereResourceEvent event) {
        if (event.isCancelled()) {
            logger.info("Browser {} unexpectedly disconnected", event.getResource().uuid());
        } else if (event.isClosedByClient()) {
            logger.info("Browser {} closed the connection", event.getResource().uuid());
        }
    }

    /**
     * Simple annotated class that demonstrate how {@link org.atmosphere.config.managed.Encoder} and {@link org.atmosphere.config.managed.Decoder
     * can be used.
     *
     * @param message an instance of {@link Message}
     * @return
     * @throws IOException
     */
    @org.atmosphere.config.service.Message(encoders = {JacksonEncoder.class}, decoders = {JacksonDecoder.class})
    public Message onMessage(Message message) throws IOException {
        logger.info("{} just send {}", message.getAuthor(), message.getMessage());
        return message;
    }

and on the client side,

    $(function () {
        "use strict";

        var header = $('#header');
        var content = $('#content');
        var input = $('#input');
        var status = $('#status');
        var myName = false;
        var author = null;
        var logged = false;
        var socket = $.atmosphere;
        var subSocket;
        var transport = 'websocket';

        // We are now ready to cut the request
        var request = { url: document.location.toString() + 'chat',
            contentType : "application/json",
            logLevel : 'debug',
            transport : transport ,
            trackMessageLength : true,
            fallbackTransport: 'websocket'};


        request.onMessage = function (response) {

             // do something
        };

        request.onClose = function(response) {
        };

        request.onError = function(response) {
        };

        subSocket = socket.subscribe(request);

atmosphere-play's People

Contributors

dependabot[bot] avatar dsimonov-idnow avatar flowersinthesand avatar iulian-udrea-idnow avatar jfarcand avatar kbarzen-idn avatar manipah avatar mickgiles avatar pedrobatista avatar petr-kolesnikov-idnow avatar pluppens avatar rafalfaron avatar srnm avatar stegmannc avatar vilyam avatar vuong-idnow avatar yousef-khanbabaei-idnow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atmosphere-play's Issues

Play Framework Chat example: client not receiving message from server

Hi all,

I'm using Play Framework 2.2.1 for one of my projects and I'm now trying Atmosphere for the first time.
I'm quite new to it, have been reading about it for a couple of days now, and I'm trying the chat sample.

I can get the client to connect to the server using websocket, and the server is receiving the messages from the client side, but the opposite is not happening. The request.onMessage is never triggered.

Also, I get the following exceptions (everytime a connection is closed/lost, I believe).

[error] o.j.p.UDP - JGRP000029: sergio-PORTEGE-R830-1936: failed sending message to cluster (377 bytes): java.lang.Exception: dest=/ff0e:0:0:0:0:8:8:8:45588 (380 bytes), headers: NAKACK2: [MSG, seqno=11], UDP: [channel_name=/chat]
[debug] o.a.i.OnDisconnectInterceptor - AtmosphereResource fa3f9e84-b852-4c4b-ba40-cd378118be94 disconnected
[info] application - Browser fa3f9e84-b852-4c4b-ba40-cd378118be94 closed the connection
[error] o.a.p.AtmosphereCoordinator - Unable to process request
java.lang.NoSuchFieldError: ASYNCHRONOUS_HOOK
at org.atmosphere.play.AtmosphereCoordinator.route(AtmosphereCoordinator.java:106) ~[atmosphere-play-1.2.0.jar:na]
at org.atmosphere.play.PlayAsyncIOWriter$1.onReady(PlayAsyncIOWriter.java:70) [atmosphere-play-1.2.0.jar:na]
at play.mvc.Results$Chunks$1.invoke(Results.java:1098) [play_2.10.jar:2.2.2]
at play.mvc.Results$Chunks$1.invoke(Results.java:1094) [play_2.10.jar:2.2.2]
at play.core.j.JavaResults$$anon$1.apply(JavaResults.scala:39) [play_2.10.jar:2.2.2]
at play.api.libs.iteratee.Enumerator$class.$bar$greater$greater(Enumerator.scala:34) [play-iteratees_2.10.jar:2.2.2]
[debug] o.a.w.DefaultWebSocketProcessor - Unable to properly complete fa3f9e84-b852-4c4b-ba40-cd378118be94
[error] play - Exception is Chunks disconnected callback
java.lang.NoSuchFieldError: ASYNCHRONOUS_HOOK
at org.atmosphere.play.PlayAsyncIOWriter._close(PlayAsyncIOWriter.java:166) ~[atmosphere-play-1.2.0.jar:na]
at org.atmosphere.play.PlayAsyncIOWriter.access$000(PlayAsyncIOWriter.java:38) ~[atmosphere-play-1.2.0.jar:na]
at org.atmosphere.play.PlayAsyncIOWriter$1$1.invoke(PlayAsyncIOWriter.java:62) ~[atmosphere-play-1.2.0.jar:na]
at play.mvc.Results$Chunks$2.invoke(Results.java:1105) ~[play_2.10.jar:2.2.2]
at play.core.j.JavaResults$$anon$1$$anonfun$1.apply$mcV$sp(JavaResults.scala:35) [play_2.10.jar:2.2.2]
at play.api.libs.iteratee.Enumerator$$anon$4$$anonfun$apply$1.applyOrElse(Enumerator.scala:113) [play-iteratees_2.10.jar:2.2.2]

Here's my build.sbt file, concerning atmosphere:

"org.atmosphere" % "atmosphere-play" % "1.2.0" exclude("org.atmosphere", "atmosphere-runtime") withSources(),
"org.atmosphere" % "atmosphere-runtime" % "2.2.0" withSources(),
"org.atmosphere" % "atmosphere-jgroups" % "2.2.0" exclude("org.atmosphere", "atmosphere-runtime"),
"org.jgroups" % "jgroups" % "3.4.5.Final" withSources(),
"javax.servlet" % "javax.servlet-api" % "3.1.0" withSources()

Can someone please explain why the client is not getting the messages from the server?

This is what the onMessage looks like:

@org.atmosphere.config.service.Message(encoders = { JacksonEncoder.class }, decoders = { JacksonDecoder.class })
public Message onMessage(Message message) throws IOException {
logger.info("{} just send {}", message.getAuthor(),
message.getMessage());
return message;
}

Regards,

Sérgio Vasconcelos

Play session not available to ManagedService in development mode

As the site I'm building uses logged-in features, I need to be able to authenticate users that use the Atmosphere functionality, but it seems that the Play session is not available to the ManagedService in dev mode, nor can I get it through the AtmosphereResource.
I've tried using the play session converter, but it doesn't work in dev mode and it makes it alot harder to develop if I have to use release mode to develop. As the session is just a Map<String, String> object, couldn't the AtmosphereController try to convert it with a standard converter if it finds no supplied one?

Here is the error message I receive when trying to use a play session converter in dev mode:

! @72jj3obh3 - Internal server error, for (GET) [/poll?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.3.2-javascript&X-Atmosphere-Transport=long-polling&X-Atmosphere-TrackMessageSize=true&Content-Type=application%2Fjson&X-atmo-protocol=true&_=1483950018894] ->

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[ProvisionException: Unable to provision, see the following errors:

  1. Error injecting constructor, java.lang.ClassNotFoundException: controllers.SessionHandler
    at org.atmosphere.play.AtmosphereController.(AtmosphereController.java:35)
    while locating org.atmosphere.play.AtmosphereController

1 error]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:280)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:206)
at play.core.server.Server$class.logExceptionAndGetResult$1(Server.scala:45)
at play.core.server.Server$class.getHandlerFor(Server.scala:65)
at play.core.server.NettyServer.getHandlerFor(NettyServer.scala:47)
at play.core.server.netty.PlayRequestHandler.handle(PlayRequestHandler.scala:82)
at play.core.server.netty.PlayRequestHandler.channelRead(PlayRequestHandler.scala:163)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
Caused by: com.google.inject.ProvisionException: Unable to provision, see the following errors:

  1. Error injecting constructor, java.lang.ClassNotFoundException: controllers.SessionHandler
    at org.atmosphere.play.AtmosphereController.(AtmosphereController.java:35)
    while locating org.atmosphere.play.AtmosphereController

1 error
at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:405)
at org.atmosphere.play.AtmosphereHttpRequestHandler.dispatch(AtmosphereHttpRequestHandler.scala:45)
at org.atmosphere.play.AtmosphereHttpRequestHandler.dispatch(AtmosphereHttpRequestHandler.scala:81)
at org.atmosphere.play.AtmosphereHttpRequestHandler.dispatch(AtmosphereHttpRequestHandler.scala:76)
at org.atmosphere.play.AtmosphereHttpRequestHandler.routeRequest(AtmosphereHttpRequestHandler.scala:24)
at play.api.http.DefaultHttpRequestHandler.handlerForRequest(HttpRequestHandler.scala:118)
at play.core.server.Server$class.getHandlerFor(Server.scala:55)
at play.core.server.NettyServer.getHandlerFor(NettyServer.scala:47)
Caused by: java.lang.ClassNotFoundException: controllers.SessionHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.atmosphere.util.IOUtils.loadClass(IOUtils.java:370)
at org.atmosphere.play.AtmosphereController.(AtmosphereController.java:42)
at org.atmosphere.play.AtmosphereController$$FastClassByGuice$$5c257ff6.newInstance()
at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)
at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:61)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)

Example on front page does not work.

Play Framework 2.5.4, atmosphere-play 2.3.0

Used the chat code from the front page of this project, get handshake errors when trying to connect websocket.
WebSocket connection to 'ws://localhost:9000/chat?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.3.2-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&Content-Type=application/json&X-atmo-protocol=true' failed: Error during WebSocket handshake: Unexpected response code: 404

java.lang.NoSuchFieldError: ASYNCHRONOUS_HOOK

Getting this with current master branch and atmosphere-runtime 2.2.0-SNAPSHOT ... Cannot seem to find any version of atmosphere runtime where ASYNCHRONOUS_HOOK is a valid field

[error] o.a.p.AtmosphereCoordinator - Unable to process request
java.lang.NoSuchFieldError: ASYNCHRONOUS_HOOK
        at org.atmosphere.play.AtmosphereCoordinator.route(AtmosphereCoordinator.java:106) ~[atmosphere-play-2.0.0-SNAPSHOT.jar:na]
        at org.atmosphere.play.PlayAsyncIOWriter$1.onReady(PlayAsyncIOWriter.java:70) [atmosphere-play-2.0.0-SNAPSHOT.jar:na]
        at play.mvc.Results$Chunks$1.invoke(Results.java:1083) [play_2.11-2.3.1.jar:2.3.1]
        at play.mvc.Results$Chunks$1.invoke(Results.java:1079) [play_2.11-2.3.1.jar:2.3.1]
        at play.core.j.JavaResults$$anonfun$chunked$2.apply(JavaResults.scala:38) [play_2.11-2.3.1.jar:2.3.1]
Uncaught error from thread [play-akka.actor.default-dispatcher-5] shutting down JVM since 'akka.jvm-exit-on

Play scala NoClassDefFoundError: play/mvc/Results$Status

I use the atmosphere-play for a play-scala project, when I connect the server use websocket, I get some error like:

java.lang.NoClassDefFoundError: play/mvc/Results$Status
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2658)
    at java.lang.Class.getDeclaredConstructors(Class.java:2007)
    at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:245)
    at com.google.inject.internal.ConstructorBindingImpl.create(ConstructorBindingImpl.java:99)
    at com.google.inject.internal.InjectorImpl.createUninitializedBinding(InjectorImpl.java:658)
    at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:882)
    at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:805)
    at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:282)
    at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:214)
Caused by: java.lang.ClassNotFoundException: play.mvc.Results$Status
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2658)
    at java.lang.Class.getDeclaredConstructors(Class.java:2007)
    at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:245)

here is the source:
Chat.scala

@Singleton
@ManagedService(path = "/chat")
class Chat @Inject() extends AtmosphereController {
  private val logger = LoggerFactory.getLogger("circle")

  @Ready
  def onReady(resource: AtmosphereResource) = {
    logger.info("Browser {} connected.", resource.uuid())

  }

  @Disconnect
  def onDisconnected(event: AtmosphereResourceEvent) = {
    if (event.isCancelled) {
      logger.info("Browser {} unexpectedly disconnected", event.getResource.uuid())
    } else if (event.isClosedByClient) {
      logger.info("Browser {} closed the connection", event.getResource.uuid())
    }
  }

  @org.atmosphere.config.service.Message
  def onMessage(message: String) = {
    logger.info("message {}", message)
  }

}

GlobalSetting.scala

@Singleton
class GlobalSetting @Inject()(appLifecycle: ApplicationLifecycle) {
  AtmosphereCoordinator.instance().discover(classOf[CircleController]).ready()

  appLifecycle.addStopHook { () =>
    AtmosphereCoordinator.instance().shutdown()
    Future.successful(())
  }

}

build.sbt

libraryDependencies ++= Seq(
  jdbc,
  cache,
  ws,
  "org.scalatestplus.play" %% "scalatestplus-play" % "1.5.0-RC1" % Test,
  "org.atmosphere" % "atmosphere-play" % "2.2.0",
  "org.atmosphere" % "atmosphere-runtime" % "2.4.3",
  "org.atmosphere" % "atmosphere-guice" % "2.4.2"
)

Null pointer exception from PlayAsyncIOWriter

When using long-polling, on closing the web-page, a null pointer exception is thrown from PlayAsyncIOWriter._close(). This doesn't happen with websocket. The log output is at end of this comment.

I'm using @managedservice(path='/ws'), and broadcasting server messages with broadcaster '/ws' and per-request-broadcaster-filter, which checks a header on the resource request. The managed service is just logging arguments to methods for @ready @resume and @disconnect. Is there anything I can do to prevent this exception? Is it safe to run in production with this exception happening? Thanks in advance for your help.

Here's the log output:

[error] play at [Play] - Exception is Chunks disconnected callback
java.lang.NullPointerException: null
    at org.atmosphere.play.PlayAsyncIOWriter._close(PlayAsyncIOWriter.java:171) ~[atmosphere-play-1.2.0.jar:na]
    at org.atmosphere.play.PlayAsyncIOWriter.access$000(PlayAsyncIOWriter.java:38) ~[atmosphere-play-1.2.0.jar:na]
    at org.atmosphere.play.PlayAsyncIOWriter$1$1.invoke(PlayAsyncIOWriter.java:62) ~[atmosphere-play-1.2.0.jar:na]
    at play.mvc.Results$Chunks$2.invoke(Results.java:1105) ~[play_2.10.jar:2.2.3]
    at play.core.j.JavaResults$$anon$1$$anonfun$1.apply$mcV$sp(JavaResults.scala:35) [play_2.10.jar:2.2.3]
    at play.api.libs.iteratee.Enumerator$$anon$4$$anonfun$apply$1.applyOrElse(Enumerator.scala:113) [play-iteratees_2.10.jar:2.2.3]

Is the dependency on servlet-api 2.5 outdated?

Hi,

When I'm starting play and request a site, play crashes with

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeader

As this method was introduced in servlet-api 3.0 (javadoc), I guess that the dependency on 2.5 is outdated.
I'm using this workaround in my build.sbt dependencies to fix it:

    "org.atmosphere" % "atmosphere-play" % "2.1.1" exclude("javax.servlet", "servlet-api"),
    "javax.servlet" % "javax.servlet-api" % "3.1.0",

It would be nice to see this fixed.

Thank you!

ManagedService path ignores application.context parameter

Hello,

@ManagedService(path = "/ws/agent/{id}")
public class UserSocketActor {
    // Something else
}

This works as expected. However, if you set the configuration property application.context that won't work.

application.context defines a prefix path for all requests to that application. It looks like your ManagerdService path ignores it.

Can this be changed somehow, to be relative to the context?

@Disconnect annotation never invoked

In https://github.com/Atmosphere/atmosphere-play/blob/master/module/src/main/java/org/atmosphere/play/PlayWebSocket.java#L53 the socket is always closed with code 1002 however in https://github.com/Atmosphere/atmosphere/blob/master/modules/cpr/src/main/java/org/atmosphere/websocket/DefaultWebSocketProcessor.java#L647 that close code is not allowed...

private boolean allowedCloseCode(int closeCode) {
        return closeCode < 1002 || closeCode > 1004 ? true : false;
}

possibly related to Atmosphere/atmosphere#1636

Creation of several concurrent SSE connections doesn't work

The code of atmosphere-samples/play-samples/chat was modified to use SSE transport and create 10 chat rooms on single page.

It turns out, that if >5 connections are opened, connections become broken (browser shows some connections in "PENDING" state).

In that state we can't send user name/messages etc - everything stops working.
If # of subscriptions (chats) is reduced to 2 (3 .. up to 5) - it seems to be workable.

Source code of the modified sample: https://www.dropbox.com/s/3bghaxv2o6file2/chat.zip?dl=0

Atmosphere crashes on development reload

Hello

I'm using latest version of atmosphere play with Play 2.2.1. When developing, the server restarts but I get an exception and atmosphere stops to work.

Is this normal? Must I add additional code to reload atmosphere on server reload?

Support Play 2.2

Support Play 2.1.2+

flowersinthesand/portal-java#96
play.core.j.JavaAction that is an one of bridge object between Play's scala API and java API is changed incompatibly in 2.1.2. I checked it work with 2.1.5 which is a latest 2.1.x. The following commit restricts the minimum latest version to be 2.1.2.

flowersinthesand/portal-java@48a9adb

Support Play 2.2

flowersinthesand/portal-java#94
play.core.j.JavaAction is changed incompatbly again in 2.2.0. Also, many things have to be changed to migrate. The following gist contains such diff for migration: https://gist.github.com/flowersinthesand/6789935

Most of all, the problem is a change in Handlers.scala I have to provide (Router.scala in atmosphere-play)
https://gist.github.com/flowersinthesand/6789935#file-migration-patch-L14-L54 To be more exact, JavaAction's invocation is changed from play.mvc.Result to play.libs.F.Promise[play.mvc.Result].

If we can provide both type, it may be able to support both 2.1.2+ and 2.2+. But, I coudln't find the solution and I haven't done scala. Can you chek if it's possible? If not, we may have to create a new project for supporting 2.1.2+ or force the user to use 2.2 only.

Long polling not working in play 2.6.x with atmosphere-play 2.4.0

Tested from test application. Long-polling not working, it throws ERR_INCOMPLETE_CHUNKED_ENCODING. Could you please confirm if this is an issue or any configuration missing.

https://localhost:9443/chat?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=3.0.5-javascript&X-Atmosphere-Transport=long-polling&X-Atmosphere-TrackMessageSize=true&Content-Type=application%2Fjson&X-atmo-protocol=true&_=1594021894645 net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)

long-polling and jsonp transport produces duplicate messages in sample chat application

That happened with 'chat' application from the 'play-samples' folder of
atmosphere-samples.

If the transport is changed to jsonp or long-polling inside index.scala.html, each new text message is received and displayed twice in the browser, although Chat.onMessage() is executed only once on server side. Below is the details of code changes and output from server and client side.

Before:

var transport = 'websocket';

After:

var transport = 'jsonp';

image

Output on server side

Chat.onMessage() call was not duplicated

[info] o.a.s.play.Chat - John just send John
[info] o.a.s.play.Chat - John just send Test

Javascript output for jsonp

Page loaded:

Atmosphere: jsonp.window
atmosphere.js:3220 Atmosphere: Firing onOpen
atmosphere.js:3220 Atmosphere: Firing onOpen
atmosphere.js:3220 Atmosphere: jsonp.onload

User name selected ("John"):

onMessage method call was duplicated

Atmosphere: ajaxRequest.onreadystatechange, new state: 2
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 4
atmosphere.js:3220 Atmosphere: jsonp.window
atmosphere.js:1121 Resource interpreted as Script but transferred with MIME type text/plain: "http://localhost:9000/chat?X-Atmosphere-tracking-id=df812c0d-af62-4725-a63a…ication%2Fjson&X-atmo-protocol=true&jsonpTransport=atmosphere1426628629428".
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: jsonp.onload
atmosphere.js:1121 Resource interpreted as Script but transferred with MIME type text/plain: "http://localhost:9000/chat?X-Atmosphere-tracking-id=df812c0d-af62-4725-a63a…ication%2Fjson&X-atmo-protocol=true&jsonpTransport=atmosphere1426628629429".
atmosphere.js:3220 Atmosphere: jsonp.window
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: jsonp.onload

Message sent ("Test"):

onMessage method call was duplicated, in result "Test" message is shown twice.

Atmosphere: ajaxRequest.onreadystatechange, new state: 2
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 4
atmosphere.js:3220 Atmosphere: jsonp.window
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:1121 Resource interpreted as Script but transferred with MIME type text/plain: "http://localhost:9000/chat?X-Atmosphere-tracking-id=df812c0d-af62-4725-a63a…ication%2Fjson&X-atmo-protocol=true&jsonpTransport=atmosphere1426628629431".
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: jsonp.onload
atmosphere.js:1121 Resource interpreted as Script but transferred with MIME type text/plain: "http://localhost:9000/chat?X-Atmosphere-tracking-id=df812c0d-af62-4725-a63a…ication%2Fjson&X-atmo-protocol=true&jsonpTransport=atmosphere1426628629432".
atmosphere.js:3220 Atmosphere: jsonp.window
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: jsonp.onload

Javascript output for long-polling

Page loaded:

Atmosphere: ajaxRequest.onreadystatechange, new state: 2
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 3
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 4
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 2
atmosphere.js:3220 Atmosphere: Firing onOpen
atmosphere.js:3220 Atmosphere: Firing onOpen
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 3

User name selected ("John"):

onMessage method call was duplicated

Atmosphere: ajaxRequest.onreadystatechange, new state: 2
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 4
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 3
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 4
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 2
2atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 3
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 4
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 2
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 3

Message sent ("Test"):

onMessage method call was duplicated, in result "Test" message is shown twice.

Atmosphere: ajaxRequest.onreadystatechange, new state: 2

atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 4
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 3
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 4
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 2
2atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 3
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 4
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: Firing onMessage
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 2
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 3

Atmosphere-samples Code Revision: d792baf, master

Note: this is not an issue in case if transport is changed to 'jsonp' or 'long-polling' in "samples/sse-chat" project.
Browser: Google Chrome 41.0.2272.89 (Windows)

atmosphere-play 2.1.0 was used (build.sbt changed):

libraryDependencies += "org.atmosphere" % "atmosphere-play" % "2.1.0"

Can't get guice injection to work with atmosphere-play

Using the atmosphere-guice plugin in the following manner:

AtmosphereCoordinator.instance().framework().addInitParameter("org.atmosphere.cpr.objectFactory", GuiceObjectFactory.class.getName())
            .getServletContext().setAttribute(Injector.class.getName(), injector);

AtmosphereCoordinator.instance().discover(EventsAtmosphere.class).ready();

Doesn't seem to work. Any ideas on how to get injection to work with @ManagedService?

SSE transport do not work (switched to fallbackTransport after second message)

It seems atmosphere-play do not support SSE protocol (while it's known to be supported on lay in general)

Steps to Reproduce

  1. Start project play-samples/chat" (dependency has been updated to libraryDependencies += "org.atmosphere" % "atmosphere-play" % "2.1.0")
  2. update transport to "sse" in index.html
  3. Type name ("Johnny")
  4. Type message ("Message")
    ==> Message has been received by server, but not displayed on the client. it looks client got disconnected from server.
    It looks after first message transport has been switched to "pooling"
    image

image

Server Logs

[info] o.a.s.play.Chat - Browser 1bfa8e4b-397a-466d-88eb-2671b334d1d9 connected.
[debug] o.a.p.AtmosphereCoordinator - Transport sse resumeOnBroadcast false
[info] o.a.s.play.Chat - MyName just send MyName
[debug] o.a.p.AtmosphereCoordinator - Transport polling resumeOnBroadcast false
[info] o.a.s.play.Chat - Browser 1bfa8e4b-397a-466d-88eb-2671b334d1d9 unexpectedly disconnected
[warn] o.a.c.AtmosphereResponse - AtmosphereResponse for 1bfa8e4b-397a-466d-88eb-2671b334d1d9 has been closed
[info] o.a.s.play.Chat - Browser 2272b847-6dab-4a55-9922-499f6bb04e81 unexpectedly disconnected
[info] o.a.s.play.Chat - MyName just send MyMessage
[debug] o.a.p.AtmosphereCoordinator - Transport *polling* resumeOnBroadcast false
[info] o.a.s.play.Chat - Browser 1bfa8e4b-397a-466d-88eb-2671b334d1d9 unexpectedly disconnected
[warn] o.a.c.AtmosphereResponse - AtmosphereResponse for 1bfa8e4b-397a-466d-88eb-2671b334d1d9 has been closed

Browser - Chrome

Notes:

@org.atmosphere.config.service.Disconnect do not detect Android Chrome close Tab

Hello,

Atmosphere-play 2.1.2 with @ManagedService

When closing a tab with Android Chrome, the @Disconnect method is not fired.

AsyncSupportListener onClose is fired, but this is not in the context of the room, so it is not useful for me.

Try out the chat sample you provided with Chrome browser for Android and you will see it does not detect the closing of the tab (it does detect if in the URL bar I change the URL, but nothing else).

Cannot find org.atmosphere.play.Router

Compilation fails for Play! chat sample as downloaded from atmosphere-samples site, no modifications. Using Play! 2.5.4

bba0124$ activator compile
[info] Loading project definition from /Users/bba0124/Downloads/atmosphere-samples-master/play-samples/chat/project
[info] Set current project to chat (in build file:/Users/bba0124/Downloads/atmosphere-samples-master/play-samples/chat/)
[info] Compiling 3 Scala sources and 7 Java sources to /Users/bba0124/Downloads/atmosphere-samples-master/play-samples/chat/target/scala-2.11/classes...
[error] /Users/bba0124/Downloads/atmosphere-samples-master/play-samples/chat/app/Global.java:21: error: cannot find symbol
[error] import org.atmosphere.play.Router;
[error] ^
[error] symbol: class Router
[error] location: package org.atmosphere.play
[error] /Users/bba0124/Downloads/atmosphere-samples-master/play-samples/chat/app/Global.java:40: error: cannot find symbol
[error] return Router.dispatch(request);
[error] ^
[error] symbol: variable Router
[error] location: class Global
[error] 2 errors
error javac returned nonzero exit code
[error] Total time: 5 s, completed Jul 12, 2016 2:06:17 PM

Play Framework 2.4.0 routing, global settings and compilation error

Error Log

overriding method onRequestReceived in trait GlobalSettings of type (request: play.api.mvc.RequestHeader)(play.api.mvc.RequestHeader, play.api.mvc.Handler); method onRequestReceived has incompatible type
object Global extends GlobalSettings {
    override def onStart(app: Application): Unit = {
        AtmosphereCoordinator.instance().discover(classOf[MyAtmosphereSocket]).ready()
        super.onStart(app)
    }

    override def onStop(app: Application): Unit = {
        AtmosphereCoordinator.instance().shutdown()
        super.onStop(app)
    }

    override def onRequestReceived(request: RequestHeader): Option[Handler] =
        Router.dispatch(request) match {
            case Some(result) => Some(result)
            case None => super.onRouteRequest(request)
        }


}

I am basically trying the atmosphere-play-samples.

It was working in play V2.3.x...

Play 2.8.x support

Hi,

is there any chance for supporting Play Framework 2.8.x? Several concepts which were deprecated in 2.6.x have been removed/refactored in 2.7 or 2.8. and atmosphere-play cannot be used with 2.8.x.

"streaming" support does not work (switched to pooling)

This issue is pretty similar to #24 (same thing as SSE)

  1. "play-samples/chat" app, switch protocol to "streaming",
  2. open page, type name, type message
    ==> client got disconnected, protocol will be switched to "pooling", no new messages can be sent

BrowserЖ Chrome 41.0.2272.89 m

Page Loaded / Server

[info] o.a.s.play.Chat - Browser 04e0089c-87ff-4389-843b-aa8fd5f4675f connected.
[debug] o.a.p.AtmosphereCoordinator - Transport streaming resumeOnBroadcast false
[info] o.a.s.play.Chat - Browser bd002f74-4dfc-407a-872a-0cca9b0fe3cd unexpectedly disconnected

Page Loaded / JS Console

Wed Mar 18 2015 00:14:51 GMT+0200 (Финляндия (зима)) Atmosphere: ajaxRequest.onreadystatechange, new state: 2
atmosphere.js:3220 Wed Mar 18 2015 00:14:51 GMT+0200 (Финляндия (зима)) Atmosphere: ajaxRequest.onreadystatechange, new state: 3
atmosphere.js:3220 Wed Mar 18 2015 00:14:51 GMT+0200 (Финляндия (зима)) Atmosphere: Firing onOpen
atmosphere.js:3220 Wed Mar 18 2015 00:14:51 GMT+0200 (Финляндия (зима)) Atmosphere: Firing onOpen
atmosphere.js:3220 Wed Mar 18 2015 00:14:51 GMT+0200 (Финляндия (зима)) Atmosphere: ajaxRequest.onreadystatechange, new state: 3
2atmosphere.js:3220 Wed Mar 18 2015 00:15:51 GMT+0200 (Финляндия (зима)) Atmosphere: ajaxRequest.onreadystatechange, new state: 3

Name sent (Server)

[info] o.a.s.play.Chat - MyName just send MyName
[debug] o.a.p.AtmosphereCoordinator - Transport polling resumeOnBroadcast false
[info] o.a.s.play.Chat - Browser 04e0089c-87ff-4389-843b-aa8fd5f4675f unexpectedly disconnected
[warn] o.a.c.AtmosphereResponse - AtmosphereResponse for 04e0089c-87ff-4389-843b-aa8fd5f4675f has been closed

Name sent (JS Console)

Wed Mar 18 2015 00:16:51 GMT+0200 (Финляндия (зима)) Atmosphere: ajaxRequest.onreadystatechange, new state: 3
atmosphere.js:3220 Wed Mar 18 2015 00:17:47 GMT+0200 (Финляндия (зима)) Atmosphere: ajaxRequest.onreadystatechange, new state: 2
atmosphere.js:2090 XHR finished loading: POST "http://localhost:9090/chat?X-Atmosphere-tracking-id=04e0089c-87ff-4389-843b…here-TrackMessageSize=true&Content-Type=application%2Fjson&_=1426630667534".
atmosphere.js:3220 Wed Mar 18 2015 00:17:47 GMT+0200 (Финляндия (зима)) Atmosphere: ajaxRequest.onreadystatechange, new state: 4
atmosphere.js:3220 Wed Mar 18 2015 00:17:47 GMT+0200 (Финляндия (зима)) Atmosphere: ajaxRequest.onreadystatechange, new state: 3
atmosphere.js:3220 Wed Mar 18 2015 00:17:47 GMT+0200 (Финляндия (зима)) Atmosphere: Firing onMessage
atmosphere.js:3220 Wed Mar 18 2015 00:17:47 GMT+0200 (Финляндия (зима)) Atmosphere: Firing onMessage````

**Message sent (server)**
````[info] o.a.s.play.Chat - MyName just send MyMessage
[debug] o.a.p.AtmosphereCoordinator - Transport polling resumeOnBroadcast false
[info] o.a.s.play.Chat - Browser 04e0089c-87ff-4389-843b-aa8fd5f4675f unexpectedly disconnected
[warn] o.a.c.AtmosphereResponse - AtmosphereResponse for 04e0089c-87ff-4389-843b-aa8fd5f4675f has been closed

transport has been switched to "pooling" from "sreaming"

AtmosphereCoordinator prevents Play Reload in DEV mode

When changing a file in DEV mode and Play attempts to recompile/reload AtmosphereCoordinator's static final references prevent the parent ClassLoader from being garbage collected. The result is that objects of the same type created in a different ClassLoader throw ClassCastExceptions on comparisons. e.g. "Cannot cast models.Foo to models.Foo" in a loop like
for(Foo bar : listOfFoos) {
}

Samples don't work with external access

Accessing the chat with another machine shows the log:

[info] o.a.s.play.Chat - Browser 7350ed83-07bc-4b13-87ad-55c9da606327 connected.
[debug] o.a.p.AtmosphereCoordinator - Transport sse resumeOnBroadcast false
[info] o.a.s.play.Chat - Browser 7350ed83-07bc-4b13-87ad-55c9da606327 unexpectedly disconnected
[info] o.a.s.play.Chat - Browser 41d72855-c1f5-430a-8bda-165ffeb873a4 connected.
[debug] o.a.p.AtmosphereCoordinator - Transport sse resumeOnBroadcast false
[info] o.a.s.play.Chat - Browser 41d72855-c1f5-430a-8bda-165ffeb873a4 unexpectedly disconnected
[info] o.a.s.play.Chat - Browser fbc594f7-05ff-469f-a4fc-07252293a7fb connected.
...

Any hint about what is wrong?

Thanks

ajax transport does not work in sample chat application

Sample application: play-samples/chat, atmosphere-samples.

If the transport is changed to ajax inside index.scala.html, server side Chat.onReady() is not called and (therefore), client side does not receive onOpen(response) callback. Chat is not initialized and application stays in 'Connecting' state.

Before

var transport = 'websocket';

After

var transport = 'ajax';

Javascipt output

The key "target-densitydpi" is not supported.
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 2
atmosphere.js:3220 Atmosphere: ajaxRequest.onreadystatechange, new state: 4

Server logs output

[info] o.a.s.play.Chat - null just send disconnecting
[debug] o.a.p.AtmosphereCoordinator - Transport polling resumeOnBroadcast false
[debug] o.a.p.AtmosphereCoordinator - Transport ajax resumeOnBroadcast false
[info] o.a.s.play.Chat - Browser 66ddf330-0aaf-4fcf-b9d1-506bb07fddb4 unexpectedly disconnected
[warn] o.a.c.AtmosphereResponse - AtmosphereResponse for 66ddf330-0aaf-4fcf-b9d1-506bb07fddb4 has been closed

Notes

  • Browser: Google Chrome 41.0.2272.89 (Windows)
  • atmosphere-samples revision: master, d792baf
  • atmosphere-play 2.1.0 was used (build.sbt changed):
libraryDependencies += "org.atmosphere" % "atmosphere-play" % "2.1.0"

JVM crash after migration to play 2.3

Hi,

since I migrated from play 2.2 to play 2.3, atmoshere crashes the JVM with the following exception:

    Uncaught error from thread [play-akka.actor.default-dispatcher-7] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[play]
    java.lang.AbstractMethodError: org.atmosphere.play.Router$$anon$1.createResult(Lplay/mvc/Http$Context;Lplay/mvc/Result;)Lplay/api/mvc/Result;
        at play.core.j.JavaAction$$anonfun$13.apply(JavaAction.scala:84)
        at play.core.j.JavaAction$$anonfun$13.apply(JavaAction.scala:84)
        at scala.util.Success$$anonfun$map$1.apply(Try.scala:206)
        at scala.util.Try$.apply(Try.scala:161)
        at scala.util.Success.map(Try.scala:206)
        at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
        at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
        at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:46)
        at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40)
        at scala.concurrent.impl.Promise$DefaultPromise.scala$concurrent$impl$Promise$DefaultPromise$$dispatchOrAddCallback(Promise.scala:280)
        at scala.concurrent.impl.Promise$DefaultPromise.onComplete(Promise.scala:270)
        at scala.concurrent.Future$class.map(Future.scala:235)

My relevant lines from build.sbt:

    scalaVersion := "2.10.4"
    ...
      "org.atmosphere" % "atmosphere-runtime" % "2.1.8" withSources(),
      "org.atmosphere" % "atmosphere-play" % "2.0.0" exclude("org.atmosphere", "atmosphere-runtime") withSources(),

And how I start atmosphere from app/Global.scala:

    class Global extends GlobalSettings {
      var injector :Injector = null
      override def getControllerInstance[A](clazz:Class[A]) = {
        injector.getInstance(clazz)
      }

      override def onStart(application:Application) {
        injector = InjectorProvider.injector
        atmosphere.framework().addInitParameter(ApplicationConfig.WEBSOCKET_CONTENT_TYPE, "application/json")
        atmosphere.framework().objectFactory(new GuiceObjectFactory(injector))
        atmosphere.path("/live/state/{id: [0-9]*}").discover(classOf[live.StateWebSocket])
        atmosphere.path("/live/idea/{id: [0-9]*}").discover(classOf[live.IdeaWebSocket])
        atmosphere.ready()
      }

      override def onStop(application:Application) {
        println("onstop")
        atmosphere.shutdown()
        shutdownDatabase()
      }

      def shutdownDatabase() {
        val database:Database = injector.getInstance(classOf[Database])
        database.shutdown()
      }

      override def onRouteRequest(request:RequestHeader) : Handler = {
        val framework: AtmosphereFramework = atmosphere().framework()
        println("is broadcast specified: "+ framework.isBroadcasterSpecified)
        Router.dispatch(request)
      }

    }

What do I have to change to make it work again?

Thanks for your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.