Switched to JerseyBroadcaster

This commit is contained in:
Viktor Klang 2009-07-29 20:17:40 +02:00
parent daeae689b3
commit 352d4b6c2a
7 changed files with 39 additions and 6 deletions

Binary file not shown.

Binary file not shown.

10
deploy/root/page.html Normal file
View file

@ -0,0 +1,10 @@
<html>
<head><title>blah</title></head>
<body>
<form method="post" enctype="application/x-www-form-urlencoded" action="chat">
<input name="action"/>
<input name="name"/>
<input name="message"/>
<input type="submit" value="submit" name="submit"/>
</form>
</body>

View file

@ -94,7 +94,7 @@ class AkkaCometServlet extends org.atmosphere.cpr.AtmosphereServlet
val servlet = new AkkaServlet
this.config = new AtmosphereConfig { ah = servlet }
atmosphereHandlers.put("", new AtmosphereHandlerWrapper(servlet,new DefaultBroadcaster))
atmosphereHandlers.put("", new AtmosphereHandlerWrapper(servlet,new JerseyBroadcaster))
setCometSupport(new GrizzlyCometSupport(config))
getCometSupport.init(sconf)

Binary file not shown.

Binary file not shown.

View file

@ -21,9 +21,6 @@ class Boot {
SupervisorConfig(
RestartStrategy(OneForOne, 3, 100),
Supervise(
new SimpleService,
LifeCycle(Permanent, 100))
:: Supervise(
new Chat,
LifeCycle(Permanent, 100))
:: Nil)
@ -93,6 +90,9 @@ class Chat extends Actor with Logging{
override def receive: PartialFunction[Any, Unit] = {
case Chat(who,what,msg) => {
//log.info("Chat(" + who + ", " + what + ", " + msg + ")")
what match {
case "login" => reply("System Message__"+who+" has joined.")
case "post" => reply("" + who + "__" + msg)
@ -106,6 +106,29 @@ class Chat extends Actor with Logging{
@Consumes(Array("application/x-www-form-urlencoded"))
@POST
@Produces(Array("text/html"))
@FilterBroadcast(Array(classOf[XSSHtmlFilter]))
@FilterBroadcast(Array(classOf[XSSHtmlFilter],classOf[JsonpFilter]))
def publishMessage(form: MultivaluedMap[String, String]) = (this !! Chat(form.getFirst("name"),form.getFirst("action"),form.getFirst("message"))).getOrElse("System__error")
}
}
class JsonpFilter extends BroadcastFilter[String] with Logging
{
val BEGIN_SCRIPT_TAG = "<script type='text/javascript'>\n"
val END_SCRIPT_TAG = "</script>\n"
def filter(m : String) = {
var name = m
var message = ""
if (m.indexOf("__") > 0) {
name = m.substring(0, m.indexOf("__"))
message = m.substring(m.indexOf("__") + 2)
}
(BEGIN_SCRIPT_TAG + "window.parent.app.update({ name: \""
+ name + "\", message: \""
+ message + "\" });\n"
+ END_SCRIPT_TAG)
}
}