Sunday, February 26, 2012

Sample StrutsPrepareAndExecuteFilter - struts2 framework


package org.apache.struts2.dispatcher.ng.filter;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.dispatcher.ng.*;

// Referenced classes of package org.apache.struts2.dispatcher.ng.filter:
//            FilterHostConfig

public class StrutsPrepareAndExecuteFilter
    implements StrutsStatics, Filter
{

    private PrepareOperations prepare;
    private ExecuteOperations execute;

    public StrutsPrepareAndExecuteFilter()
    {
    }

    public void init(FilterConfig filterConfig)
        throws ServletException
    {
        InitOperations init = new InitOperations();
        FilterHostConfig config = new FilterHostConfig(filterConfig);
        init.initLogging(config);
        org.apache.struts2.dispatcher.Dispatcher dispatcher = init.initDispatcher(config);
        init.initStaticContentLoader(config, dispatcher);
        prepare = new PrepareOperations(filterConfig.getServletContext(), dispatcher);
        execute = new ExecuteOperations(filterConfig.getServletContext(), dispatcher);
        init.cleanup();
        break MISSING_BLOCK_LABEL_91;
        Exception exception;
        exception;
        init.cleanup();
        throw exception;
    }

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException
    {
        HttpServletRequest request;
        HttpServletResponse response;
        request = (HttpServletRequest)req;
        response = (HttpServletResponse)res;
        prepare.createActionContext(request, response);
        prepare.assignDispatcherToThread();
        prepare.setEncodingAndLocale(request, response);
        request = prepare.wrapRequest(request);
        org.apache.struts2.dispatcher.mapper.ActionMapping mapping = prepare.findActionMapping(request, response);
        if(mapping == null)
        {
            boolean handled = execute.executeStaticResourceRequest(request, response);
            if(!handled)
            {
                chain.doFilter(request, response);
            }
        } else
        {
            execute.executeAction(request, response, mapping);
        }
        prepare.cleanupRequest(request);
        break MISSING_BLOCK_LABEL_141;
        Exception exception;
        exception;
        prepare.cleanupRequest(request);
        throw exception;
    }

    public void destroy()
    {
        prepare.cleanupDispatcher();
    }
}

No comments:

Post a Comment

Thanks for your comments/Suggestions.