interceptor
This commit is contained in:
@@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
19
prd/src/main/java/site/ocr/prd/WebMVCConfig.java
Normal file
19
prd/src/main/java/site/ocr/prd/WebMVCConfig.java
Normal file
@@ -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("/**");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user