Skip to content

Commit

Permalink
perf($VarAndVal): synchronize codes - WebRequestLogAspect.java
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed May 8, 2020
1 parent bc5b365 commit f38dded
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import com.jmsoftware.common.util.RequestUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
* <h1>RequestLogAspect</h1>
* <p><strong>Description</strong>:</p>
Expand Down Expand Up @@ -61,9 +60,9 @@ public void requestLogPointcut() {
*/
@Before("requestLogPointcut()")
public void beforeHandleRequest(JoinPoint joinPoint) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
val attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
assert attributes != null;
HttpServletRequest request = attributes.getRequest();
val request = attributes.getRequest();
log.info("============ WEB REQUEST LOG START ============");
log.info("URL : {}", request.getRequestURL().toString());
log.info("HTTP Method : {}", request.getMethod());
Expand All @@ -84,9 +83,9 @@ public void beforeHandleRequest(JoinPoint joinPoint) {
*/
@Around("requestLogPointcut()")
public Object aroundHandleRequest(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
Object result = proceedingJoinPoint.proceed();
long elapsedTime = System.currentTimeMillis() - startTime;
val startTime = System.currentTimeMillis();
val result = proceedingJoinPoint.proceed();
val elapsedTime = System.currentTimeMillis() - startTime;
try {
var formattedStringifiedJson = JSONUtil.formatJsonStr(mapper.writeValueAsString(result));
if (formattedStringifiedJson.length() > 500) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import com.jmsoftware.common.util.RequestUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
* <h1>RequestLogAspect</h1>
* <p><strong>Description</strong>:</p>
Expand Down Expand Up @@ -61,9 +60,9 @@ public void requestLogPointcut() {
*/
@Before("requestLogPointcut()")
public void beforeHandleRequest(JoinPoint joinPoint) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
val attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
assert attributes != null;
HttpServletRequest request = attributes.getRequest();
val request = attributes.getRequest();
log.info("============ WEB REQUEST LOG START ============");
log.info("URL : {}", request.getRequestURL().toString());
log.info("HTTP Method : {}", request.getMethod());
Expand All @@ -84,9 +83,9 @@ public void beforeHandleRequest(JoinPoint joinPoint) {
*/
@Around("requestLogPointcut()")
public Object aroundHandleRequest(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
Object result = proceedingJoinPoint.proceed();
long elapsedTime = System.currentTimeMillis() - startTime;
val startTime = System.currentTimeMillis();
val result = proceedingJoinPoint.proceed();
val elapsedTime = System.currentTimeMillis() - startTime;
try {
var formattedStringifiedJson = JSONUtil.formatJsonStr(mapper.writeValueAsString(result));
if (formattedStringifiedJson.length() > 500) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import com.jmsoftware.common.util.RequestUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
* <h1>RequestLogAspect</h1>
* <p><strong>Description</strong>:</p>
Expand Down Expand Up @@ -61,9 +60,9 @@ public void requestLogPointcut() {
*/
@Before("requestLogPointcut()")
public void beforeHandleRequest(JoinPoint joinPoint) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
val attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
assert attributes != null;
HttpServletRequest request = attributes.getRequest();
val request = attributes.getRequest();
log.info("============ WEB REQUEST LOG START ============");
log.info("URL : {}", request.getRequestURL().toString());
log.info("HTTP Method : {}", request.getMethod());
Expand All @@ -84,9 +83,9 @@ public void beforeHandleRequest(JoinPoint joinPoint) {
*/
@Around("requestLogPointcut()")
public Object aroundHandleRequest(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
Object result = proceedingJoinPoint.proceed();
long elapsedTime = System.currentTimeMillis() - startTime;
val startTime = System.currentTimeMillis();
val result = proceedingJoinPoint.proceed();
val elapsedTime = System.currentTimeMillis() - startTime;
try {
var formattedStringifiedJson = JSONUtil.formatJsonStr(mapper.writeValueAsString(result));
if (formattedStringifiedJson.length() > 500) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import com.jmsoftware.common.util.RequestUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
* <h1>RequestLogAspect</h1>
* <p><strong>Description</strong>:</p>
Expand Down Expand Up @@ -61,9 +60,9 @@ public void requestLogPointcut() {
*/
@Before("requestLogPointcut()")
public void beforeHandleRequest(JoinPoint joinPoint) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
val attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
assert attributes != null;
HttpServletRequest request = attributes.getRequest();
val request = attributes.getRequest();
log.info("============ WEB REQUEST LOG START ============");
log.info("URL : {}", request.getRequestURL().toString());
log.info("HTTP Method : {}", request.getMethod());
Expand All @@ -84,9 +83,9 @@ public void beforeHandleRequest(JoinPoint joinPoint) {
*/
@Around("requestLogPointcut()")
public Object aroundHandleRequest(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
Object result = proceedingJoinPoint.proceed();
long elapsedTime = System.currentTimeMillis() - startTime;
val startTime = System.currentTimeMillis();
val result = proceedingJoinPoint.proceed();
val elapsedTime = System.currentTimeMillis() - startTime;
try {
var formattedStringifiedJson = JSONUtil.formatJsonStr(mapper.writeValueAsString(result));
if (formattedStringifiedJson.length() > 500) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import com.jmsoftware.common.util.RequestUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
* <h1>RequestLogAspect</h1>
* <p><strong>Description</strong>:</p>
Expand Down Expand Up @@ -61,9 +60,9 @@ public void requestLogPointcut() {
*/
@Before("requestLogPointcut()")
public void beforeHandleRequest(JoinPoint joinPoint) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
val attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
assert attributes != null;
HttpServletRequest request = attributes.getRequest();
val request = attributes.getRequest();
log.info("============ WEB REQUEST LOG START ============");
log.info("URL : {}", request.getRequestURL().toString());
log.info("HTTP Method : {}", request.getMethod());
Expand All @@ -84,9 +83,9 @@ public void beforeHandleRequest(JoinPoint joinPoint) {
*/
@Around("requestLogPointcut()")
public Object aroundHandleRequest(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
Object result = proceedingJoinPoint.proceed();
long elapsedTime = System.currentTimeMillis() - startTime;
val startTime = System.currentTimeMillis();
val result = proceedingJoinPoint.proceed();
val elapsedTime = System.currentTimeMillis() - startTime;
try {
var formattedStringifiedJson = JSONUtil.formatJsonStr(mapper.writeValueAsString(result));
if (formattedStringifiedJson.length() > 500) {
Expand Down

0 comments on commit f38dded

Please sign in to comment.