Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL-12749
This commit is contained in:
commit
e37338dd2b
2
pom.xml
2
pom.xml
|
@ -651,6 +651,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>
|
||||
|
@ -1328,6 +1329,7 @@
|
|||
<module>spring-boot-jasypt</module>
|
||||
<module>spring-boot-keycloak</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>
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>spring-boot-management</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>spring-boot-management</name>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.spring.boot.management.trace;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(App.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.baeldung.spring.boot.management.trace;
|
||||
|
||||
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;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class CustomTraceRepository implements HttpTraceRepository {
|
||||
|
||||
AtomicReference<HttpTrace> lastTrace = new AtomicReference<>();
|
||||
|
||||
@Override
|
||||
public List<HttpTrace> findAll() {
|
||||
return Collections.singletonList(lastTrace.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(HttpTrace trace) {
|
||||
if ("GET".equals(trace.getRequest()
|
||||
.getMethod())) {
|
||||
lastTrace.set(trace);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.spring.boot.management.trace;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController("echo")
|
||||
public class EchoController {
|
||||
|
||||
@GetMapping
|
||||
public String echo(@RequestParam("msg") String msg) {
|
||||
return "echoing " + msg;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.baeldung.spring.boot.management.trace;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.boot.actuate.trace.http.HttpExchangeTracer;
|
||||
import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
|
||||
import org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TraceRequestFilter extends HttpTraceFilter {
|
||||
/**
|
||||
* Create a new {@link HttpTraceFilter} instance.
|
||||
*
|
||||
* @param repository the trace repository
|
||||
* @param tracer used to trace exchanges
|
||||
*/
|
||||
public TraceRequestFilter(HttpTraceRepository repository, HttpExchangeTracer tracer) {
|
||||
super(repository, tracer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
|
||||
return request.getServletPath().contains("actuator");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
management.endpoints.web.exposure.include=httptrace
|
||||
management.trace.http.include=RESPONSE_HEADERS
|
||||
|
Loading…
Reference in New Issue