improvements Spring httpTrace + added spring-boot-management to main pom

This commit is contained in:
Marcos Lopez Gonzalez 2019-08-05 22:46:01 +02:00
parent 9e7a60545f
commit ebfee30bb9
3 changed files with 6 additions and 10 deletions

View File

@ -652,6 +652,7 @@
<module>spring-boot-keycloak</module>
<module>spring-boot-kotlin</module>
<module>spring-boot-logging-log4j2</module>
<module>spring-boot-management</module>
<module>spring-boot-mvc</module>
<module>spring-boot-mvc-birt</module>
<module>spring-boot-ops</module>

View File

@ -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<HttpTrace> traces = new ArrayList<>(1);
AtomicReference<HttpTrace> lastTrace = new AtomicReference<>();
@Override
public List<HttpTrace> 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);
}
}

View File

@ -1,3 +1,3 @@
management.endpoints.web.exposure.include=httptrace
management.trace.http.include=REQUEST_HEADERS
management.trace.http.include=RESPONSE_HEADERS