Posts for: #Java

Using Correlation IDs in Spring Boot for Distributed Tracing

In this post, I’ll show you how to implement correlation ids in a Spring Boot application, how to propagate them to downstream services (optionally, with FeignClient), and how to log them using Logback.

What Are Correlation IDs?

In modern microservices architectures, a single user request often traverses multiple services before a response is returned. When something goes wrong, or when you want to trace the flow of a request, it can be challenging to follow its journey across service boundaries. This is where correlation IDs come in.

Read more

Writing parameterized tests for Junit 5?

As a software engineer, I often encounter situations where I need to run the same test logic with different input values. Repeating the same test with minor variations not only clutters your test classes but also violates the DRY (Don't Repeat Yourself) principle.

That’s where parameterized tests come into play. Since JUnit 5, writing these tests has become much easier and cleaner. In this post, I’ll walk you through how to use parameterized tests effectively with JUnit 5.

Read more

How to logging SOAP requests and responses in Spring Boot?

When working with SOAP web services in a Spring Boot application, it’s often necessary to log incoming and outgoing SOAP messages for debugging, auditing, or monitoring purposes. Unlike REST APIs, where logging can be handled easily with filters and interceptors, SOAP requires a specialized approach.

Why Log SOAP Messages?

  • Debugging: Helps developers diagnose issues by capturing full request and response messages.
  • Auditing: Ensures compliance by keeping a record of exchanged messages.
  • Monitoring: Allows tracking of service interactions in production.

Implementing a SOAP Logging Handler

Spring Boot provides integration with SOAP web services using JAX-WS. To log SOAP requests and responses, we can implement a custom SOAPHandler. Here’s a simple SoapLoggingHandler that captures both inbound (responses) and outbound (requests) SOAP messages:

Read more