開発メモ

開発用のメモです。

アプリケーション領域を確認する Interceptor

import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class SessionAttributeInterceptor extends AbstractInterceptor {

    Logger logger = Logger.getLogger(getClass());

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        Map<String, Object> map = ServletActionContext.getContext().getSession();
        logger.debug("---- session start ----");
        for (Entry<String, Object> entry : map.entrySet()) {
            logger.debug(String.format(entry.getKey(), entry.getValue()));
        }
        String ret = invocation.invoke();
        for (Entry<String, Object> entry : map.entrySet()) {
            logger.debug(String.format(entry.getKey(), entry.getValue()));
        }
        logger.debug("---- session end ----");
        return ret;
    }

}
Twitter: @asahina_alice