diff --git a/prd/src/main/java/site/ocr/prd/SessionLoggingInterceptor.java b/prd/src/main/java/site/ocr/prd/SessionLoggingInterceptor.java new file mode 100644 index 0000000..760c8fa --- /dev/null +++ b/prd/src/main/java/site/ocr/prd/SessionLoggingInterceptor.java @@ -0,0 +1,37 @@ +package site.ocr.prd; + +import java.util.Enumeration; + +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +@Component +public class SessionLoggingInterceptor implements HandlerInterceptor { + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) + throws Exception { + //현재 세션이 있으면 가져오기, 없으면 null + HttpSession sessoin = request.getSession(false); + if (sessoin != null) { + StringBuilder sb = new StringBuilder("[SESSION DEBUG] :: "); + //세션ID(누구 세션인지) + sb.append("ID=").append(sessoin.getId()).append("\\n"); + //세션값 + Enumeration attrvName = sessoin.getAttributeNames(); + while (attrvName.hasMoreElements()) { + String name = attrvName.nextElement(); + String value = (String) sessoin.getAttribute(name); + sb.append("NAME=").append(name).append(", ").append("VALUE=").append(value).append("\\n"); + } + System.out.println(sb.toString()); + } else { + System.out.println("[SESSION DEBUG] :: No session found."); + } + return HandlerInterceptor.super.preHandle(request, response, handler); + } +} diff --git a/prd/src/main/java/site/ocr/prd/WebClientConfig.java b/prd/src/main/java/site/ocr/prd/WebClientConfig.java index be5a179..0e1063d 100644 --- a/prd/src/main/java/site/ocr/prd/WebClientConfig.java +++ b/prd/src/main/java/site/ocr/prd/WebClientConfig.java @@ -2,7 +2,6 @@ package site.ocr.prd; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.http.MediaType; import org.springframework.web.reactive.function.client.WebClient; @Configuration diff --git a/prd/src/main/java/site/ocr/prd/WebMVCConfig.java b/prd/src/main/java/site/ocr/prd/WebMVCConfig.java new file mode 100644 index 0000000..f111c94 --- /dev/null +++ b/prd/src/main/java/site/ocr/prd/WebMVCConfig.java @@ -0,0 +1,19 @@ +package site.ocr.prd; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebMVCConfig implements WebMvcConfigurer { + + @Autowired + private SessionLoggingInterceptor sessionLoggingInterceptor; + + @Override + public void addInterceptors(InterceptorRegistry registry) { + WebMvcConfigurer.super.addInterceptors(registry); + registry.addInterceptor(sessionLoggingInterceptor).addPathPatterns("/**"); + } +}