添加部分组件

This commit is contained in:
TanJ 2023-07-07 17:19:01 +08:00
parent ac244f1f73
commit f52623c8a7
17 changed files with 143 additions and 23 deletions

View File

@ -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>

View 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;
}
}

View File

@ -0,0 +1,8 @@
package cn.axzo.pokonyan.config;
/**
* @author tanjie@axzo.cn
* @date 2023/7/7 17:17
*/
public class GlobalConfig {
}

View File

@ -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;

View File

@ -1,4 +1,4 @@
package cn.axzo.config;
package cn.axzo.pokonyan.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -2,4 +2,4 @@
* @author tanjie@axzo.cn
* @date 2023/7/6 14:57
*/
package cn.axzo.filter;
package cn.axzo.pokonyan.config;

View File

@ -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);

View File

@ -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;

View File

@ -2,4 +2,4 @@
* @author tanjie@axzo.cn
* @date 2023/7/6 14:57
*/
package cn.axzo.util;
package cn.axzo.pokonyan.filter;

View File

@ -1,4 +1,4 @@
package cn.axzo.util;
package cn.axzo.pokonyan.util;
import java.util.function.Consumer;

View 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);
}
}

View File

@ -2,4 +2,4 @@
* @author tanjie@axzo.cn
* @date 2023/7/6 14:57
*/
package cn.axzo.config;
package cn.axzo.pokonyan.util;

View File

@ -1,4 +1,4 @@
package cn.axzo.wrapper;
package cn.axzo.pokonyan.wrapper;
import lombok.SneakyThrows;