From ebfee30bb9a841e9b58bb993fb845378927577d1 Mon Sep 17 00:00:00 2001 From: Marcos Lopez Gonzalez Date: Mon, 5 Aug 2019 22:46:01 +0200 Subject: [PATCH] improvements Spring httpTrace + added spring-boot-management to main pom --- pom.xml | 1 + .../management/trace/CustomTraceRepository.java | 13 ++++--------- .../src/main/resources/application.properties | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 5b5058763d..ed181cd919 100644 --- a/pom.xml +++ b/pom.xml @@ -652,6 +652,7 @@ spring-boot-keycloak spring-boot-kotlin spring-boot-logging-log4j2 + spring-boot-management spring-boot-mvc spring-boot-mvc-birt spring-boot-ops diff --git a/spring-boot-management/src/main/java/com/baeldung/spring/boot/management/trace/CustomTraceRepository.java b/spring-boot-management/src/main/java/com/baeldung/spring/boot/management/trace/CustomTraceRepository.java index 1478fc90a3..d85c043dc0 100644 --- a/spring-boot-management/src/main/java/com/baeldung/spring/boot/management/trace/CustomTraceRepository.java +++ b/spring-boot-management/src/main/java/com/baeldung/spring/boot/management/trace/CustomTraceRepository.java @@ -1,8 +1,8 @@ package com.baeldung.spring.boot.management.trace; -import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import org.springframework.boot.actuate.trace.http.HttpTrace; import org.springframework.boot.actuate.trace.http.HttpTraceRepository; @@ -11,23 +11,18 @@ import org.springframework.stereotype.Repository; @Repository public class CustomTraceRepository implements HttpTraceRepository { - List traces = new ArrayList<>(1); + AtomicReference lastTrace = new AtomicReference<>(); @Override public List findAll() { - synchronized (this.traces) { - return Collections.unmodifiableList(new ArrayList<>(this.traces)); - } + return Collections.singletonList(lastTrace.get()); } @Override public void add(HttpTrace trace) { if ("GET".equals(trace.getRequest() .getMethod())) { - synchronized (this.traces) { - traces.clear(); - traces.add(trace); - } + lastTrace.set(trace); } } diff --git a/spring-boot-management/src/main/resources/application.properties b/spring-boot-management/src/main/resources/application.properties index b6c303afdb..835ca64eac 100644 --- a/spring-boot-management/src/main/resources/application.properties +++ b/spring-boot-management/src/main/resources/application.properties @@ -1,3 +1,3 @@ management.endpoints.web.exposure.include=httptrace -management.trace.http.include=REQUEST_HEADERS +management.trace.http.include=RESPONSE_HEADERS