Giter VIP home page Giter VIP logo

aerogear-controller-demo's Introduction

Build Status

AeroGear Controller Demo - very lean mvc controller

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.

Demo Contents

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.

Model View Controller Routes

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.

RESTful Controller 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.

Requesting the first set of cars:

 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.

Requesting the next set of cars:

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"

Basic / Digest Authentication

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.

Testing HTTP Basic authentication

 curl --basic -b cookies.txt -c cookies.txt -u john:123 "http://controller-aerogear.rhcloud.com/aerogear-controller-demo/autobots" -v

Testing Digest authentication

 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 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.

Installation

Building the project is done using maven:

mvn install

Deploy

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.

Manual deployment

$ cp target/aerogear-controller-demo.war $AS7_HOME/standalone/deployments

CLI deployment

$ cd $AS7_HOME
$ ./jboss-cli.sh --connect
$ [standalone@localhost:9999 /] deploy /path/to/aerogear-controller-demo/target/aerogear-controller-demo.war

Documentation

Community

Issue Tracker

aerogear-controller-demo's People

Contributors

danbev avatar qmx avatar matzew avatar sebastienblanc avatar tolis-e avatar josedonizetti avatar cvasilak avatar danielpassos avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.