Shopping time – Bootique

The last few days have been very productive. I have written demo endpoint which is able to return information whether a user should be logged in or not. In this application, I used the tool I met on the last Polish Java User Group meetup – Bootique. I’m going to describe it in the first part of this article. In the second, I’ll show you changes I made in the proxy application. There are a lot of new features.

I would like to remind you that all of the sources are available in my Github repository. Moreover, in the README file, you can find short project description with its main assumptions.

Let me introduce you Bootique

What the Bootique project is? As we can read on project’s main page:

Bootique is a minimally opinionated technology for building container-less runnable Java applications.

So, Bootique handles an application startup procedure without spending hours on configuration. Running an application written with the tool takes about 5 seconds. I don’t even want to compare this time with initial Spring application startup time. By providing support for external tools (e.g. Cayenne, Jersey, JDBC, Jetty and more), it makes itself very extensible. For more information visit project’s main page linked above.

It’s about time to write a few lines of code. At the beginning, we need some dependencies and configuration:

Writing a controller is the next step:

It checks if a user is registered (exists in users map) and returns an appropriate response. Now we should register the controller in the DI framework (Google Guice). For this purpose we should:

  1. create an  AksesiSampleModule module
  2. create module’s provider –  AksesiSampleModuleProvider

In the last step, we have to register the provider in the META-INF/services/io.bootique.BQModuleProvider file:

For now on, we can hit created controller with <application address>:<port>/login.  But before it, we should somehow run our application. Let’s run mvn clean install. In the target folder we will find:

There are two jar files. The first one is a little bit bigger. It is because Bootique creates its own executable file with all of the required dependencies inside. Additionally, using this file we can run the application with the wide range of useful options:

To run sample application I use the following command:

The config.yml file provides Jetty’s port configuration:

To sum up, it took me about 3 hours (writing code, reading the documentation, analyzing available examples) to create the sample application. After this time I really like Bootique and I’m going to use it more often, for sure. It is a fantastic replacement for Spring if you need to create a lightweight application with very fast startup.

Integration with the endpoint

As I mentioned in the Encapsulation and forwarding post, I had prepared the whole infrastructure for calling an endpoint with a converted password. For the purpose of handling all of the responses returned by an authentication endpoint, it was required to create a custom error handler AksesiResponseHandler. The default one throws an exception when the 4xx/5xx response code is returned. In our point of view, responses with those codes are completely fine and there is no reason for throwing exceptions. Having the handler written, we have to register it in the rest template ( AksesiRestTemplate).

After all of those changes, I had to refactor tests, especially the integration ones. The most problematic were to mock REST calls. After googling a while, I found the  MockRestServiceServer class:

In the test method:

I also improved logging in the infrastructure part of the application. For this purpose I created AksesiLogger:

AksesiLogger is a simple wrapper for  org.apache.log4j.Logger. It adds a custom prefix [AKSESI] to each of printed lines.

Example

The video below shows how applications cooperate. The console on the right side prints logs from the authentication endpoint (demo endpoint), the left one contains logs from the proxy.

I can say that basic functionality of Aksesi idea is provided. A user is able to configure the frontend module, send a password (mix of gestures and characters); the proxy is able to convert a password and pass it to an authentication endpoint.

You may also like

Comments