AeroGear Controller is a very lean model view controller written in Java. It focuses on the routing of HTTP request to plain Java object endpoint and the handling of the returned result. The result of an invocation is either forwarded to a view, or returned in the format requested by the caller
This project show cases some of the functionality of AeroGear Controller.
An instance of this demo is deployed on OpenShift, but it can also be deployed locally. Please refer to the installation section for deploying locally.
This demo project has a number of routes, some are used in a MVC fashion while others are expected to be called as RESTful resources.
These routes are used for the web based interface which you can find on OpenShift. Please refer to the user guide for detailed information about configuring routes.
There are few routes that are intended to respond with JSON data. These routes deal with the /cars
resource and demonstrate
pagination.
The basic idea is that a client wants to limit the number of cars it receives per request to a certain number.
curl -i --header "Accept: application/json" "http://controller-aerogear.rhcloud.com/aerogear-controller-demo/cars?offset=0&color=red&limit=5"
Running the above command will produce output similar to the below:
HTTP/1.1 200 OK
Link: <http://controller-aerogear.rhcloud.com/aerogear-controller-demo/cars?offset=5&color=red&limit=5>; rel="next"
Content-Type: application/json;charset=UTF-8
Content-Length: 194
[
{"color":"red","brand":"Audi","id":6},
{"color":"red","brand":"BMW","id":13},
{"color":"red","brand":"Fiat","id":20},
{"color":"red","brand":"Golf","id":27},
{"color":"red","brand":"Lada","id":34}
]
By default, AeroGear Controller uses Web Linking specification and the Link
header
above is an example of this. A client can use these links to navigate, to the next/previous page.
To retrieve the next set of cars, use the URL from next
(see the Link
header in the previous example):
curl -i --header "Accept: application/json" "http://controller-aerogear.rhcloud.com/aerogear-controller-demo/cars?offset=5&color=red&limit=5"
The demo has built-in support for HTTP Basic / Digest authentication. Because both authentication schemas can't coexist, Digest authentication is enabled and configured by default. To switch the authentication schema (e.g. Basic), uncomment and comment the appropriate sections in the app's web.xml
file.
curl --basic -b cookies.txt -c cookies.txt -u john:123 "http://controller-aerogear.rhcloud.com/aerogear-controller-demo/autobots" -v
curl --digest -b cookies.txt -c cookies.txt -u agnes:123 "http://controller-aerogear.rhcloud.com/aerogear-controller-demo/autobots" -v
Note: for Digest authentication, a username called 'agnes' is configured instead of 'john' as in 'Basic' authentication.
Hawk provides an authentication scheme using a message authentication code (MAC) algorithm using a nonce in combination with a timestamp. For more detailed information please refer to the Hawk page.
To make use of it on AeroGear, make sure that your web.xml has it enabled. This demo already comes with the filter commented, so is just a matter of uncomment the source and have fun.
Once you have enabled the filter, this demo will become a Hawk Server. To test it, please make use of already existing client libraries for Node.js, Ruby or Java.
Building the project is done using maven:
mvn install
An AeroGear Controller application can be deployed to any application server with a CDI container.
However, this demo uses a datasource that by default exists in JBoss AS 7.x and it is the preferred deployment environment.
$ cp target/aerogear-controller-demo.war $AS7_HOME/standalone/deployments
$ cd $AS7_HOME
$ ./jboss-cli.sh --connect
$ [standalone@localhost:9999 /] deploy /path/to/aerogear-controller-demo/target/aerogear-controller-demo.war