package jp.troter.servlet.httpsession;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jp.troter.servlet.httpsession.spi.SessionStateManager;

public class UserHttpSessionFilter implements Filter {

    protected SessionStateManager sessionStateManager;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException { }

    @Override
    public void destroy() { }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        SessionStateManager ssm = getSessionStateManager();
        UserHttpSessionHttpServletRequestWrapper requestWrapper = new UserHttpSessionHttpServletRequestWrapper(
                (HttpServletRequest) request, (HttpServletResponse) response, ssm);
        UserHttpSessionHttpServletResponseWrapper responseWrapper = new UserHttpSessionHttpServletResponseWrapper(
                (HttpServletResponse) response, requestWrapper, ssm);

        try {
            chain.doFilter(requestWrapper, responseWrapper);
        } finally {
            responseWrapper.updateState(ssm);
        }
    }

    protected SessionStateManager getSessionStateManager() {
        if (sessionStateManager == null) {
            sessionStateManager = SessionStateManager.getInstance();
        }
        return sessionStateManager;
    }
}

@@ -959,33 +959,32 @@
 estWrapper = new
- 
 UserHttpSessionH
@@ -1001,32 +1001,32 @@
 RequestWrapper(%0A
+
                 
@@ -1164,17 +1164,16 @@
 er = new
- 
 UserHttp
@@ -1415,24 +1415,24 @@
 State(ssm);%0A
-
         %7D%0A  
@@ -1432,24 +1432,739 @@
    %7D%0A    %7D%0A%0A
+    protected UserHttpSessionHttpServletRequestWrapper newUserHttpSessionHttpServletRequestWrapper(%0A            HttpServletRequest request, HttpServletResponse response,%0A            SessionStateManager sessionStateManager%0A    ) %7B%0A        return new UserHttpSessionHttpServletRequestWrapper(request, response, sessionStateManager);%0A    %7D%0A%0A    protected UserHttpSessionHttpServletResponseWrapper newUserHttpSessionHttpServletResponseWrapper(%0A            HttpServletResponse response, UserHttpSessionHttpServletRequestWrapper requestWrapper,%0A            SessionStateManager sessionStateManager%0A    ) %7B%0A        return new UserHttpSessionHttpServletResponseWrapper(response, requestWrapper, sessionStateManager);%0A    %7D%0A%0A
     protecte

use factory