From 5f3038312c1db4a99df6f97be2567d649bf63afb Mon Sep 17 00:00:00 2001 From: ebrahimiar <66822910+ebrahimiar@users.noreply.github.com> Date: Sun, 30 Jun 2024 12:18:01 +0330 Subject: [PATCH] [enhancement]changing the order of http filters and aspects. The order of HttpLoggingFilter has been changed from HIGHEST_PRECEDENCE + 1 to -280. The order of HttpMdcFilter has been changed from HIGHEST_PRECEDENCE to -300. The order of HttpStatisticsFilter has been changed from 20 to -290. The order of TimerStatisticsAspect has been changed from HIGHEST_PRECEDENCE to 20. --- README.md | 8 ++++++-- .../http/server/starter/aspect/TimerStatisticsAspect.java | 3 +-- .../http/server/starter/filter/HttpLoggingFilter.java | 3 +-- .../tosan/http/server/starter/filter/HttpMdcFilter.java | 3 +-- .../http/server/starter/filter/HttpStatisticsFilter.java | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 51c7ce2..0715a06 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,9 @@ it as a maven dependency and enable the desired functionality. ### mdc filter one of the common requirements of Http server is providing correct mdc parameters in order to trace request easily. -to reach this goal a filter name HttpMdcFilter is provided. this bean is defined by default as below: +to reach this goal a filter name HttpMdcFilter is provided. +The order of this filter is -300. +this bean is defined by default as below: ``` @Bean @ConditionalOnMissingBean @@ -268,8 +270,9 @@ your required comparison type can be specified in each securedParameter as below securedParameters.add(new SecureParameter("pan", UserMaskType.PAN, ComparisonType.RIGHT_LIKE)); ``` -for logging data a bean of type HttpLoggingFilter is provided by default as below. this bean exlude actuator url pattern +for logging data a bean of type HttpLoggingFilter is provided by default as below. this bean excludes actuator url pattern (/actuator/*) by default. +The order of this filter is -280. ``` @Bean @ConditionalOnMissingBean @@ -308,6 +311,7 @@ masking will be applied for : ### statistics filter HttpStatisticsFilter is created for purpose of logging simple metrics about http requests. +The order of this filter is -290 this filter logs some metrics as below: on request: ``` diff --git a/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/aspect/TimerStatisticsAspect.java b/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/aspect/TimerStatisticsAspect.java index 61ae706..c42c20f 100644 --- a/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/aspect/TimerStatisticsAspect.java +++ b/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/aspect/TimerStatisticsAspect.java @@ -6,7 +6,6 @@ import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; -import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; /** @@ -14,7 +13,7 @@ * @since 10/22/2022 */ @Aspect -@Order(Ordered.HIGHEST_PRECEDENCE) +@Order(20) public class TimerStatisticsAspect { private final TimerStatisticsUtil timerStatisticsUtil; diff --git a/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpLoggingFilter.java b/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpLoggingFilter.java index 1b2b857..f3aada9 100644 --- a/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpLoggingFilter.java +++ b/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpLoggingFilter.java @@ -9,7 +9,6 @@ import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.web.util.ContentCachingResponseWrapper; @@ -23,7 +22,7 @@ * @author M.khoshnevisan * @since 4/21/2021 */ -@Order(Ordered.HIGHEST_PRECEDENCE + 1) +@Order(-280) public class HttpLoggingFilter extends OncePerRequestFilterBase { private static final Logger LOGGER = LoggerFactory.getLogger(HttpLoggingFilter.class); diff --git a/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpMdcFilter.java b/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpMdcFilter.java index 5fc699b..1fb2f0c 100644 --- a/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpMdcFilter.java +++ b/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpMdcFilter.java @@ -5,7 +5,6 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import java.io.IOException; @@ -18,7 +17,7 @@ * @author mina khoshnevisan * @since 7/16/2022 */ -@Order(Ordered.HIGHEST_PRECEDENCE) +@Order(-300) public class HttpMdcFilter extends OncePerRequestFilterBase { private final MdcUtil mdcLogUtil; diff --git a/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpStatisticsFilter.java b/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpStatisticsFilter.java index 0077133..172bc5d 100644 --- a/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpStatisticsFilter.java +++ b/tosan-httpserver-spring-boot-starter/src/main/java/com/tosan/http/server/starter/filter/HttpStatisticsFilter.java @@ -30,7 +30,7 @@ * @author mina khoshnevisan * @since 7/20/2022 */ -@Order(20) +@Order(-290) public class HttpStatisticsFilter extends OncePerRequestFilterBase { private static final Logger LOGGER = LoggerFactory.getLogger(HttpStatisticsFilter.class); private static final AtomicLong activeRequestsCount = new AtomicLong(0);