Atmosphere Jersey - Server messages
Asked Answered
Z

1

7

Is it possible to let the server send messages to all connected clients without waiting for any action from them? Let me explain it :-) I've been reading the docs/examples and I have found nothing that satifies my needs: the flow is always the same; a client connects (e.g: a GET call to a Rest API), the connection is suspendend and until a new API call is received (e.g.: a POST call) the server simply waits (or at least this is what I have understood). My use case is pretty different: I want the server to send some "notifications" once new data become available. This would be my use case (pretty simplifed):

  1. Client A connects to server
  2. Connection is suspended since no new data is available at the moment
  3. The server gets notified new data is available from an external source and broadcasts it to client A
  4. Go to step 2

What I have achieved so far is getting the connection successfully established. The next step is to solve this server issue. I must say this technology is completely new to me so it is possible I misunderstood how something works. If that's the case, let me know!

This is my stack:

  • Spring 3.2.0 RELEASE
  • Jersey 1.8
  • Atmosphere Jersey 1.0.13
  • Tomcat 7.0.40

Thank you all in advance!

UPDATE: After following this I get this warning, which I have no idea how to get rid of:

2013-06-04 09:40:36,284 WARN [org.atmosphere.cpr.AtmosphereFramework] - Failed using comet support: org.atmosphere.container.Tomcat7AsyncSupportWithWebSocket, error: Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.
If that's not the case, you can also remove META-INF/context.xml and WEB-INF/lib/atmosphere-compat-tomcat.jar Is the Nio or Apr Connector enabled?
2013-06-04 09:40:36,285 WARN [org.atmosphere.cpr.AtmosphereFramework] - Using org.atmosphere.container.Tomcat7BIOSupportWithWebSocket

I followed the app structure commented here, so this should not be a problem. I have noticed that by changing the transport to "websocket" instead of "long-polling" shows no errors. The server finally sends data tough :)

Zoophilous answered 3/6, 2013 at 21:54 Comment(0)
S
0

I followed your link and modified the code a little.

When you are in the step 3 "The server gets notified new data is available from an external source and broadcasts it to client A", you have to write a line like this:

BroadcasterFactory.getDefault().lookup("/*").broadcast(response);

At first I used the TextMessage received from my ActiveMQ Queue but I get this error, so I used a Jackson class as an object response and everything worked fine.

SEVERE: A message body writer for Java class org.apache.activemq.command.ActiveMQTextMessage, and Java type class org.apache.activemq.command.ActiveMQTextMessage, and MIME media type application/json was not found jun 03, 2014 11:32:21 AM com.sun.jersey.spi.container.ContainerResponse write SEVERE: The registered message body writers compatible with the MIME media type are: application/json (JSONJAXBElementProvider, JSONArrayProvider, JSONObjectProvider, JSONRootElementProvider, JSONListElementProvider, ...)

Scroll answered 3/6, 2014 at 9:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.