添加部分组件
This commit is contained in:
parent
ac244f1f73
commit
f52623c8a7
9
pom.xml
9
pom.xml
@ -63,7 +63,10 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>apm-toolkit-trace</artifactId>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
@ -93,6 +96,10 @@
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
|
||||
51
src/main/java/cn/axzo/pokonyan/aop/RequestLog.java
Normal file
51
src/main/java/cn/axzo/pokonyan/aop/RequestLog.java
Normal file
@ -0,0 +1,51 @@
|
||||
package cn.axzo.pokonyan.aop;
|
||||
|
||||
import cn.axzo.pokonyan.util.RequestUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 打印出入参及耗时
|
||||
*
|
||||
* @author TanJ
|
||||
* @date 2021/5/12
|
||||
*/
|
||||
@Aspect
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RequestLog {
|
||||
|
||||
final String checkDeath = "checkDeath";
|
||||
|
||||
@Around("@within(restController)||@annotation(restController)")
|
||||
@SneakyThrows
|
||||
public Object request(ProceedingJoinPoint joinPoint, RestController restController) {
|
||||
|
||||
HttpServletRequest request = RequestUtil.getRequest();
|
||||
|
||||
if (request == null) {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
if (request.getRequestURL().toString().contains(checkDeath)) {
|
||||
Object proceed = joinPoint.proceed();
|
||||
return proceed;
|
||||
}
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
Object proceed = joinPoint.proceed();
|
||||
stopWatch.stop();
|
||||
log.info("[response]返回记录:responseParam = {} latency = {}", JSONUtil.toJsonStr(proceed),
|
||||
stopWatch.getTotalTimeMillis());
|
||||
return proceed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
8
src/main/java/cn/axzo/pokonyan/config/GlobalConfig.java
Normal file
8
src/main/java/cn/axzo/pokonyan/config/GlobalConfig.java
Normal file
@ -0,0 +1,8 @@
|
||||
package cn.axzo.pokonyan.config;
|
||||
|
||||
/**
|
||||
* @author tanjie@axzo.cn
|
||||
* @date 2023/7/7 17:17
|
||||
*/
|
||||
public class GlobalConfig {
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.axzo.config;
|
||||
package cn.axzo.pokonyan.config;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.axzo.config;
|
||||
package cn.axzo.pokonyan.config;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.axzo.config.jsonserializer;
|
||||
package cn.axzo.pokonyan.config.jsonserializer;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.fasterxml.jackson.databind.deser.std.DateDeserializers;
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.axzo.config.jsonserializer;
|
||||
package cn.axzo.pokonyan.config.jsonserializer;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.axzo.config.jsonserializer;
|
||||
package cn.axzo.pokonyan.config.jsonserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.axzo.config.jsonserializer;
|
||||
package cn.axzo.pokonyan.config.jsonserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
@ -2,4 +2,4 @@
|
||||
* @author tanjie@axzo.cn
|
||||
* @date 2023/7/6 14:57
|
||||
*/
|
||||
package cn.axzo.filter;
|
||||
package cn.axzo.pokonyan.config;
|
||||
@ -1,9 +1,8 @@
|
||||
package cn.axzo.filter;
|
||||
package cn.axzo.pokonyan.filter;
|
||||
|
||||
import cn.axzo.util.ExceptionUtil;
|
||||
import cn.axzo.pokonyan.util.ExceptionUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -16,12 +15,11 @@ import javax.servlet.DispatcherType;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 打印一些入参
|
||||
*
|
||||
* @author tanjie@axzo.cn
|
||||
* @date 2021/12/13 11:13
|
||||
*/
|
||||
@ -92,6 +90,7 @@ public class RequestLogHandlerInterceptor implements HandlerInterceptor, WebMvcC
|
||||
log.info("requestUrl:{}", requestUrl);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(this);
|
||||
@ -1,8 +1,8 @@
|
||||
package cn.axzo.filter;
|
||||
package cn.axzo.pokonyan.filter;
|
||||
|
||||
|
||||
import cn.axzo.util.ExceptionUtil;
|
||||
import cn.axzo.wrapper.BodyReaderHttpServletRequestWrapper;
|
||||
import cn.axzo.pokonyan.util.ExceptionUtil;
|
||||
import cn.axzo.pokonyan.wrapper.BodyReaderHttpServletRequestWrapper;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.google.common.base.Strings;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -11,8 +11,6 @@ import org.slf4j.MDC;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
import org.springframework.web.util.ContentCachingRequestWrapper;
|
||||
import org.springframework.web.util.ContentCachingResponseWrapper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.servlet.FilterChain;
|
||||
@ -2,4 +2,4 @@
|
||||
* @author tanjie@axzo.cn
|
||||
* @date 2023/7/6 14:57
|
||||
*/
|
||||
package cn.axzo.util;
|
||||
package cn.axzo.pokonyan.filter;
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.axzo.util;
|
||||
package cn.axzo.pokonyan.util;
|
||||
|
||||
|
||||
import java.util.function.Consumer;
|
||||
57
src/main/java/cn/axzo/pokonyan/util/RequestUtil.java
Normal file
57
src/main/java/cn/axzo/pokonyan/util/RequestUtil.java
Normal file
@ -0,0 +1,57 @@
|
||||
package cn.axzo.pokonyan.util;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
/**
|
||||
* @author TanJ
|
||||
* @date 2021/5/24
|
||||
*/
|
||||
public class RequestUtil {
|
||||
|
||||
|
||||
/**
|
||||
* getRequest
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static HttpServletRequest getRequest() {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
if (requestAttributes!=null) {
|
||||
return
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
||||
.getRequest();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getResponse
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static HttpServletResponse getResponse() {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
if (null != requestAttributes) {
|
||||
return
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
||||
.getResponse();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* setInheritableHolder
|
||||
*/
|
||||
public static void setInheritableHolder() {
|
||||
RequestContextHolder.setRequestAttributes(RequestContextHolder.getRequestAttributes(), true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -2,4 +2,4 @@
|
||||
* @author tanjie@axzo.cn
|
||||
* @date 2023/7/6 14:57
|
||||
*/
|
||||
package cn.axzo.config;
|
||||
package cn.axzo.pokonyan.util;
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.axzo.wrapper;
|
||||
package cn.axzo.pokonyan.wrapper;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user