Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
quanpham-axonivy committed Dec 19, 2024
1 parent f1b7648 commit 77fadf4
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.log4j.Log4j2;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
Expand All @@ -16,8 +17,11 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Map;

import static com.axonivy.market.util.FileUtils.createFile;
Expand All @@ -38,8 +42,11 @@ public void logMethodCall(JoinPoint joinPoint) throws MissingHeaderException {
ServletRequestAttributes attributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes != null) {
Method method = signature.getMethod();
log.debug("#extractHeaders arguments {} ---- {}", method.getParameters(), joinPoint.getArgs());
log.info("#extractHeaders arguments {} ---- {}", method.getParameters(), joinPoint.getArgs());
HttpServletRequest request = attributes.getRequest();
Map<String, String> headersMap = extractHeaders(request, signature, joinPoint);
Map<String, String> headersMap = extractHeaders(request, method, joinPoint);
saveLogToDailyFile(headersMap);

// block execution if request isn't from Market or Ivy Designer
Expand All @@ -49,13 +56,16 @@ public void logMethodCall(JoinPoint joinPoint) throws MissingHeaderException {
}
}

private Map<String, String> extractHeaders(HttpServletRequest request, MethodSignature signature,
private Map<String, String> extractHeaders(HttpServletRequest request, Method method,
JoinPoint joinPoint) {
return Map.of(
LoggingConstants.METHOD, escapeXml(String.valueOf(signature.getMethod())),
LoggingConstants.METHOD, escapeXml(method.getName()),
LoggingConstants.TIMESTAMP, escapeXml(getCurrentTimestamp()),
CommonConstants.USER_AGENT, escapeXml(request.getHeader(CommonConstants.USER_AGENT)),
LoggingConstants.ARGUMENTS, escapeXml(getArgumentsString(signature.getParameterNames(), joinPoint.getArgs())),
LoggingConstants.ARGUMENTS,
escapeXml(getArgumentsString(
Arrays.stream(method.getParameters()).map(Parameter::getName).toList().toArray(new String[0]),
joinPoint.getArgs())),
CommonConstants.REQUESTED_BY, escapeXml(request.getHeader(CommonConstants.REQUESTED_BY))
);
}
Expand Down

0 comments on commit 77fadf4

Please sign in to comment.