Add caching to Java's HttpClient

The out of the box HttpClient available since Java 11 is great, but is lacking caching. How to add this in a clean way? Welcom to the Decorator Design Pattern!

February 19, 2024 · 2 min

This Algorithm is 1,606,240% FASTER!

It is all in the title, but in this post I’ll go deeper how to represent encountered characters using bits.

November 25, 2023 · 3 min

Wiremock in 2 minutes

Wiremock helps you mock APIs, but how to get started? Two examples, two minutes of your time.

October 4, 2023 · 3 min

Sentry Sprint Boot Global Handler

Adding is quite straightforward, but how do you add a global handler?

June 30, 2023 · 2 min

Fallback Mechanism With Streams

The Problem I would like to summarize Person objects. Use the lastName if it is not null; if null, then use the firstName; else use the birthDay. If all these are null , then use the default text UNKNOWN. Usually, you write something like this: String summary = ""; if(p.getLastName() != null){ summary = p.getLastName(); } else if(p.getFirstName() != null){ summary = p.getFirstName(); } else if (p.getBirthDate() != null){ summary = p....

June 28, 2023 · 2 min

Advanced Grouping with Java streams

The problem I have a list of Person objects. I would like to group them per birth month, and only keep a List of lastnames. I came up with this code from memory Map<String, List<Person>> personsByMonth = .collect(Collectors.groupingBy(Person::getBirthMonth)); System.out.println(personsByMonth); And you get the following output (truncated for readability): {JUNE=[Person{lastName='Doe 11', birthDate=2022-06-07}], JANUARY=[Person{lastName='Doe 10', birthDate=2023-01-26}]} But how do I get rid of the redundant information? The solution The Collectors class provides quite a lot of variation of the groupingBy method....

May 22, 2023 · 2 min

Format and Highlight XML in the terminal

When working on legacy projects, you come across XML. And you would like some querying, highlighting and formatting to make your life less annoying.

May 8, 2023 · 3 min

Comparator and Null

Sorting collections has been quite easy with the Comparator class. But how do you deal with possible null values in for instance a List? You probably see already the NullPointerExceptions fly around, but fear not!

May 3, 2023 · 2 min

Jpa Native Updates

The point of JPA is define mappings so you don’t have to deal with low level SQL/JDBC statements anymore. In exceptional cases you can’t rely on the high level JPQL.

May 1, 2023 · 2 min

Disable Cache for Some Components in AEM

In a current project, components show information for an authenticated user, meaning this content is dynamic. As a page is cached on the first render, this means that content is no longer dynamic as it always shows the information of the authenticated user at the time of caching. Possible Solutions The dispatcher support authentication, however we were dealing with authentication that was not integrated into AEM. Listing all the pages that contains this component and exclude them from caching by the dispatcher is also not the way the go because you then need an exhaustive list of pages containing this component....

April 1, 2023 · 2 min