java - Batch HTTP requests in Play!Framework -


i have current set of of routes implemented (for example):

get     /api/:version/:entity               my.controllers.~~~~~     /api/:version/:entity/:id           my.controllers.~~~~~ post    /api/:version/:entity               my.controllers.~~~~~ post    /api/:version/:entity/:id           my.controllers.~~~~~ delete  /api/:version/:entity               my.controllers.~~~~~  post    /api/:version/search/:entity        my.controllers.~~~~~ 

and work beautifully. let's want implement "batch endpoint" same api. should this:

post    /api/:version/batch                 my.controllers.~~~~~ 

and body should this:

[     {         "method": "post",         "call": "/api/1/customer",         "body": {             "name": "antonio",             "email": "tonysmallhands@gmail.com"         }     },     {         "method": "post",         "call": "/api/1/customer/2",         "body": {             "name": "mario"         }     },     {         "method": "get",         "call": "/api/1/company"     },     {         "method": "delete",         "call": "/api/1/company/22"     } ] 

to know how can call play framework router pass requests? planning use similar advised unit tests:

@test public void badroute() {   result result = play.test.helpers.routeandcall(fakerequest(get, "/xx/kiki"));   assertthat(result).isnull(); }  

by going source code of routeandcall(), find this:

 /**  * use router determine action call request , executes it.  * @deprecated  * @see #route instead  */ @suppresswarnings(value = "unchecked") public static result routeandcall(fakerequest fakerequest) {     try {         return routeandcall((class<? extends play.core.router.routes>)fakerequest.class.getclassloader().loadclass("routes"), fakerequest);     } catch(runtimeexception e) {         throw e;     } catch(throwable t) {         throw new runtimeexception(t);     } }  /**  * use router determine action call request , executes it.  * @deprecated  * @see #route instead  */ public static result routeandcall(class<? extends play.core.router.routes> router, fakerequest fakerequest) {     try {         play.core.router.routes routes = (play.core.router.routes)router.getclassloader().loadclass(router.getname() + "$").getdeclaredfield("module$").get(null);         if(routes.routes().isdefinedat(fakerequest.getwrappedrequest())) {             return invokehandler(routes.routes().apply(fakerequest.getwrappedrequest()), fakerequest);         } else {             return null;         }     } catch(runtimeexception e) {         throw e;     } catch(throwable t) {         throw new runtimeexception(t);     } } 

so question is: there less "hacky" way play (i not against mixing scala , java it) copy above code? have give option of executing batched calls in parallel or in sequence ... guess instantiating 1 routes using class loader problematic then?

you can use following method call route fake requests: play.current.global.onrouterequest. please see post full example: http://yefremov.net/blog/play-batch-api/