This commit is contained in:
2025-11-07 11:44:53 +08:00
parent 03a0226fcb
commit f96c92b260
23 changed files with 18 additions and 198 deletions

View File

@@ -1,20 +1,31 @@
package com.czg.config;
import cn.hutool.core.util.IdUtil;
import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.util.Map;
/**
* @author GYJoker
*/
@Configuration
public class CorsFilter implements Filter {
@Value("${spring.application.name:unknown-service}")
private String applicationName;
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
throws IOException, ServletException {
// traceId
Map<String, String> copyOfContextMap = MDC.getCopyOfContextMap();
copyOfContextMap.put("traceId",applicationName + IdUtil.getSnowflakeNextId());
MDC.setContextMap(copyOfContextMap);
HttpServletResponse response = (HttpServletResponse) resp;
HttpServletRequest reqs = (HttpServletRequest) req;
String curOrigin = reqs.getHeader("Origin");