package com.example.struts2.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import java.util.Map;

/**
 * 日志拦截器 - 演示自定义拦截器
 * 
 * 学习点：
 * - AbstractInterceptor 基类
 * - intercept() 方法
 * - ActionInvocation 对象
 * - 拦截器链执行顺序
 */
public class LoggingInterceptor extends AbstractInterceptor {
    
    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        String actionName = invocation.getProxy().getActionName();
        String method = invocation.getProxy().getMethod();
        
        System.out.println("[LoggingInterceptor] 进入 Action: " + actionName + 
            ", Method: " + method);
        
        long startTime = System.currentTimeMillis();
        
        // 执行下一个拦截器或 Action
        String result = invocation.invoke();
        
        long duration = System.currentTimeMillis() - startTime;
        
        System.out.println("[LoggingInterceptor] 退出 Action: " + actionName + 
            ", Result: " + result + ", 耗时: " + duration + "ms");
        
        return result;
    }
}