Archive: 2019

Awesome Asciidoctor: Auto Number Callouts

Posted on by  
Hubert Klein Ikkink

In a previous post we learned about callouts in Asciidoctor to add explanation to source code. While surfing the Internet I came upon the following blog post by Alex Soto: Auto-numbered Callouts in Asciidoctor. I turns out that since Asciidoctor 1.5.8 we can use a dot (.) instead of explicit numbers to have automatic increasing numbering for the callouts.

Let’s take our example from the earlier blog post and now use auto numbered callouts:

Continue reading →

Prevent ResponseEntity being generated as OpenAPI model

Posted on by  
Tom de Vroomen

When using Springfox you can annotate your endpoints to automatically generate OpenAPI docs for your clients.
This blogpost will show how you can prevent Springfox generating a model on an endpoint with ResponseEntity as return type.
I’ll also cover how to prevent generating default responses.

Take an endpoint like below.
You want to return ResponseEntity because you want control over the status and body which is returned within your endpoint code.

Click to see the Spingfox configuration used for this example

Now your generated OpenAPI doc contains responses with a $ref to ResponseEntity.

Springfox will also generate default responses for 201, 202, 400, 401, 403, 404, which you may never need.

Click to see the generated definition for ResponseEntity (it is quite long)

Continue reading →

Adding Spring Security

Posted on by  
Tim te Beek

Adding Spring Security to an existing application can be quite a daunting prospect. Merely adding the required dependencies to your project sets off a chain of events which can break your application and tests.

Maybe you’re suddenly shown a login prompt which expects a generated password logged on startup.
Maybe your tests now get the dreaded 401 Unauthorized, or a subsequently a 403 Forbidden.
Maybe you get a ClassCastException when trying to use your Authentication#getPrincipal().
Either way, this post is here to help!

Continue reading →

Using ZIO's Ref to ensure a singleton in the Environment

Posted on by  
Chiel van de Steeg

In a previous post I’ve shown how to use ZIO environments to provide your program with dependencies, or modules. While using environments at the customer I’m currently working for, we found out that the logic to get a database session object using a module would run over and again. This makes sense, since a ZIO[R, E, A] is a prescribed way of getting an A, and the result is not cached. Our application was reading configuration files and creating SQL sessions on every module call, while the resulting object was obviously constructed from the same underlying values. There are multiple ways to solve this:

  • Creating the singleton objects before running you application logic.

  • Caching the result of the loading code in a reference.

In this post I’ve chosen the latter, because I wanted to show the use of ZIO’s Ref. Also, I like how semantically the desired data and the logic of retrieving it belong together.

Continue reading →

Spring Cloud Gateway with OpenID Connect and Token Relay

Posted on by  
Tim te Beek

When combined with Spring Security 5.2+ and an OpenID Provider such as Keycloak, one can rapidly setup and secure Spring Cloud Gateway for OAuth2 resource servers.

Spring Cloud Gateway aims to provide a simple, yet effective way to route to APIs and provide cross cutting concerns to them such as: security, monitoring/metrics, and resiliency.

We consider this combination a promising standards-based gateway solution, with desirable characteristics such as hiding tokens from the client, while keeping complexity to a minimum.

Continue reading →

HotSpot JVM optimizations

Posted on by  
Christophe Hesters

This is an overview of some optimization techniques used by Hotspot JVM to increase performance. I will start by giving a small example of how I ran into these optimizations while writing a naive benchmark. Each optimization is then explained with a short example and ends with some pointers on how to analyze your own code.

Continue reading →

Functional dependency injection in Scala using ZIO environments

Posted on by  
Chiel van de Steeg

ZIO is a type-safe, composable library for asynchronous and concurrent programming in Scala (from: The ZIO github). The library copes with functional IO, like many Functional Programming libraries do. The added value of ZIO is that the ZIO[R, E, A] type-constructor (the main IO monad of the library) acts as an IO monad, an error handling monad, and a reader monad. A functional programming style often needs a combination of these three types to cope with the most common problems when creating an application:

  • performing side effects (getting the A)

  • coping with errors (handling E)

  • supplying dependencies (providing R)

This blogpost will show you how to cope with the R part of a ZIO[R, E, A]: the Environment

Continue reading →

Spring Security: Custom Permission Evaluator

Posted on by  
Tim te Beek

Often you’ll find access decisions move beyond simplistic ownership or having a certain role, for instance when users share domain objects with other users. In such cases it’s common to separate permission to view an instance from being able to make changes to the same instance. When your access rules are relatively straightforward, Spring Security offers the PermissionEvaluator interface to secure instance access.

Continue reading →

shadow-left