wms-winstone-1.0.5

D));
    }
    for (int n = 0; n < 10; n++) {
      unusedResponsePool.add(new WinstoneResponse());
    }
  }
  
  public void destroy()
  {
    requestHandler.shutdown();
  }
  
  public void handleRequest(Socket socket, Listener listener)
    throws IOException, InterruptedException
  {
    try
    {
      requestHandler.submit(new RequestHandlerThread(simulateModUniqueId, saveSessions, socket, listener));
    }
    catch (RejectedExecutionException e)
    {
      logger.warn("WARNING: Request handler pool limit exceeded - waiting for retry");
      socket.close();
    }
  }
  
  public WinstoneRequest getRequestFromPool()
    throws IOException
  {
    WinstoneRequest winstoneRequest = null;
    synchronized (requestPoolSemaphore)
    {
      int unused = unusedRequestPool.size();
      if (unused > 0)
      {
        winstoneRequest = (WinstoneRequest)unusedRequestPool.remove(unused - 1);
        logger.debug("ReqPool: Using pooled request - available: {}", "" + unusedRequestPool.size());
      }
      else
      {
        winstoneRequest = new WinstoneRequest(MAXPARAMALLOWED);
        logger.debug("ReqPool: Spawning new request - available: {}", "" + unusedRequestPool.size());
      }
    }
    return winstoneRequest;
  }
  
  public void releaseRequestToPool(WinstoneRequest winstoneRequest)
  {
    winstoneRequest.cleanUp();
    synchronized (requestPoolSemaphore)
    {
      if (unusedRequestPool.size() < 1000) {
        unusedRequestPool.add(winstoneRequest);
      }
      logger.debug("ReqPool: Request released - available: {}", "" + unusedRequestPool.size());
    }
  }
  
  public WinstoneResponse getResponseFromPool()
    throws IOException
  {
    WinstoneResponse rsp = null;
    synchronized (responsePoolSemaphore)
    {
      int unused = unusedResponsePool.size();
      if (unused > 0)
      {
        rsp = (WinstoneResponse)unusedResponsePool.remove(unused - 1);
        logger.debug("RspPool: Using pooled response - available: {}", "" + unusedResponsePool.size());
      }
      else
      {
        rsp = new WinstoneResponse();
        logger.debug("RspPool: Spawning new response - available: {}", "" + unusedResponsePool.size());
      }
    }
    return rsp;
  }
  
  public void releaseResponseToPool(WinstoneResponse winstoneResponse)
  {
    winstoneResponse.cleanUp();
    synchronized (responsePoolSemaphore)
    {
      if (unusedResponsePool.size() < 1000) {
        unusedResponsePool.add(winstoneResponse);
      }
      logger.debug("RspPool: Response released - available: {}", "" + unusedResponsePool.size());
    }
  }
  
  public static int getMaximumAllowedParameter()
  {
    return MAXPARAMALLOWED;
  }
}

