Skip to content

Instantly share code, notes, and snippets.

package com.mojolly.websocket
import org.eclipse.jetty.server.handler.AbstractHandler
import org.eclipse.jetty.server.{Request, Server}
import java.io.IOException
import javax.servlet.ServletException
import javax.servlet.http.{HttpServlet, HttpServletResponse, HttpServletRequest}
import org.eclipse.jetty.servlet.{ServletHolder, ServletContextHandler}
import org.eclipse.jetty.server.session.SessionHandler
import akka.actor.Scheduler
@casualjim
casualjim / boot.scala
Created December 14, 2010 17:57
jetty continuation issues
package com.mojolly.websocket
import akka.actor.{Scheduler, Actor}
import java.util.concurrent.TimeUnit
import Actor._
import org.jredis.ri.alphazero.JRedisClient
/*
* Gets executed by the listener defined in web.xml
*/
asyncGet("/route") {
// all methods below are optional so in reality you would only see 2 or 3
init { continuation =>
}
resumed { continuation =>
}
expired { continuation =>
}
//Usage:
//override def pomPostProcess(node: Node): Node = mcPom(moduleConfigurations)(super.pomPostProcess(node))
trait McPom { self: DefaultProject =>
import scala.xml._
def mcPom(mcs: Set[ModuleConfiguration])(node: Node): Node = {
//make sure we have a trailing slash so we deduplicate URLs properly
def cleanUrl(url: String) = url match {
case null => ""
@casualjim
casualjim / ScalatraWebSocket.scala
Created December 18, 2010 21:15
WebSocket support for scalatra
package com.mojolly.websocket
import org.scalatra._
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
import org.eclipse.jetty.websocket.{WebSocket => ServletWebSocket, WebSocketFactory}
import akka.util.Logging
import java.io.UnsupportedEncodingException
import org.eclipse.jetty.websocket.WebSocket.Outbound
import collection.mutable.{ HashSet, SynchronizedSet }
@casualjim
casualjim / server.rb
Created January 12, 2011 07:12
A jruby jetty launcher for an exploded war
description "ConnFu demo application"
start on runlevel [2345]
stop on runlevel [!2345]
console none
# the following ensures that the process is restarted when it should die unexpectedly
respawn
exec sudo -u randomuser -H bash -c "cd /home/randomuser/connfu-demo; PORT=14080 /home/randomuser/.rvm/rubies/jruby-1.5.6/bin/ruby -J-Xmx256m -J-Xms128m -J-Xmn64m --server --headless connfu-demo-server"
@casualjim
casualjim / gist:779445
Created January 14, 2011 10:19
Scalatra Socket.IO example
package org.scalatra
import socketio.{SocketIOServlet}
class SocketIOExample extends SocketIOServlet {
// overriden because otherwise you need a trailing slash for the root url
// prefer the freedom with or without root.
override def requestPath = {
val p = (Option(request.getPathInfo) getOrElse "").trim
@ -129,16 +130,16 @@ class AkkaModulesParentProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val ATMO_VERSION = "0.6.2"
lazy val CAMEL_VERSION = "2.5.0"
lazy val CASSANDRA_VERSION = "0.6.1"
- lazy val DISPATCH_VERSION = "0.7.4"
+ lazy val DISPATCH_VERSION = "0.7.8"
lazy val HAWT_DISPATCH_VERSION = "1.0"
lazy val JACKSON_VERSION = "1.4.3"
lazy val JERSEY_VERSION = "1.3"
lazy val MULTIVERSE_VERSION = "0.6.1"
<% iterations.each do |iteration| %>
<h2 id='Sprint_<%= iteration.number %>' style='display:inline'>Sprint <%= iteration.number %></h2><i> - ends <%= iteration.finish.strftime("%Y-%m-%d") %></i><a href='#Sprint_<%= iteration.number %>' class='anchor'>&nbsp;&para;</a>
<ul>
<% iteration.stories.each do |story| %>
<li class='story'><h3 style='display:inline'><i>Story <%= story.id %> (<%= story.current_state %>)</i></h3>
<small class='taskCount'><i><%= " - #{story.tasks.size} tasks defined" if story.respond_to?(:tasks) %></i></small>
<p class='storyDescription'><span class="storyIngress"><%= story.name%></span><br><span class="storyRest" style="color:grey"></span></p>
<% end %>
</ul>
<% end %>
[error] x render hello
[error] '<html>
[error] <head>
[error] <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
[error] <title>Error 500 com.mojolly.backchat.scalatra.tests.ScalatraTestServlet.pathPatternParser2RouteMatcher(Lorg/scalatra/PathPattern;)Lorg/scalatra/RouteMatcher;</title>
[error] </head>
[error] <body><h2>HTTP ERROR 500</h2>
[error] <p>Problem accessing /hello. Reason:
[error] <pre> com.mojolly.backchat.scalatra.tests.ScalatraTestServlet.pathPatternParser2RouteMatcher(Lorg/scalatra/PathPattern;)Lorg/scalatra/RouteMatcher;</pre></p><h3>Caused by:</h3><pre>java.lang.AbstractMethodError: com.mojolly.backchat.scalatra.tests.ScalatraTestServlet.pathPatternParser2RouteMatcher(Lorg/scalatra/PathPattern;)Lorg/scalatra/RouteMatcher;
[error] at org.scalatra.ScalatraKernel$class.string2RouteMatcher(ScalatraKernel.scala:81)