play rest swagger and some google charts

I’ve got an article published in Linux Format issue 214 Rest,Swagger and Play with a demo application using Google Charts to display a timeseries overtime. There are 2 demos, one tracking the share price of BT compared to FTSE 100 and the temperature difference between London and Darlington.

The share price information uses Yahoo’s YQL to query a source of stock quotes

The temperature information is available from Open Weather Map API

The database for Play implementation is Sqlite. The play implementation is 2.4 as 2.5 was too fresh to support Swagger at the time. I wanted to show how easy it is to add Swagger annotations to a simple interface.

Finally as it’s Play it was easy to deploy this to Heroku. Albeit changing the database from Sqlite to Postgres. See

and the 2 charts

Source code is available here

weather chart
stock chart

tictactoe swagger,oauth, jsf with cucumber and selenium

Added a project to github today

Screenshot3-Swagger UI - Google Chrome

There is a version running on heroku too see

swagger ui –

or the demo game
tictactoe –

It’s a springfox swagger implementation of oauth using spring(with hibernate/h2), jsf, cucumber and selenium

Quick note, the tests use Selenium and are set to use Firefox and Chrome. See file in package bjason.swagger.jsf. Also note that to test Chrome at least I’ve had to include copies of chromedrive for Linux. You’ll need copies for other platforms from here

The aim of the project was to look at a more recent copy of swagger than I’ve used before. Then to use JSF rather than the usual JSP. Finally I wanted to see the oauth feature built into swagger working. So the implementation features are built around my tool choice and what I wanted to see rather than best way to do it. Biggest “choice” being heavy use of javascript in JSF pages to call rest resources when I think I’d have done that on the backend in this case.

What does the game do? It just allows 2 players to have a game of tic tac toe. It doesn’t check who wins, so it isn’t finished. it just shows the use of a simple rest api.

Note the use of spring profile below, as default is to deploy to heroku (postgress) rather than in memory h2 db.

to run up to play tictactoe as well as see the swagger gui

mvnw clean spring-boot:run

then visit

or to play the game

Swagger requires a recent version of the browser, be that Chrome, Firefox or IE. The oauth functionality uses Object.assign which is added in ECMAScript 6th edition.

I’ve included the swagger-ui here, as I’ve tested this works, at least for my 2 browsers, Chrome and Firefox.

To run selenium tests

mvnw package


test class sets up the use of 2 browsers. If you aren’t using Chrome or Firefox, or are a
non Linux 64 bit please visit to see links to the various third party drivers

you may need to change this entry if using windows
“./chromedriver.” + System.getProperty(“”) + “.”
+ System.getProperty(“”));

to simple reference the drive explicitly, e.g. System.setProperty(“”,”chromedrive.exe”);

the test is setup to use 2 browsers, Chrome and Firefox. To change simply set these lines accordingly.
_chromePlayer2 = new ChromeDriver();
_firefoxPlayer1 = new FirefoxDriver();

I chose these browsers simply because they are the 2 I use for testing on my system.

this file creates the actual game resources. Using lots of swagger annotations it defines the interface alongside the implementation.
It is here that the rest api definitions have their scope’s defined as well. There’s a lot of annotations but the entire api is configured in one place,
then the actual code just implements the api functionality. The authorisation is specified here but actually implemented in

this class extends HandlerInterceptorAdapter and implements the check to ensure the token is valid. Massive cheat here as I use a
spring bean rather than call the check externally via a rest call or similar.
CheckBearer is added as an intercepter in

this class implements the rest api’s to support oauth operations. It supports the GET that the tictactoe web app makes to get a token, along
with the POST create of a token that authorization/authorization_server.html uses before it redirects back to the calling tictactoe web app


this page is simply the simple page that the oauth provider implements, here you just enter an email address that isnt validated and it will then
create a token and allow a redirect back to the app using the specified redirect_uri


the app is using h2 in memory db to store information about the game in progress.

Sets up JSF servlet, adds a logging filter plus adds the CheckBearer for calls to the tictactoe rest resources.

<2h>WEB-INF/ faces-config.xml and web.xml

This is needed just to keep JSF happy. Otherwise not required.


setup is via src/test/resources/bjason/swagger/jsf/jsf.feature, and classes and JsfFeatureSteps. I’ve described the
scenarios for driving the GUI pages using selenium. Sorry no proper unit tests.

Screenshot6-Swagger UI - Google Chrome

Screenshot5-authorization page - Google Chrome

Screenshot4-authorization page - Google Chrome

Screenshot3-Swagger UI - Google Chrome

Screenshot2-Swagger UI - Google Chrome

Screenshot1-Swagger UI - Google Chrome