/* Location:
 * Qualified Name:     net.winstone.core.ObjectPool
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.core;

import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ServletConfiguration
  implements ServletConfig, Comparable<ServletConfiguration>
{
  protected static Logger logger = LoggerFactory.getLogger(ServletConfiguration.class);
  private static final transient String ELEM_NAME = "servlet-name";
  private static final transient String ELEM_CLASS = "servlet-class";
  private static final transient String ELEM_JSP_FILE = "jsp-file";
  private static final transient String ELEM_INIT_PARAM = "init-param";
  private static final transient String ELEM_INIT_PARAM_NAME = "param-name";
  private static final transient String ELEM_INIT_PARAM_VALUE = "param-value";
  private static final transient String ELEM_LOAD_ON_STARTUP = "load-on-startup";
  private static final transient String ELEM_RUN_AS = "run-as";
  private static final transient String ELEM_SECURITY_ROLE_REF = "security-role-ref";
  private static final transient String ELEM_ROLE_NAME = "role-name";
  private static final transient String ELEM_ROLE_LINK = "role-link";
  private static final transient String JSP_FILE = "org.apache.catalina.jsp_file";
  private String servletName;
  private String className;
  private Servlet instance;
  private final Map<String, String> initParams;
  private final WebAppConfiguration webAppConfig;
  private int loadOnStartup;
  private String jspFile;
  private final Map<String, String> securityRoleRefs;
  private final Object servletSemaphore = Boolean.TRUE;
  private boolean isSingleThreadModel = Boolean.FALSE.booleanValue();
  private boolean unavailable = Boolean.FALSE.booleanValue();
  private Throwable unavailableException = null;
  
  protected ServletConfiguration(WebAppConfiguration webAppConfig)
  {
    this.webAppConfig = webAppConfig;
    initParams = new HashMap();
    loadOnStartup = -1;
    securityRoleRefs = new HashMap();
  }
  
  public ServletConfiguration(WebAppConfiguration webAppConfig, String servletName, String className, Map<String, String> initParams, int loadOnStartup)
  {
    this(webAppConfig);
    if (initParams != null) {
      this.initParams.putAll(initParams);
    }
    this.servletName = servletName;
    this.className = className;
    jspFile = null;
    this.loadOnStartup = loadOnStartup;
  }
  
  public ServletConfiguration(WebAppConfiguration webAppConfig, Node elm)
  {
    this(webAppConfig);
    for (int n = 0; n < elm.getChildNodes().getLength(); n++)
    {
      Node child = elm.getChildNodes().item(n);
      if (child.getNodeType() == 1)
      {
        String nodeName = child.getNodeName();
        if (nodeName.equals("servlet-name"))
        {
          servletName = WebAppConfiguration.getTextFromNode(child);
        }
        else if (nodeName.equals("servlet-class"))
        {
          className = WebAppConfiguration.getTextFromNode(child);
        }
        else if (nodeName.equals("jsp-file"))
        {
          jspFile = WebAppConfiguration.getTextFromNode(child);
        }
        else if (nodeName.equals("load-on-startup"))
        {
          String index = child.getFirstChild() == null ? "-1" : WebAppConfiguration.getTextFromNode(child);
          loadOnStartup = Integer.parseInt(index);
        }
        else if (nodeName.equals("init-param"))
        {
          String paramName = "";
          String paramValue = "";
          for (int k = 0; k < child.getChildNodes().getLength(); k++)
          {
            Node paramNode = child.getChildNodes().item(k);
            if (paramNode.getNodeType() == 1) {
              if (paramNode.getNodeName().equals("param-name")) {
                paramName = WebAppConfiguration.getTextFromNode(paramNode);
              } else if (paramNode.getNodeName().equals("param-value")) {
                paramValue = WebAppConfiguration.getTextFromNode(paramNode);
              }
            }
          }
          if (!paramName.equals("")) {
            initParams.put(paramName, paramValue);
          }
        }
        else if (nodeName.equals("run-as"))
        {
          for (int m = 0; m < child.getChildNodes().getLength(); m++)
          {
            Node roleElm = child.getChildNodes().item(m);
            if ((roleElm.getNodeType() != 1) || (!roleElm.getNodeName().equals("role-name"))) {}
          }
        }
        else if (nodeName.equals("security-role-ref"))
        {
          String name = "";
          String link = "";
          for (int k = 0; k < child.getChildNodes().getLength(); k++)
          {
            Node roleRefNode = child.getChildNodes().item(k);
            if (roleRefNode.getNodeType() == 1) {
              if (roleRefNode.getNodeName().equals("role-name")) {
                name = WebAppConfiguration.getTextFromNode(roleRefNode);
              } else if (roleRefNode.getNodeName().equals("role-link")) {
                link = WebAppConfiguration.getTextFromNode(roleRefNode);
              }
            }
          }
          if ((!name.equals("")) && (!link.equals(""))) {
            initParams.put(name, link);
          }
        }
      }
    }
    if ((jspFile != null) && (className == null))
    {
      className = "org.apache.jasper.servlet.JspServlet";
      WebAppConfiguration.addJspServletParams(initParams);
    }
    logger.debug("Loaded servlet instance {} class: {}", servletName, className);
  }
  
  public String getInitParameter(String name)
  {
    return (String)initParams.get(name);
  }
  
  public Enumeration<?> getInitParameterNames()
  {
    return Collections.enumeration(initParams.keySet());
  }
  
  public ServletContext getServletContext()
  {
    return webAppConfig;
  }
  
  public String getServletName()
  {
    return servletName;
  }
  
  public void ensureInitialization()
  {
    if (instance != null) {
      return;
    }
    synchronized (servletSemaphore)
    {
      if (instance != null) {
        return;
      }
      if (unavailableException != null) {
        return;
      }
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(webAppConfig.getLoader());
      
      Servlet newInstance = null;
      Throwable otherError = null;
      try
      {
        Class<?> servletClass = Class.forName(className, Boolean.TRUE.booleanValue(), webAppConfig.getLoader());
        newInstance = (Servlet)servletClass.newInstance();
        isSingleThreadModel = Class.forName("javax.servlet.SingleThreadModel").isInstance(newInstance);
        
        logger.debug("{}: init", servletName);
        newInstance.init(this);
        instance = newInstance;
      }
      catch (ClassNotFoundException err)
      {
        logger.warn("Failed to load class: {}", className, err);
        setUnavailable(newInstance);
        unavailableException = err;
      }
      catch (IllegalAccessException err)
      {
        logger.warn("Failed to load class: {}", className, err);
        setUnavailable(newInstance);
        unavailableException = err;
      }
      catch (InstantiationException err)
      {
        logger.warn("Failed to load class: {}", className, err);
        setUnavailable(newInstance);
        unavailableException = err;
      }
      catch (ServletException err)
      {
        logger.warn("Failed to initialise servlet {}", servletName, err);
        instance = null;
        setUnavailable(newInstance);
        unavailableException = err;
      }
      catch (RuntimeException err)
      {
        otherError = err;
        throw err;
      }
      catch (Error err)
      {
        otherError = err;
        throw err;
      }
      finally
      {
        Thread.currentThread().setContextClassLoader(cl);
        if ((otherError == null) && (unavailableException == null)) {
          instance = newInstance;
        }
      }
    }
  }
  
  public void execute(ServletRequest request, ServletResponse response, String requestURI)
    throws ServletException, IOException
  {
    ensureInitialization();
    if (unavailable)
    {
      SimpleRequestDispatcher rd = webAppConfig.getErrorDispatcherByClass(unavailableException);
      rd.forward(request, response);
      return;
    }
    if (jspFile != null) {
      request.setAttribute("org.apache.catalina.jsp_file", jspFile);
    }
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(webAppConfig.getLoader());
    try
    {
      if (isSingleThreadModel) {
        synchronized (this)
        {
          instance.service(request, response);
        }
      } else {
        instance.service(request, response);
      }
    }
    catch (UnavailableException err)
    {
      setUnavailable(instance);
      ((HttpServletResponse)response).sendError(404, "File " + requestURI + " not found");
    }
    finally
    {
      Thread.currentThread().setContextClassLoader(cl);
    }
  }
  
  public int getLoadOnStartup()
  {
    return loadOnStartup;
  }
  
  public Map<String, String> getSecurityRoleRefs()
  {
    return securityRoleRefs;
  }
  
  public int compareTo(ServletConfiguration objTwo)
  {
    Integer one = new Integer(loadOnStartup);
    Integer two = new Integer(loadOnStartup);
    return one.compareTo(two);
  }
  
  public void destroy()
  {
    synchronized (servletSemaphore)
    {
      setUnavailable(instance);
    }
  }
  
  protected void setUnavailable(Servlet unavailableServlet)
  {
    unavailable = Boolean.TRUE.booleanValue();
    if (unavailableServlet != null)
    {
      logger.debug("{}: destroy", servletName);
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(webAppConfig.getLoader());
      try
      {
        unavailableServlet.destroy();
      }
      finally
      {
        Thread.currentThread().setContextClassLoader(cl);
        instance = null;
      }
    }
    webAppConfig.removeServletConfigurationAndMappings(this);
  }
}

/* Location:
 * Qualified Name:     net.winstone.core.ServletConfiguration
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.core;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.FilterChain;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestWrapper;
import javax.servlet.ServletResponse;
import javax.servlet.ServletResponseWrapper;
import net.winstone.core.authentication.AuthenticationHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SimpleRequestDispatcher
  implements RequestDispatcher, FilterChain
{
  protected static Logger logger = LoggerFactory.getLogger(SimpleRequestDispatcher.class);
  private final WebAppConfiguration webAppConfig;
  private final ServletConfiguration servletConfig;
  private String servletPath;
  private String pathInfo;
  private String queryString;
  private String requestURI;
  private Integer errorStatusCode;
  private Throwable errorException;
  private String errorSummaryMessage;
  private AuthenticationHandler authHandler;
  private Mapping[] forwardFilterPatterns;
  private Mapping[] includeFilterPatterns;
  private FilterConfiguration[] matchingFilters;
  private int matchingFiltersEvaluated;
  private Boolean doInclude;
  private boolean isErrorDispatch;
  private boolean useRequestAttributes;
  private WebAppConfiguration includedWebAppConfig;
  private ServletConfiguration includedServletConfig;
  
  public SimpleRequestDispatcher(WebAppConfiguration webAppConfig, ServletConfiguration servletConfig)
  {
    this.servletConfig = servletConfig;
    this.webAppConfig = webAppConfig;
    
    matchingFiltersEvaluated = 0;
  }
  
  public void setForNamedDispatcher(Mapping[] forwardFilterPatterns, Mapping[] includeFilterPatterns)
  {
    this.forwardFilterPatterns = forwardFilterPatterns;
    this.includeFilterPatterns = includeFilterPatterns;
    matchingFilters = null;
    useRequestAttributes = Boolean.FALSE.booleanValue();
    isErrorDispatch = Boolean.FALSE.booleanValue();
  }
  
  public void setForURLDispatcher(String servletPath, String pathInfo, String queryString, String requestURIInsideWebapp, Mapping[] forwardFilterPatterns, Mapping[] includeFilterPatterns)
  {
    this.servletPath = servletPath;
    this.pathInfo = pathInfo;
    this.queryString = queryString;
    requestURI = requestURIInsideWebapp;
    
    this.forwardFilterPatterns = forwardFilterPatterns;
    this.includeFilterPatterns = includeFilterPatterns;
    matchingFilters = null;
    useRequestAttributes = Boolean.TRUE.booleanValue();
    isErrorDispatch = Boolean.FALSE.booleanValue();
  }
  
  public void setForErrorDispatcher(String servletPath, String pathInfo, String queryString, int statusCode, String summaryMessage, Throwable exception, String errorHandlerURI, Mapping[] errorFilterPatterns)
  {
    this.servletPath = servletPath;
    this.pathInfo = pathInfo;
    this.queryString = queryString;
    requestURI = errorHandlerURI;
    
    errorStatusCode = new Integer(statusCode);
    errorException = exception;
    errorSummaryMessage = summaryMessage;
    matchingFilters = getMatchingFilters(errorFilterPatterns, webAppConfig, servletPath + (pathInfo == null ? "" : pathInfo), getName(), "ERROR", servletPath != null);
    useRequestAttributes = Boolean.TRUE.booleanValue();
    isErrorDispatch = Boolean.TRUE.booleanValue();
  }
  
  public void setForInitialDispatcher(String servletPath, String pathInfo, String queryString, String requestURIInsideWebapp, Mapping[] requestFilterPatterns, AuthenticationHandler authHandler)
  {
    this.servletPath = servletPath;
    this.pathInfo = pathInfo;
    this.queryString = queryString;
    requestURI = requestURIInsideWebapp;
    this.authHandler = authHandler;
    matchingFilters = getMatchingFilters(requestFilterPatterns, webAppConfig, servletPath + (pathInfo == null ? "" : pathInfo), getName(), "REQUEST", servletPath != null);
    useRequestAttributes = Boolean.FALSE.booleanValue();
    isErrorDispatch = Boolean.FALSE.booleanValue();
  }
  
  public String getName()
  {
    return servletConfig.getServletName();
  }
  
  public void include(ServletRequest request, ServletResponse response)
    throws ServletException, IOException
  {
    if (doInclude == null)
    {
      logger.debug("INCLUDE: servlet={}, path={}", getName(), requestURI);
      
      WinstoneRequest wr = getUnwrappedRequest(request);
      
      wr.addIncludeQueryParameters(queryString);
      if (useRequestAttributes) {
        wr.addIncludeAttributes(webAppConfig.getContextPath() + requestURI, webAppConfig.getContextPath(), servletPath, pathInfo, queryString);
      }
      WinstoneResponse wresp = getUnwrappedResponse(response);
      wresp.startIncludeBuffer();
      
      includedServletConfig = wr.getServletConfig();
      includedWebAppConfig = wr.getWebAppConfig();
      wr.setServletConfig(servletConfig);
      wr.setWebAppConfig(webAppConfig);
      wresp.setWebAppConfig(webAppConfig);
      
      doInclude = Boolean.TRUE;
    }
    if (matchingFilters == null) {
      matchingFilters = getMatchingFilters(includeFilterPatterns, webAppConfig, servletPath + (pathInfo == null ? "" : pathInfo), getName(), "INCLUDE", servletPath != null);
    }
    try
    {
      if (matchingFiltersEvaluated < matchingFilters.length)
      {
        doFilter(request, response);
        finishInclude(request, response);
      }
      else
      {
        try
        {
          servletConfig.execute(request, response, webAppConfig.getContextPath() + requestURI);
        }
        finally
        {
          if (matchingFilters.length == 0) {
            finishInclude(request, response);
          }
        }
      }
    }
    catch (Throwable err)
    {
      finishInclude(request, response);
      if ((err instanceof ServletException)) {
        throw ((ServletException)err);
      }
      if ((err instanceof IOException)) {
        throw ((IOException)err);
      }
      if ((err instanceof Error)) {
        throw ((Error)err);
      }
      throw ((RuntimeException)err);
    }
  }
  
  private void finishInclude(ServletRequest request, ServletResponse response)
    throws IOException
  {
    WinstoneRequest wr = getUnwrappedRequest(request);
    wr.removeIncludeQueryString();
    if (useRequestAttributes) {
      wr.removeIncludeAttributes();
    }
    WinstoneResponse wresp = getUnwrappedResponse(response);
    wresp.finishIncludeBuffer();
    if (includedServletConfig != null)
    {
      wr.setServletConfig(includedServletConfig);
      includedServletConfig = null;
    }
    if (includedWebAppConfig != null)
    {
      wr.setWebAppConfig(includedWebAppConfig);
      wresp.setWebAppConfig(includedWebAppConfig);
      includedWebAppConfig = null;
    }
  }
  
  public void forward(ServletRequest request, ServletResponse response)
    throws ServletException, IOException
  {
    if (doInclude == null)
    {
      logger.debug("FORWARD: servlet={}, path={}", getName(), requestURI);
      if (response.isCommitted()) {
        throw new IllegalStateException("Called RequestDispatcher.forward() on committed response");
      }
      WinstoneRequest req = getUnwrappedRequest(request);
      WinstoneResponse rsp = getUnwrappedResponse(response);
      
      rsp.resetBuffer();
      req.clearIncludeStackForForward();
      rsp.clearIncludeStackForForward();
      if (useRequestAttributes)
      {
        req.setAttribute("javax.servlet.forward.request_uri", req.getRequestURI());
        req.setAttribute("javax.servlet.forward.context_path", req.getContextPath());
        req.setAttribute("javax.servlet.forward.servlet_path", req.getServletPath());
        req.setAttribute("javax.servlet.forward.path_info", req.getPathInfo());
        req.setAttribute("javax.servlet.forward.query_string", req.getQueryString());
        if (isErrorDispatch)
        {
          req.setAttribute("javax.servlet.error.request_uri", req.getRequestURI());
          req.setAttribute("javax.servlet.error.status_code", errorStatusCode);
          req.setAttribute("javax.servlet.error.message", errorSummaryMessage != null ? errorSummaryMessage : "");
          if (req.getServletConfig() != null) {
            req.setAttribute("javax.servlet.error.servlet_name", req.getServletConfig().getServletName());
          }
          if (errorException != null)
          {
            req.setAttribute("javax.servlet.error.exception_type", errorException.getClass());
            req.setAttribute("javax.servlet.error.exception", errorException);
          }
          rsp.setErrorStatusCode(errorStatusCode.intValue());
          request = req;
          response = rsp;
        }
      }
      req.setServletPath(servletPath);
      req.setPathInfo(pathInfo);
      req.setRequestURI(webAppConfig.getContextPath() + requestURI);
      req.setForwardQueryString(queryString);
      req.setWebAppConfig(webAppConfig);
      req.setServletConfig(servletConfig);
      req.setRequestAttributeListeners(webAppConfig.getRequestAttributeListeners());
      
      rsp.setWebAppConfig(webAppConfig);
      if (matchingFilters == null) {
        matchingFilters = getMatchingFilters(forwardFilterPatterns, webAppConfig, servletPath + (pathInfo == null ? "" : pathInfo), getName(), "FORWARD", servletPath != null);
      } else if ((!isErrorDispatch) && (!continueAfterSecurityCheck(request, response))) {
        return;
      }
      doInclude = Boolean.FALSE;
    }
    boolean outsideFilter = matchingFiltersEvaluated == 0;
    if (matchingFiltersEvaluated < matchingFilters.length) {
      doFilter(request, response);
    } else {
      servletConfig.execute(request, response, webAppConfig.getContextPath() + requestURI);
    }
    if (outsideFilter)
    {
      WinstoneResponse rsp = getUnwrappedResponse(response);
      rsp.flushBuffer();
      rsp.getWinstoneOutputStream().setClosed(Boolean.TRUE.booleanValue());
    }
  }
  
  private boolean continueAfterSecurityCheck(ServletRequest request, ServletResponse response)
    throws IOException, ServletException
  {
    if (authHandler != null) {
      return authHandler.processAuthentication(request, response, servletPath + (pathInfo == null ? "" : pathInfo));
    }
    return Boolean.TRUE.booleanValue();
  }
  
  public void doFilter(ServletRequest request, ServletResponse response)
    throws ServletException, IOException
  {
    if (matchingFiltersEvaluated < matchingFilters.length)
    {
      FilterConfiguration filter = matchingFilters[(matchingFiltersEvaluated++)];
      logger.debug("Executing Filter: {}", filter.getFilterName());
      filter.execute(request, response, this);
      return;
    }
    if (doInclude == null) {
      return;
    }
    if (doInclude.booleanValue()) {
      include(request, response);
    } else {
      forward(request, response);
    }
  }
  
  private static FilterConfiguration[] getMatchingFilters(Mapping[] filterPatterns, WebAppConfiguration webAppConfig, String fullPath, String servletName, String filterChainType, boolean isURLBasedMatch)
  {
    String cacheKey = null;
    if (isURLBasedMatch) {
      cacheKey = filterChainType + ":URI:" + fullPath;
    } else {
      cacheKey = filterChainType + ":Servlet:" + servletName;
    }
    FilterConfiguration[] matchingFilters = null;
    Map<String, FilterConfiguration[]> cache = webAppConfig.getFilterMatchCache();
    synchronized (cache)
    {
      matchingFilters = (FilterConfiguration[])cache.get(cacheKey);
      if (matchingFilters == null)
      {
        logger.debug("No cached filter chain available. Calculating for cacheKey={}", cacheKey);
        List<FilterConfiguration> outFilters = new ArrayList();
        for (int n = 0; n < filterPatterns.length; n++)
        {
          Mapping filterPattern = filterPatterns[n];
          if ((filterPattern.getLinkName() != null) && ((filterPattern.getLinkName().equals(servletName)) || (filterPattern.getLinkName().equals("*")))) {
            outFilters.add(webAppConfig.getFilters().get(filterPattern.getMappedTo()));
          } else if ((filterPattern.getLinkName() == null) && (isURLBasedMatch) && (filterPattern.match(fullPath, null, null))) {
            outFilters.add(webAppConfig.getFilters().get(filterPattern.getMappedTo()));
          }
        }
        matchingFilters = (FilterConfiguration[])outFilters.toArray(new FilterConfiguration[0]);
        cache.put(cacheKey, matchingFilters);
      }
      else
      {
        logger.debug("Cached filter chain available for cacheKey={}", cacheKey);
      }
    }
    return matchingFilters;
  }
  
  protected WinstoneRequest getUnwrappedRequest(ServletRequest request)
  {
    ServletRequest workingRequest = request;
    while ((workingRequest instanceof ServletRequestWrapper)) {
      workingRequest = ((ServletRequestWrapper)workingRequest).getRequest();
    }
    return (WinstoneRequest)workingRequest;
  }
  
  protected WinstoneResponse getUnwrappedResponse(ServletResponse response)
  {
    ServletResponse workingResponse = response;
    while ((workingResponse instanceof ServletResponseWrapper)) {
      workingResponse = ((ServletResponseWrapper)workingResponse).getResponse();
    }
    return (WinstoneResponse)workingResponse;
  }
}

/* Location:
 * Qualified Name:     net.winstone.core.SimpleRequestDispatcher
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.core;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Constructor;
import java.net.FileNameMap;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionListener;
import net.winstone.MimeTypes;
import net.winstone.WinstoneException;
import net.winstone.WinstoneResourceBundle;
import net.winstone.accesslog.AccessLogger;
import net.winstone.accesslog.AccessLoggerProviderFactory;
import net.winstone.accesslog.PatternType;
import net.winstone.cluster.Cluster;
import net.winstone.core.authentication.AuthenticationHandler;
import net.winstone.core.authentication.AuthenticationRealm;
import net.winstone.core.authentication.realm.ArgumentsRealm;
import net.winstone.jndi.JndiManager;
import net.winstone.loader.FilteringClassLoader;
import net.winstone.loader.ReloadingClassLoader;
import net.winstone.loader.WebappClassLoader;
import net.winstone.servlet.ErrorServlet;
import net.winstone.servlet.InvokerServlet;
import net.winstone.servlet.StaticResourceServlet;
import net.winstone.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class WebAppConfiguration
  implements ServletContext, Comparator<Object>
{
  protected static Logger logger = LoggerFactory.getLogger(WebAppConfiguration.class);
  private static final String ELEM_DISPLAY_NAME = "display-name";
  private static final String ELEM_SERVLET = "servlet";
  private static final String ELEM_SERVLET_MAPPING = "servlet-mapping";
  private static final String ELEM_SERVLET_NAME = "servlet-name";
  private static final String ELEM_FILTER = "filter";
  private static final String ELEM_FILTER_MAPPING = "filter-mapping";
  private static final String ELEM_FILTER_NAME = "filter-name";
  private static final String ELEM_DISPATCHER = "dispatcher";
  private static final String ELEM_URL_PATTERN = "url-pattern";
  private static final String ELEM_WELCOME_FILES = "welcome-file-list";
  private static final String ELEM_WELCOME_FILE = "welcome-file";
  private static final String ELEM_SESSION_CONFIG = "session-config";
  private static final String ELEM_SESSION_TIMEOUT = "session-timeout";
  private static final String ELEM_MIME_MAPPING = "mime-mapping";
  private static final String ELEM_MIME_EXTENSION = "extension";
  private static final String ELEM_MIME_TYPE = "mime-type";
  private static final String ELEM_CONTEXT_PARAM = "context-param";
  private static final String ELEM_PARAM_NAME = "param-name";
  private static final String ELEM_PARAM_VALUE = "param-value";
  private static final String ELEM_LISTENER = "listener";
  private static final String ELEM_LISTENER_CLASS = "listener-class";
  private static final String ELEM_DISTRIBUTABLE = "distributable";
  private static final String ELEM_ERROR_PAGE = "error-page";
  private static final String ELEM_EXCEPTION_TYPE = "exception-type";
  private static final String ELEM_ERROR_CODE = "error-code";
  private static final String ELEM_ERROR_LOCATION = "location";
  private static final String ELEM_SECURITY_CONSTRAINT = "security-constraint";
  private static final String ELEM_LOGIN_CONFIG = "login-config";
  private static final String ELEM_SECURITY_ROLE = "security-role";
  private static final String ELEM_ROLE_NAME = "role-name";
  private static final String ELEM_ENV_ENTRY = "env-entry";
  private static final String ELEM_LOCALE_ENC_MAP_LIST = "locale-encoding-mapping-list";
  private static final String ELEM_LOCALE_ENC_MAPPING = "locale-encoding-mapping";
  private static final String ELEM_LOCALE = "locale";
  private static final String ELEM_ENCODING = "encoding";
  private static final String ELEM_JSP_CONFIG = "jsp-config";
  private static final String ELEM_JSP_PROPERTY_GROUP = "jsp-property-group";
  private static final String DISPATCHER_REQUEST = "REQUEST";
  private static final String DISPATCHER_FORWARD = "FORWARD";
  private static final String DISPATCHER_INCLUDE = "INCLUDE";
  private static final String DISPATCHER_ERROR = "ERROR";
  private static final String JSP_SERVLET_MAPPING = "*.jsp";
  private static final String JSPX_SERVLET_MAPPING = "*.jspx";
  private static final String JSP_SERVLET_LOG_LEVEL = "WARNING";
  private static final String INVOKER_SERVLET_NAME = "invoker";
  private static final String DEFAULT_INVOKER_PREFIX = "/servlet/";
  private static final String DEFAULT_SERVLET_NAME = "default";
  private static final String ERROR_SERVLET_NAME = "winstoneErrorServlet";
  private static final String WEB_INF = "WEB-INF";
  private static final String CLASSES = "classes/";
  private static final String LIB = "lib";
  private final HostConfiguration ownerHostConfig;
  private final Cluster cluster;
  private final String webRoot;
  private final String prefix;
  private final String contextName;
  private ClassLoader loader;
  private String displayName;
  private WebAppJNDIManager webAppJNDIManager;
  private final Map<String, Object> attributes;
  private final Map<String, String> initParameters;
  private final Map<String, WinstoneSession> sessions;
  private FileNameMap mimeTypes;
  private final Map<String, ServletConfiguration> servletInstances;
  private final Map<String, FilterConfiguration> filterInstances;
  private final ServletContextAttributeListener[] contextAttributeListeners;
  private ServletContextListener[] contextListeners;
  private final ServletRequestListener[] requestListeners;
  private final ServletRequestAttributeListener[] requestAttributeListeners;
  private final HttpSessionActivationListener[] sessionActivationListeners;
  private final HttpSessionAttributeListener[] sessionAttributeListeners;
  private final HttpSessionListener[] sessionListeners;
  private Throwable contextStartupError;
  private final Map<String, String> exactServletMatchMounts;
  private final Mapping[] patternMatches;
  private final Mapping[] filterPatternsRequest;
  private final Mapping[] filterPatternsForward;
  private final Mapping[] filterPatternsInclude;
  private final Mapping[] filterPatternsError;
  private AuthenticationHandler authenticationHandler;
  private AuthenticationRealm authenticationRealm;
  private final String[] welcomeFiles;
  private Integer sessionTimeout;
  private final Class<?>[] errorPagesByExceptionKeysSorted;
  private final Map<Class<?>, String> errorPagesByException;
  private final Map<String, String> errorPagesByCode;
  private final Map<String, String> localeEncodingMap;
  private String defaultServletName;
  private String errorServletName;
  private AccessLogger accessLogger;
  private final Map<String, FilterConfiguration[]> filterMatchCache;
  private final boolean useSavedSessions;
  
  public static String getTextFromNode(Node node)
  {
    if (node == null) {
      return null;
    }
    Node child = node.getFirstChild();
    if (child == null) {
      return "";
    }
    String textNode = child.getNodeValue();
    if (textNode == null) {
      return "";
    }
    return textNode.trim();
  }
  
  public static boolean useSavedSessions(Map<String, String> args)
  {
    return StringUtils.booleanArg(args, "useSavedSessions", Boolean.FALSE.booleanValue());
  }
  
  public WebAppConfiguration(HostConfiguration ownerHostConfig, Cluster cluster, JndiManager jndiManager, String webRoot, String prefix, ObjectPool objectPool, Map<String, String> startupArgs, Node elm, String contextName)
  {
    this.ownerHostConfig = ownerHostConfig;
    this.webRoot = webRoot;
    if ((!prefix.equals("")) && (!prefix.startsWith("/")))
    {
      logger.warn("WARNING: Added missing leading slash to prefix: {}", prefix);
      this.prefix = ("/" + prefix);
    }
    else
    {
      this.prefix = prefix;
    }
    this.contextName = contextName;
    
    List<File> localLoaderClassPathFiles = new ArrayList();
    loader = buildWebAppClassLoader(startupArgs, new FilteringClassLoader(Thread.currentThread().getContextClassLoader(), new String[] { "org.apache.log4j", "org.slf4j" }), webRoot, localLoaderClassPathFiles);
    
    boolean useJasper = StringUtils.booleanArg(startupArgs, "useJasper", Boolean.TRUE.booleanValue());
    boolean useInvoker = StringUtils.booleanArg(startupArgs, "useInvoker", Boolean.FALSE.booleanValue());
    boolean useJNDI = StringUtils.booleanArg(startupArgs, "useJNDI", Boolean.FALSE.booleanValue());
    useSavedSessions = useSavedSessions(startupArgs);
    if (useJasper) {
      try
      {
        Class.forName("javax.servlet.jsp.JspFactory", Boolean.TRUE.booleanValue(), Thread.currentThread().getContextClassLoader());
        Class.forName("org.apache.jasper.servlet.JspServlet", Boolean.TRUE.booleanValue(), loader);
      }
      catch (Throwable err)
      {
        if (StringUtils.booleanArg(startupArgs, "useJasper", Boolean.FALSE.booleanValue()))
        {
          logger.warn("WARNING: Jasper servlet not found - disabling JSP support. Do you have all \nthe jasper libraries in the lib folder ?");
          logger.debug("Error loading Jasper JSP compilation servlet");
        }
        useJasper = Boolean.FALSE.booleanValue();
      }
    }
    if (useInvoker) {
      try
      {
        Class.forName(InvokerServlet.class.getName(), Boolean.FALSE.booleanValue(), loader);
      }
      catch (Throwable err)
      {
        logger.warn("WARNING: Invoker servlet not found - disabling invoker support.");
        useInvoker = Boolean.FALSE.booleanValue();
      }
    }
    attributes = new HashMap();
    initParameters = new HashMap();
    sessions = new HashMap();
    
    servletInstances = new HashMap();
    filterInstances = new HashMap();
    filterMatchCache = new HashMap();
    
    List<ServletContextAttributeListener> contextAttributeListeners = new ArrayList();
    List<ServletContextListener> contextListeners = new ArrayList();
    List<ServletRequestListener> requestListeners = new ArrayList();
    List<ServletRequestAttributeListener> requestAttributeListeners = new ArrayList();
    List<HttpSessionActivationListener> sessionActivationListeners = new ArrayList();
    List<HttpSessionAttributeListener> sessionAttributeListeners = new ArrayList();
    List<HttpSessionListener> sessionListeners = new ArrayList();
    
    errorPagesByException = new HashMap();
    errorPagesByCode = new HashMap();
    boolean distributable = Boolean.FALSE.booleanValue();
    
    exactServletMatchMounts = new HashMap();
    List<Mapping> localFolderPatterns = new ArrayList();
    List<Mapping> localExtensionPatterns = new ArrayList();
    
    List<Mapping> lfpRequest = new ArrayList();
    List<Mapping> lfpForward = new ArrayList();
    List<Mapping> lfpInclude = new ArrayList();
    List<Mapping> lfpError = new ArrayList();
    
    List<String> localWelcomeFiles = new ArrayList();
    List<ServletConfiguration> startupServlets = new ArrayList();
    
    Set<String> rolesAllowed = new HashSet();
    List<Node> constraintNodes = new ArrayList();
    List<Node> envEntryNodes = new ArrayList();
    List<Class<?>> localErrorPagesByExceptionList = new ArrayList();
    
    Node loginConfigNode = null;
    
    addListenerInstance(loader, contextAttributeListeners, contextListeners, requestAttributeListeners, requestListeners, sessionActivationListeners, sessionAttributeListeners, sessionListeners);
    
    localeEncodingMap = new HashMap();
    String encodingMapSet = "en_US=8859_1;en=8859_1;ja=SJIS";
    StringTokenizer st = new StringTokenizer("en_US=8859_1;en=8859_1;ja=SJIS", ";");
    while (st.hasMoreTokens())
    {
      String token = st.nextToken();
      int delimPos = token.indexOf("=");
      if (delimPos != -1) {
        localeEncodingMap.put(token.substring(0, delimPos), token.substring(delimPos + 1));
      }
    }
    List<String> jspMappings = new ArrayList();
    jspMappings.add("*.jsp");
    jspMappings.add("*.jspx");
    
    String userName = System.getProperty("user.name", "anyone");
    File tmpDir = new File(new File(new File(new File(System.getProperty("java.io.tmpdir"), userName), "winstone.tmp"), ownerHostConfig.getHostname()), contextName);
    tmpDir.mkdirs();
    attri
1 2 3 4 5 6 7 8 9 10 11 12 13 14

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd