V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  iiicarus  ›  全部回复第 6 页 / 共 7 页
回复总数  137
1  2  3  4  5  6  7  
2019-09-27 15:21:27 +08:00
回复了 rizon 创建的主题 程序员 spring boot 有没有办法全局拦截 url 进行截断处理
AOP 做,pointcut 拦截所有 controller,然后拿到 URL,过滤掉不需要的 URL,然后再进行一系列操作。前几天刚好完成了类似功能。http 日志详细记录。
2019-09-27 15:01:25 +08:00
回复了 wandeCat 创建的主题 问与答 作为一名码奴,迫不及待想给祖国庆生
没有假( 4 天也算假的话) 也没有加班工资
2019-09-26 14:42:25 +08:00
回复了 babedoll 创建的主题 问与答 如何面对同事的代码强迫症?
@nnnToTnnn 应该不是 list 和 lists。类似 users 和 userList
2019-09-25 17:37:20 +08:00
回复了 iiicarus 创建的主题 问与答 mybatis <delete> 标签写 update 语句,会造成什么影响?
@zcmxw1 因为部门有人这样写了代码,明明逻辑删除,最后数据库找不到数据,又不能知道是否是操作数据库直接删除的,所以有此一问。事出有因
2019-09-25 16:56:14 +08:00
回复了 iiicarus 创建的主题 问与答 mybatis <delete> 标签写 update 语句,会造成什么影响?
求大佬解答
2019-09-25 16:54:04 +08:00
回复了 BillyQIn 创建的主题 问与答 如果只能向别人推荐一本书,你会推荐哪本?
《罪与罚》
2019-09-10 11:25:29 +08:00
回复了 iiicarus 创建的主题 Java 求教,如何从 HttpServletRequest 中获取类名和方法名
@Aresxue 谢谢!从 request 中获取类名和方法名太困难了,感觉违背了 AOP 存在的意义!我们领导也是非要我这样做,目前的做法是,从路径 path 中分析得到模块。也没有具体的类名和方法名,不过另外做了 AOP,没提交,等后面要的时候再说吧~~~
2019-09-09 14:29:23 +08:00
回复了 CabbSir 创建的主题 阅读 如果人生至此只推荐一本书给别人,那么您的答案是什么
平凡的世界
2019-09-09 14:27:51 +08:00
回复了 jcloud 创建的主题 推广 回帖送京东 JOY 玩偶,最高还能领 100000 京豆!
想要中奖,就是这么直接!
2019-09-09 12:02:50 +08:00
回复了 iiicarus 创建的主题 Java 求教,如何从 HttpServletRequest 中获取类名和方法名
代码如上
2019-09-09 12:02:31 +08:00
回复了 iiicarus 创建的主题 Java 求教,如何从 HttpServletRequest 中获取类名和方法名
@Slf4j
public class HttpTraceLogFilter extends OncePerRequestFilter implements Ordered {

private static final String NEED_TRACE_PATH_PREFIX_BUSINESS = "/business";
private static final String NEED_TRACE_PATH_PREFIX_NPI = "/npi";
private static final String NEED_TRACE_PATH_PREFIX_SYSTEM = "/system";
private static final String IGNORE_CONTENT_TYPE = "multipart/form-data";

private final MeterRegistry registry;

public HttpTraceLogFilter(MeterRegistry registry) {
this.registry = registry;
}

@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE - 10;
}

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
if (!isRequestValid(request)) {
filterChain.doFilter(request, response);
return;
}
if (!(request instanceof ContentCachingRequestWrapper)) {
request = new ContentCachingRequestWrapper(request);
}
if (!(response instanceof ContentCachingResponseWrapper)) {
response = new ContentCachingResponseWrapper(response);
}

