Created
October 6, 2013 01:11
-
-
Save artgon/6848075 to your computer and use it in GitHub Desktop.
Async Scalatra Objectify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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