Awesome
gspore
Gspore is intended on being used as a .jar which is sufficient to allow java or groovy application that include it to consume SPORE implementing webservices.
It allows the consuming app to instanciate spore clients on the basis of api descriptions and to use them. Clients are generated with a set of class methods that matches the set of functionalities described in the api description, all of which are indeed callable, and send actual HTTP requests constructed according to the specification.
The raw features of the spore client and it's dynamically generated methods can be customized by the middlewares, which are specific workflow rewriters that are added on client scope, but can be enabled in a conditional fashion(e.g add authentication element on client scope).
The standard use of gspore should be something like
- Generate a client through api descritpion
- Create and enable, conditionaly or not, Middlewares
- Make requests
To summarize, the workflow processes through the following steps:
- feed() function is given the api description, and returns either errors or a Spore.
- In the second case, the Spore either returns errors or it adds itself one class method for each method registered in the api description Json under the entry "methods".
- By that point, basic HTTP request can be issued, and Middlewares can be enabled.
- If Middlewares were enabled, the method calls are intercepted and passed through each middleware, in enablement order, being potentially rewritten in the process.
- Unless the request was canceled, response structuring elements of the request go through each optional middleware post-processing callback in reverse enablement order.
- If no middleware prevented it from doing so, the request is actually sent.
- A response is returned to the client.
Install
- git clone https://github.com/unistra/gspore.git
- cd gspore
- mvn install
SPORE CLIENT
###sample groovy syntax :
//Create or get client
Spore spore = getClient("Client","/pathToMyJson/test.json")
//Enable Middleware, from hard-coded class or by generating a modified at runtime Middleware
spore.enable(spore.Middleware,[
"processRequest":{localArgs->
localArgs["spore.headers"]=["k":"v"]}, payload:["entry":["subEntry":'value']]
])
//same thing, with a boolean returning closure to specify wether or not the Middleware should be enabled
spore.enableIf(spore.Middleware,[payload:["entry":["subEntry":'value']]){args-> args['name']=="retrieve_page" }
//call method
spore.methodNameFoundInTheJson([arg1:"test",arg2:2,id:"unid"])
###sample java syntax :
//Create or get client
Spore spore = getClient("Client","/pathToMyJson/test.json");
//Instanciate Middleware from hard-coded class
JContentTypeSetter j = new JContentTypeSetter();
//enable Middleware conditionnaly or not
spore.enable(j.getClass(), args);
Map<Object,Object> args0 = new HashMap<Object ,Object>();
//call method
spore.invokeMethod("methodNameFoundInTheJson",args0)