diff --git a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/handler/GlobalExceptionHandler.java b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/handler/GlobalExceptionHandler.java index 98e83eb1..83cc01a9 100644 --- a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/handler/GlobalExceptionHandler.java +++ b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/handler/GlobalExceptionHandler.java @@ -39,7 +39,7 @@ public class GlobalExceptionHandler implements ErrorWebExceptionHandler { public Mono handle(ServerWebExchange exchange, Throwable ex) { val request = exchange.getRequest(); log.error("Exception occurred when [{}] requested access. Exception message: {}. Request URL: [{}] {}", - RequestUtil.getRequestIpAndPort(request), ex.getMessage(), request.getMethod(), request.getURI(), ex); + RequestUtil.getRequesterIpAndPort(request), ex.getMessage(), request.getMethod(), request.getURI(), ex); ServerHttpResponse response = exchange.getResponse(); if (response.isCommitted()) { return Mono.error(ex); diff --git a/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/filter/AccessLogFilter.java b/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/filter/AccessLogFilter.java index adbec428..b4e2d91f 100644 --- a/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/filter/AccessLogFilter.java +++ b/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/filter/AccessLogFilter.java @@ -4,6 +4,7 @@ import com.jmsoftware.maf.reactivespringbootstarter.util.RequestUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.core.Ordered; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.stereotype.Component; import org.springframework.util.AntPathMatcher; @@ -13,17 +14,16 @@ import reactor.core.publisher.Mono; /** - *

RequestFilter

+ *

AccessLogFilter

*

* Change description here. * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com - * @date 2/15/20 7:42 PM + * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 12/24/2020 10:56 AM **/ @Slf4j @Component @RequiredArgsConstructor -public class AccessLogFilter implements WebFilter { +public class AccessLogFilter implements WebFilter, Ordered { private final MafConfiguration mafConfiguration; private final AntPathMatcher antPathMatcher = new AntPathMatcher(); @@ -38,13 +38,18 @@ public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { } // Only record non-ignored request log log.info("{} (pre). Requester: {}, request URL: [{}] {}", - this.getClass().getSimpleName(), RequestUtil.getRequestIpAndPort(request), request.getMethod(), + this.getClass().getSimpleName(), RequestUtil.getRequesterIpAndPort(request), request.getMethod(), request.getURI()); return chain.filter(exchange).then( Mono.fromRunnable(() -> log.info("{} (post). Requester: {}, request URL: [{}] {}", this.getClass().getSimpleName(), - RequestUtil.getRequestIpAndPort(request), request.getMethod(), + RequestUtil.getRequesterIpAndPort(request), request.getMethod(), request.getURI())) ); } + + @Override + public int getOrder() { + return -500; + } } diff --git a/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/util/RequestUtil.java b/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/util/RequestUtil.java index 88e0b24a..cd2af253 100644 --- a/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/util/RequestUtil.java +++ b/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/util/RequestUtil.java @@ -22,11 +22,11 @@ public class RequestUtil { * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com * @date 2/15/20 9:52 PM */ - public static String getRequestIpAndPort(ServerHttpRequest request) { + public static String getRequesterIpAndPort(ServerHttpRequest request) { var requestRemoteAddress = request.getRemoteAddress(); if (ObjectUtil.isNotNull(requestRemoteAddress)) { return requestRemoteAddress.toString().substring(1); } - return "Unknown Request"; + return "Unknown Requester"; } }