int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
long startTime = System.currentTimeMillis();
try {
filterChain.doFilter(request, response);
status = response.getStatus();
} finally {
String path = request.getRequestURI();
boolean pathFlag = path.startsWith(NEED_TRACE_PATH_PREFIX_BUSINESS) || path.startsWith(NEED_TRACE_PATH_PREFIX_NPI) || path.startsWith(NEED_TRACE_PATH_PREFIX_SYSTEM);
if (pathFlag && !Objects.equals(IGNORE_CONTENT_TYPE, request.getContentType())) {

String requestBody = IOUtils.toString(request.getInputStream(), Charsets.UTF_8);
log.info(requestBody);
//1. 记录日志
HttpTraceLog traceLog = new HttpTraceLog();
traceLog.setPath(path);
log.info("path ===================>: {}", path);
traceLog.setMethod(request.getMethod());
log.info("method ===================>: {}", request.getMethod());
long timeConsuming = System.currentTimeMillis() - startTime;
traceLog.setTimeTaken(timeConsuming);
log.info("timeConsuming ===================>: {} ms", timeConsuming);
//traceLog.setTime(LocalDateTime.now().toString());
//traceLog.setParameterMap(JsonMapper.INSTANCE.toJson(request.getParameterMap()));
traceLog.setStatus(status);
log.info("status ===================>: {}", status);
//traceLog.setRequestBody(getRequestBody(request));
//traceLog.setResponseBody(getResponseBody(response));
//log.info("Http trace log: {}", JsonMapper.INSTANCE.toJson(traceLog));
//log.info("Http trace log: {}===============================================>", traceLog);
}
updateResponse(response);
}
}

private boolean isRequestValid(HttpServletRequest request) {
try {
new URI(request.getRequestURL().toString());
return true;
} catch (URISyntaxException ex) {
return false;
}
}

private String getRequestBody(HttpServletRequest request) {
String requestBody = "";
ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class);
if (wrapper != null) {
try {
requestBody = IOUtils.toString(wrapper.getContentAsByteArray(), wrapper.getCharacterEncoding());
} catch (IOException e) {
// NOOP
}
}
return requestBody;
}

private String getResponseBody(HttpServletResponse response) {
String responseBody = "";
ContentCachingResponseWrapper wrapper = WebUtils.getNativeResponse(response, ContentCachingResponseWrapper.class);
if (wrapper != null) {
try {
responseBody = IOUtils.toString(wrapper.getContentAsByteArray(), wrapper.getCharacterEncoding());
} catch (IOException e) {
// NOOP
}
}
return responseBody;
}

private void updateResponse(HttpServletResponse response) throws IOException {
ContentCachingResponseWrapper responseWrapper = WebUtils.getNativeResponse(response, ContentCachingResponseWrapper.class);
Objects.requireNonNull(responseWrapper).copyBodyToResponse();
}


@Data
private static class HttpTraceLog {
private String path;
private String parameterMap;
private String method;
private Long timeTaken;
private String time;
private Integer status;
private String requestBody;
private String responseBody;
}
}
2019-09-09 12:02:14 +08:00
回复了 iiicarus 创建的主题 Java 求教,如何从 HttpServletRequest 中获取类名和方法名
@Configuration
@ConditionalOnWebApplication
public class HttpTraceConfiguration {

@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
static class ServletTraceFilterConfiguration {

@Bean
public HttpTraceLogFilter httpTraceLogFilter(MeterRegistry registry) {
return new HttpTraceLogFilter(registry);
}
}
}
2019-08-31 16:46:59 +08:00
回复了 iiicarus 创建的主题 问与答 B-Tree 和 B+Tree 怎么读
@7654 get! 谢谢
2019-08-31 16:46:43 +08:00
回复了 iiicarus 创建的主题 问与答 B-Tree 和 B+Tree 怎么读
@lhx2008 谢谢。以后就这样读。读英文可能有的人不喜欢
1  2  3  4  5  6  7  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2644 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 26ms · UTC 04:25 · PVG 12:25 · LAX 20:25 · JFK 23:25
Developed with CodeLauncher
♥ Do have faith in what you're doing.