Remote call to a PlayFramework object
I am looking for a way to send serialized objects (or simply strings) to a PlayFramework model or controller object through a remote JVM.
I am trying to create a web application based on pushed events, so for the moment, it is possible to get new events through a long polling ajax call, when some events are added to the model.
Now, I would like to add events into my model from a remote JVM, through RMI, a socket, or anything which could work. I have searched in the PlayFramework documentation but haven't开发者_如何学Python found any API or piece of code on how to do this.
You can use WebSockets, I wrote a blog post about it here: http://geeks.aretotally.in/log4play-log4j-ui-mashed-up-with-play-framework-knockout-js-and-websockets
My example only pushes from server to client but you can use WebSockets for two-way communication through JSON: http://www.playframework.org/documentation/1.2.1/asynchronous#UsingWebSockets
You can also use Akka Remote Actors (http://akka.io/docs/akka/1.1.3/scala/remote-actors.html).
Isn't pushing data into the server the easy part?
The natural way would be to invoke some controller action (read: HTTP POST) accepting a JsonData object (if data is structured) or plain parameters if data is unstructured.
Off the top of my head, in play speak it would look like this:
WSRequest request = new WSUrlFetch().newRequest("http://<url of your 'vm'>");
// request.setParameter("param", value);
// ...
request.post();
You do not need WebSockets for this.
精彩评论