Added Quarkus util classes.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>de.neitzel.lib</groupId>
|
||||
<artifactId>neitzellib</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>quarkus</artifactId>
|
||||
|
||||
<properties>
|
||||
<!-- Application Properties -->
|
||||
<link.name>${project.artifactId}</link.name>
|
||||
<launcher>${project.artifactId}</launcher>
|
||||
<appName>${project.artifactId}</appName>
|
||||
<jar.filename>${project.artifactId}-${project.version}</jar.filename>
|
||||
|
||||
<quarkus.platform.version>3.30.1</quarkus.platform.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/io.quarkus/quarkus-core -->
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-core</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-reactive-routes</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${jar.filename}</finalName>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-pmd-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,26 @@
|
||||
package de.neitzel.quarkus.util;
|
||||
|
||||
import io.quarkus.vertx.web.RouteFilter;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* A utility class that logs details of all incoming routes within a Quarkus application using Vert.x Web.
|
||||
* This logging is performed at the global level, meaning it applies to all routes handled by the application.
|
||||
*/
|
||||
@Slf4j
|
||||
public class GlobalRouteLogging {
|
||||
|
||||
/**
|
||||
* Logs all details of the incoming route request, including the method and URI, as well as all headers present in the request.
|
||||
* This method is designed to be used within a Vert.x Web application to log details for every incoming route globally.
|
||||
*
|
||||
* @param rc The routing context containing information about the current request and response.
|
||||
*/
|
||||
@RouteFilter(100)
|
||||
void logAll(RoutingContext rc) {
|
||||
log.info("⬅️ {} {}", rc.request().method(), rc.request().uri());
|
||||
rc.request().headers().forEach(h -> log.info("Header {}: {}", h.getKey(), h.getValue()));
|
||||
rc.next(); // wichtig: weiterreichen
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package de.neitzel.quarkus.util;
|
||||
|
||||
import jakarta.annotation.Priority;
|
||||
import jakarta.ws.rs.Priorities;
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.container.ContainerRequestFilter;
|
||||
import jakarta.ws.rs.container.PreMatching;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* A JAX-RS filter that logs the details of incoming HTTP requests before they are processed by the application.
|
||||
* This filter is annotated with {@code @Provider} to indicate it is a JAX-RS extension,
|
||||
* {@code @PreMatching} to specify it should run before the matching phase, and
|
||||
* {@code @Slf4j} for automatic logging using Lombok's {@code @Log} annotation.
|
||||
* It has a user priority level of {@link Priorities#USER}, which means it is executed after
|
||||
* but still within the standard processing chain.
|
||||
*/
|
||||
@Provider
|
||||
@PreMatching
|
||||
@Slf4j
|
||||
@Priority(Priorities.USER)
|
||||
public class IncomingRequestFilter implements ContainerRequestFilter {
|
||||
|
||||
/**
|
||||
* Logs the details of incoming HTTP requests before they are processed by the application.
|
||||
* This includes logging the request method and URI, as well as all headers present in the request.
|
||||
*
|
||||
* @param ctx The context of the incoming container request being filtered.
|
||||
*/
|
||||
@Override
|
||||
public void filter(ContainerRequestContext ctx) {
|
||||
log.info("⬅️ {} {}", ctx.getMethod(), ctx.getUriInfo().getRequestUri());
|
||||
ctx.getHeaders().forEach((k, v) -> log.info("Header {}: {}", k, v));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package de.neitzel.quarkus.util;
|
||||
|
||||
import jakarta.ws.rs.client.ClientRequestContext;
|
||||
import jakarta.ws.rs.client.ClientRequestFilter;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* A client-side filter that logs the details of HTTP requests before they are sent.
|
||||
*/
|
||||
@Slf4j
|
||||
@Provider
|
||||
public class LoggingRequestFilter implements ClientRequestFilter {
|
||||
/**
|
||||
* Logs the details of HTTP requests before they are sent.
|
||||
*
|
||||
* @param requestContext The context of the client request being filtered.
|
||||
*/
|
||||
@Override
|
||||
public void filter(ClientRequestContext requestContext) {
|
||||
log.info("➡️ Calling {} {}", requestContext.getMethod(), requestContext.getUri());
|
||||
requestContext.getHeaders().forEach((k, v) -> log.info("Header {}: {}", k, v));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user