Skip to content

Commit

Permalink
Improve possible extension of filter class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chavjoh committed Jan 20, 2024
1 parent 5ba9520 commit 201b777
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/chavaillaz/jakarta/rs/LoggedFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ protected static <A extends Annotation> Optional<A> getAnnotation(ResourceInfo r
*
* @return The annotation type
*/
protected Class<? extends Logged> getAnnotation() {
return Logged.class;
protected Optional<Logged> getAnnotation() {
return getAnnotation(resourceInfo, Logged.class);
}

/**
Expand Down Expand Up @@ -167,7 +167,7 @@ public void filter(ContainerRequestContext requestContext, ContainerResponseCont
* @param requestContext The context of the request
*/
protected void logRequestBody(ContainerRequestContext requestContext) {
getAnnotation(resourceInfo, getAnnotation())
getAnnotation()
.map(Logged::requestBody)
.filter(loggingActivated -> loggingActivated && requestContext.hasEntity())
.ifPresent(logging -> MDC.put(REQUEST_BODY, getRequestBody(requestContext)));
Expand All @@ -179,7 +179,7 @@ protected void logRequestBody(ContainerRequestContext requestContext) {
* @param responseContext THe context of the response
*/
protected void logResponseBody(ContainerResponseContext responseContext) {
getAnnotation(resourceInfo, getAnnotation())
getAnnotation()
.map(Logged::responseBody)
.filter(loggingActivated -> loggingActivated && responseContext.hasEntity())
.ifPresent(logging -> MDC.put(RESPONSE_BODY, getResponseBody(responseContext)));
Expand Down

0 comments on commit 201b777

Please sign in to comment.