We can use the flatten
method in Groovy to flatten a collection that contains other collections into a single collection with all elements. We can pass a closure as extra argument to the flatten
method to transform each element that is flattened. The argument of the closure is the element from the original collection.
In the following example we first use the flatten
method without a closure argument. Then we pass a closure argument and transform the element:
Continue reading →
I’ve recently had the situation where I deployed a Spring Boot application on OpenShift where a certain dependency needed a properties file that couldn’t be found.
The problem was that this dependency didn’t scan the classpath for the file, but just opened a FileInputStream relative to the current path.
In this blogpost I will guide you through the process of deploying a text file next to a jar in an OpenShift container.
I’ve reproduced an example scenario, but you can skip these steps and go right to the solution if you want to.
Continue reading →
The December 2019 release of Apache Kafka 2.4.0 saw usability improvements in TopologyTestDriver, with the addition of new TestInputTopic
and TestOutputTopic
classes.
These offer typesafe methods to easily produce and consume messages for your Kafka Streams tests.
In this post we’ll explore these new classes in the context of Avro messages, which requires a small trick to get working.
Continue reading →
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 →
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 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 →
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:
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 →
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 →
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 →
You might have a need for a custom access decision voter when security decisions are made based on who is accessing what domain object. Luckily Spring Security has quite a few options for such implement such access control list (ACL) constraints.
Continue reading →