Skip to content

Instantly share code, notes, and snippets.

@artgon
Created October 6, 2013 01:11
Show Gist options
  • Save artgon/6848075 to your computer and use it in GitHub Desktop.
Save artgon/6848075 to your computer and use it in GitHub Desktop.
Async Scalatra Objectify
/**
* For each action we map to the Scalatra equivalent block parameter
* though we are still bound to the HttpServletRequest and Response
* currently.
*/
sortedActions.foreach(action => {
def scalatraFunction(route: String) = action.method match {
case Options => options(route)_
case Get => get(route)_
case Post => post(route)_
case Put => put(route)_
case Delete => delete(route)_
case Patch => patch(route)_
}
scalatraFunction("/" + action.route.getOrElse(throw new BadRequestException("No Route Found"))) {
new AsyncResult { val is =
Future {
// wrap HttpServletRequest in adapter and get ObjectifyResponse
val objectifyResponse = execute(action,
new ScalatraRequestAdapter(RichRequest(request), RichResponse(response), params(request).toMap, Some(fileParams)))
// find appropriate response adapter and serialize the response
locateResponseAdapter(objectifyResponse).serializeResponseAny(request, response, objectifyResponse)
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment