org.eclipse.jetty.servlet_8.1.3.v20120522

16:45:24.843 INFO  jd.cli.Main - Decompiling org.eclipse.jetty.servlet_8.1.3.v20120522.jar
package org.eclipse.jetty.servlet.jmx;

import org.eclipse.jetty.jmx.ObjectMBean;
import org.eclipse.jetty.servlet.ServletMapping;

public class ServletMappingMBean
  extends ObjectMBean
{
  public ServletMappingMBean(Object managedObject)
  {
    super(managedObject);
  }
  
  public String getObjectNameBasis()
  {
    if ((_managed != null) && ((_managed instanceof ServletMapping)))
    {
      ServletMapping mapping = (ServletMapping)_managed;
      String name = mapping.getServletName();
      if (name != null) {
        return name;
      }
    }
    return super.getObjectNameBasis();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.servlet.jmx.ServletMappingMBean
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.servlet.jmx;

import org.eclipse.jetty.jmx.ObjectMBean;
import org.eclipse.jetty.servlet.Holder;

public class HolderMBean
  extends ObjectMBean
{
  public HolderMBean(Object managedObject)
  {
    super(managedObject);
  }
  
  public String getObjectNameBasis()
  {
    if ((_managed != null) && ((_managed instanceof Holder)))
    {
      Holder holder = (Holder)_managed;
      String name = holder.getName();
      if (name != null) {
        return name;
      }
    }
    return super.getObjectNameBasis();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.servlet.jmx.HolderMBean
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.servlet.jmx;

import org.eclipse.jetty.jmx.ObjectMBean;
import org.eclipse.jetty.servlet.FilterMapping;

public class FilterMappingMBean
  extends ObjectMBean
{
  public FilterMappingMBean(Object managedObject)
  {
    super(managedObject);
  }
  
  public String getObjectNameBasis()
  {
    if ((_managed != null) && ((_managed instanceof FilterMapping)))
    {
      FilterMapping mapping = (FilterMapping)_managed;
      String name = mapping.getFilterName();
      if (name != null) {
        return name;
      }
    }
    return super.getObjectNameBasis();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.servlet.jmx.FilterMappingMBean
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.servlet;

import java.io.IOException;
import java.util.Stack;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.eclipse.jetty.util.log.Logger;

class ServletHolder$SingleThreadedWrapper
  implements Servlet
{
  Stack<Servlet> _stack = new Stack();
  
  private ServletHolder$SingleThreadedWrapper(ServletHolder paramServletHolder) {}
  
  public void destroy()
  {
    synchronized (this)
    {
      while (_stack.size() > 0)
      {
        try
        {
          ((Servlet)_stack.pop()).destroy();
        }
        catch (Exception e) {}
        ServletHolder.access$200().warn(e);
      }
    }
  }
  
  public ServletConfig getServletConfig()
  {
    return ServletHolder.access$300(this$0);
  }
  
  public String getServletInfo()
  {
    return null;
  }
  
  public void init(ServletConfig config)
    throws ServletException
  {
    synchronized (this)
    {
      if (_stack.size() == 0) {
        try
        {
          Servlet s = this$0.newInstance();
          s.init(config);
          _stack.push(s);
        }
        catch (ServletException e)
        {
          throw e;
        }
        catch (Exception e)
        {
          throw new ServletException(e);
        }
      }
    }
  }
  
  public void service(ServletRequest req, ServletResponse res)
    throws ServletException, IOException
  {
    Servlet s;
    synchronized (this)
    {
      Servlet s;
      if (_stack.size() > 0) {
        s = (Servlet)_stack.pop();
      } else {
        try
        {
          s = this$0.newInstance();
          s.init(ServletHolder.access$300(this$0));
        }
        catch (ServletException e)
        {
          throw e;
        }
        catch (Exception e)
        {
          throw new ServletException(e);
        }
      }
    }
    try
    {
      s.service(req, res);
    }
    finally
    {
      synchronized (this)
      {
        _stack.push(s);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.servlet.ServletHolder.SingleThreadedWrapper
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.servlet;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.servlet.descriptor.JspConfigDescriptor;
import javax.servlet.descriptor.JspPropertyGroupDescriptor;
import javax.servlet.descriptor.TaglibDescriptor;

public class ServletContextHandler$JspConfig
  implements JspConfigDescriptor
{
  private List<TaglibDescriptor> _taglibs = new ArrayList();
  private List<JspPropertyGroupDescriptor> _jspPropertyGroups = new ArrayList();
  
  public Collection<TaglibDescriptor> getTaglibs()
  {
    return new ArrayList(_taglibs);
  }
  
  public void addTaglibDescriptor(TaglibDescriptor d)
  {
    _taglibs.add(d);
  }
  
  public Collection<JspPropertyGroupDescriptor> getJspPropertyGroups()
  {
    return new ArrayList(_jspPropertyGroups);
  }
  
  public void addJspPropertyGroup(JspPropertyGroupDescriptor g)
  {
    _jspPropertyGroups.add(g);
  }
  
  public String toString()
  {
    StringBuffer sb = new StringBuffer();
    sb.append("JspConfigDescriptor: \n");
    for (TaglibDescriptor taglib : _taglibs) {
      sb.append(taglib + "\n");
    }
    for (JspPropertyGroupDescriptor jpg : _jspPropertyGroups) {
      sb.append(jpg + "\n");
    }
    return sb.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.servlet.ServletContextHandler.JspConfig
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.servlet;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.AbstractHttpConnection;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.LazyList;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.Logger;

class ServletHandler$CachedChain
  implements FilterChain
{
  FilterHolder _filterHolder;
  CachedChain _next;
  ServletHolder _servletHolder;
  
  ServletHandler$CachedChain(ServletHandler paramServletHandler, Object filters, ServletHolder servletHolder)
  {
    if (LazyList.size(filters) > 0)
    {
      _filterHolder = ((FilterHolder)LazyList.get(filters, 0));
      filters = LazyList.remove(filters, 0);
      _next = new CachedChain(paramServletHandler, filters, servletHolder);
    }
    else
    {
      _servletHolder = servletHolder;
    }
  }
  
  public void doFilter(ServletRequest request, ServletResponse response)
    throws IOException, ServletException
  {
    Request baseRequest = (request instanceof Request) ? (Request)request : AbstractHttpConnection.getCurrentConnection().getRequest();
    if (_filterHolder != null)
    {
      if (ServletHandler.access$000().isDebugEnabled()) {
        ServletHandler.access$000().debug("call filter " + _filterHolder, new Object[0]);
      }
      Filter filter = _filterHolder.getFilter();
      if (_filterHolder.isAsyncSupported())
      {
        filter.doFilter(request, response, _next);
      }
      else
      {
        boolean suspendable = baseRequest.isAsyncSupported();
        if (suspendable) {
          try
          {
            baseRequest.setAsyncSupported(false);
            filter.doFilter(request, response, _next);
          }
          finally
          {
            baseRequest.setAsyncSupported(true);
          }
        } else {
          filter.doFilter(request, response, _next);
        }
      }
      return;
    }
    HttpServletRequest srequest = (HttpServletRequest)request;
    if (_servletHolder != null)
    {
      if (ServletHandler.access$000().isDebugEnabled()) {
        ServletHandler.access$000().debug("call servlet " + _servletHolder, new Object[0]);
      }
      _servletHolder.handle(baseRequest, request, response);
    }
    else if (this$0.getHandler() == null)
    {
      this$0.notFound(srequest, (HttpServletResponse)response);
    }
    else
    {
      this$0.nextHandle(URIUtil.addPaths(srequest.getServletPath(), srequest.getPathInfo()), baseRequest, srequest, (HttpServletResponse)response);
    }
  }
  
  public String toString()
  {
    if (_filterHolder != null) {
      return _filterHolder + "->" + _next.toString();
    }
    if (_servletHolder != null) {
      return _servletHolder.toString();
    }
    return "null";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.servlet.ServletHandler.CachedChain
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.AbstractHttpConnection;
import org.eclipse.jetty.server.Dispatcher;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

public class ErrorPageErrorHandler
  extends ErrorHandler
{
  private static final Logger LOG = Log.getLogger(ErrorPageErrorHandler.class);
  public static final String ERROR_PAGE = "org.eclipse.jetty.server.error_page";
  protected ServletContext _servletContext;
  private final Map<String, String> _errorPages = new HashMap();
  private final List<ErrorCodeRange> _errorPageList = new ArrayList();
  
  public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
    throws IOException
  {
    String method = request.getMethod();
    if ((!method.equals("GET")) && (!method.equals("POST")) && (!method.equals("HEAD")))
    {
      AbstractHttpConnection.getCurrentConnection().getRequest().setHandled(true);
      return;
    }
    if (_errorPages != null)
    {
      String error_page = null;
      Class<?> exClass = (Class)request.getAttribute("javax.servlet.error.exception_type");
      if (ServletException.class.equals(exClass))
      {
        error_page = (String)_errorPages.get(exClass.getName());
        if (error_page == null)
        {
          Throwable th = (Throwable)request.getAttribute("javax.servlet.error.exception");
          while ((th instanceof ServletException)) {
            th = ((ServletException)th).getRootCause();
          }
          if (th != null) {
            exClass = th.getClass();
          }
        }
      }
      while ((error_page == null) && (exClass != null))
      {
        error_page = (String)_errorPages.get(exClass.getName());
        exClass = exClass.getSuperclass();
      }
      if (error_page == null)
      {
        Integer code = (Integer)request.getAttribute("javax.servlet.error.status_code");
        if (code != null)
        {
          error_page = (String)_errorPages.get(Integer.toString(code.intValue()));
          if ((error_page == null) && (_errorPageList != null)) {
            for (int i = 0; i < _errorPageList.size(); i++)
            {
              ErrorCodeRange errCode = (ErrorCodeRange)_errorPageList.get(i);
              if (errCode.isInRange(code.intValue()))
              {
                error_page = errCode.getUri();
                break;
              }
            }
          }
        }
      }
      if (error_page != null)
      {
        String old_error_page = (String)request.getAttribute("org.eclipse.jetty.server.error_page");
        if ((old_error_page == null) || (!old_error_page.equals(error_page)))
        {
          request.setAttribute("org.eclipse.jetty.server.error_page", error_page);
          
          Dispatcher dispatcher = (Dispatcher)_servletContext.getRequestDispatcher(error_page);
          try
          {
            if (dispatcher != null)
            {
              dispatcher.error(request, response);
              return;
            }
            LOG.warn("No error page " + error_page, new Object[0]);
          }
          catch (ServletException e)
          {
            LOG.warn("EXCEPTION ", e);
            return;
          }
        }
      }
    }
    super.handle(target, baseRequest, request, response);
  }
  
  public Map<String, String> getErrorPages()
  {
    return _errorPages;
  }
  
  public void setErrorPages(Map<String, String> errorPages)
  {
    _errorPages.clear();
    if (errorPages != null) {
      _errorPages.putAll(errorPages);
    }
  }
  
  public void addErrorPage(Class<? extends Throwable> exception, String uri)
  {
    _errorPages.put(exception.getName(), uri);
  }
  
  public void addErrorPage(String exceptionClassName, String uri)
  {
    _errorPages.put(exceptionClassName, uri);
  }
  
  public void addErrorPage(int code, String uri)
  {
    _errorPages.put(Integer.toString(code), uri);
  }
  
  public void addErrorPage(int from, int to, String uri)
  {
    _errorPageList.add(new ErrorCodeRange(from, to, uri));
  }
  
  protected void doStart()
    throws Exception
  {
    super.doStart();
    _servletContext = ContextHandler.getCurrentContext();
  }
  
  protected void doStop()
    throws Exception
  {
    super.doStop();
  }
  
  private class ErrorCodeRange
  {
    private int _from;
    private int _to;
    private String _uri;
    
    ErrorCodeRange(int from, int to, String uri)
      throws IllegalArgumentException
    {
      if (from > to) {
        throw new IllegalArgumentException("from>to");
      }
      _from = from;
      _to = to;
      _uri = uri;
    }
    
    boolean isInRange(int value)
    {
      if ((value >= _from) && (value <= _to)) {
        return true;
      }
      return false;
    }
    
    String getUri()
    {
      return _uri;
    }
    
    public String toString()
    {
      return "from: " + _from + ",to: " + _to + ",uri: " + _uri;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.servlet.ErrorPageErrorHandler
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.servlet.listener;

import java.beans.Introspector;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class IntrospectorCleaner
  implements ServletContextListener
{
  public void contextInitialized(ServletContextEvent sce) {}
  
  public void contextDestroyed(ServletContextEvent sce) {}
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.servlet.listener.IntrospectorCleaner
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.servlet.listener;

import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

public class ELContextCleaner
  implements ServletContextListener
{
  private static final Logger LOG = Log.getLogger(ELContextCleaner.class);
  
  public void contextInitialized(ServletContextEvent sce) {}
  
  public void contextDestroyed(ServletContextEvent sce)
  {
    try
    {
      Class beanELResolver = Loader.loadClass(getClass(), "javax.el.BeanELResolver");
      
      Field field = getField(beanELResolver);
      
      purgeEntries(field);
      
      LOG.info("javax.el.BeanELResolver purged", new Object[0]);
    }
    catch (ClassNotFoundException e) {}catch (SecurityException e)
    {
      LOG.warn("Cannot purge classes from javax.el.BeanELResolver", e);
    }
    catch (IllegalArgumentException e)
    {
      LOG.warn("Cannot purge classes from javax.el.BeanELResolver", e);
    }
    catch (IllegalAccessException e)
    {
      LOG.warn("Cannot purge classes from javax.el.BeanELResolver", e);
    }
    catch (NoSuchFieldException e)
    {
      LOG.info("Not cleaning cached beans: no such field javax.el.BeanELResolver.properties", new Object[0]);
    }
  }
  
  protected Field getField(Class beanELResolver)
    throws SecurityException, NoSuchFieldException
  {
    if (beanELResolver == null) {
      return null;
    }
    return beanELResolver.getDeclaredField("properties");
  }
  
  protected void purgeEntries(Field properties)
    throws IllegalArgumentException, IllegalAccessException
  {
    if (properties == null) {
      return;
    }
    if (!properties.isAccessible()) {
      properties.setAccessible(true);
    }
    ConcurrentHashMap map = (ConcurrentHashMap)properties.get(null);
    if (map == null) {
      return;
    }
    Iterator<Class> itor = map.keySet().iterator();
    while (itor.hasNext())
    {
      Class clazz = (Class)itor.next();
      LOG.info("Clazz: " + clazz + " loaded by " + clazz.getClassLoader(), new Object[0]);
      if (Thread.currentThread().getContextClassLoader().equals(clazz.getClassLoader()))
      {
        itor.remove();
        LOG.info("removed", new Object[0]);
      }
      else
      {
        LOG.info("not removed: contextclassloader=" + Thread.currentThread().getContextClassLoader() + "clazz's classloader=" + clazz.getClassLoader(), new Object[0]);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.servlet.listener.ELContextCleaner
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import javax.servlet.MultipartConfigElement;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.ServletSecurityElement;
import javax.servlet.SingleThreadModel;
import javax.servlet.UnavailableException;
import org.eclipse.jetty.security.IdentityService;
import org.eclipse.jetty.security.RunAsToken;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.UserIdentity.Scope;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

public class ServletHolder
  extends Holder<Servlet>
  implements UserIdentity.Scope, Comparable
{
  private static final Logger LOG = Log.getLogger(ServletHolder.class);
  private int _initOrder;
  private boolean _initOnStartup = false;
  private Map<String, String> _roleMap;
  private String _forcedPath;
  private String _runAsRole;
  private RunAsToken _runAsToken;
  private IdentityService _identityService;
  private ServletRegistration.Dynamic _registration;
  private transient Servlet _servlet;
  private transient Config _config;
  private transient long _unavailable;
  private transient boolean _enabled = true;
  private transient UnavailableException _unavailableEx;
  public static final Map<String, String> NO_MAPPED_ROLES = Collections.emptyMap();
  
  public ServletHolder()
  {
    super(Holder.Source.EMBEDDED);
  }
  
  public ServletHolder(Holder.Source creator)
  {
    super(creator);
  }
  
  public ServletHolder(Servlet servlet)
  {
    super(Holder.Source.EMBEDDED);
    setServlet(servlet);
  }
  
  public ServletHolder(String name, Class<? extends Servlet> servlet)
  {
    super(Holder.Source.EMBEDDED);
    setName(name);
    setHeldClass(servlet);
  }
  
  public ServletHolder(String name, Servlet servlet)
  {
    super(Holder.Source.EMBEDDED);
    setName(name);
    setServlet(servlet);
  }
  
  public ServletHolder(Class<? extends Servlet> servlet)
  {
    super(Holder.Source.EMBEDDED);
    setHeldClass(servlet);
  }
  
  public UnavailableException getUnavailableException()
  {
    return _unavailableEx;
  }
  
  public synchronized void setServlet(Servlet servlet)
  {
    if ((servlet == null) || ((servlet instanceof SingleThreadModel))) {
      throw new IllegalArgumentException();
    }
    _extInstance = true;
    _servlet = servlet;
    setHeldClass(servlet.getClass());
    if (getName() == null) {
      setName(servlet.getClass().getName() + "-" + super.hashCode());
    }
  }
  
  public int getInitOrder()
  {
    return _initOrder;
  }
  
  public void setInitOrder(int order)
  {
    _initOnStartup = true;
    _initOrder = order;
  }
  
  public boolean isSetInitOrder()
  {
    return _initOnStartup;
  }
  
  public int compareTo(Object o)
  {
    if ((o instanceof ServletHolder))
    {
      ServletHolder sh = (ServletHolder)o;
      if (sh == this) {
        return 0;
      }
      if (_initOrder < _initOrder) {
        return 1;
      }
      if (_initOrder > _initOrder) {
        return -1;
      }
      int c = (_className != null) && (_className != null) ? _className.compareTo(_className) : 0;
      if (c == 0) {
        c = _name.compareTo(_name);
      }
      if (c == 0) {
        c = hashCode() > o.hashCode() ? 1 : -1;
      }
      return c;
    }
    return 1;
  }
  
  public boolean equals(Object o)
  {
    return compareTo(o) == 0;
  }
  
  public int hashCode()
  {
    return _name == null ? System.identityHashCode(this) : _name.hashCode();
  }
  
  public synchronized void setUserRoleLink(String name, String link)
  {
    if (_roleMap == null) {
      _roleMap = new HashMap();
    }
    _roleMap.put(name, link);
  }
  
  public String getUserRoleLink(String name)
  {
    if (_roleMap == null) {
      return name;
    }
    String link = (String)_roleMap.get(name);
    return link == null ? name : link;
  }
  
  public Map<String, String> getRoleMap()
  {
    return _roleMap == null ? NO_MAPPED_ROLES : _roleMap;
  }
  
  public String getForcedPath()
  {
    return _forcedPath;
  }
  
  public void setForcedPath(String forcedPath)
  {
    _forcedPath = forcedPath;
  }
  
  public boolean isEnabled()
  {
    return _enabled;
  }
  
  public void setEnabled(boolean enabled)
  {
    _enabled = enabled;
  }
  
  public void doStart()
    throws Exception
  {
    _unavailable = 0L;
    if (!_enabled) {
      return;
    }
    try
    {
      super.doStart();
      checkServletType();
    }
    catch (UnavailableException ue)
    {
      makeUnavailable(ue);
    }
    _identityService = _servletHandler.getIdentityService();
    if ((_identityService != null) && (_runAsRole != null)) {
      _runAsToken = _identityService.newRunAsToken(_runAsRole);
    }
    _config = new Config();
    if ((_class != null) && (SingleThreadModel.class.isAssignableFrom(_class))) {
      _servlet = new SingleThreadedWrapper(null);
    }
    if ((_extInstance) || (_initOnStartup)) {
      try
      {
        initServlet();
      }
      catch (Exception e)
      {
        if (_servletHandler.isStartWithUnavailable()) {
          LOG.ignore(e);
        } else {
          throw e;
        }
      }
    }
  }
  
  public void doStop()
    throws Exception
  {
    Object old_run_as = null;
    if (_servlet != null) {
      try
      {
        if (_identityService != null) {
          old_run_as = _identityService.setRunAs(_identityService.getSystemUserIdentity(), _runAsToken);
        }
        destroyInstance(_servlet);
      }
      catch (Exception e)
      {
        LOG.warn(e);
      }
      finally
      {
        if (_identityService != null) {
          _identityService.unsetRunAs(old_run_as);
        }
      }
    }
    if (!_extInstance) {
      _servlet = null;
    }
    _config = null;
  }
  
  public void destroyInstance(Object o)
    throws Exception
  {
    if (o == null) {
      return;
    }
    Servlet servlet = (Servlet)o;
    servlet.destroy();
    getServletHandler().destroyServlet(servlet);
  }
  
  public synchronized Servlet getServlet()
    throws ServletException
  {
    if (_unavailable != 0L)
    {
      if ((_unavailable < 0L) || ((_unavailable > 0L) && (System.currentTimeMillis() < _unavailable))) {
        throw _unavailableEx;
      }
      _unavailable = 0L;
      _unavailableEx = null;
    }
    if (_servlet == null) {
      initServlet();
    }
    return _servlet;
  }
  
  public Servlet getServletInstance()
  {
    return _servlet;
  }
  
  public void checkServletType()
    throws UnavailableException
  {
    if ((_class == null) || (!Servlet.class.isAssignableFrom(_class))) {
      throw new UnavailableException("Servlet " + _class + " is not a javax.servlet.Servlet");
    }
  }
  
  public boolean isAvailable()
  {
    if ((isStarted()) && (_unavailable == 0L)) {
      return true;
    }
    try
    {
      getServlet();
    }
    catch (Exception e)
    {
      LOG.ignore(e);
    }
    return (isStarted()) && (_unavailable == 0L);
  }
  
  private void makeUnavailable(UnavailableException e)
  {
    if ((_unavailableEx == e) && (_unavailable != 0L)) {
      return;
    }
    _servletHandler.getServletContext().log("unavailable", e);
    
    _unavailableEx = e;
    _unavailable = -1L;
    if (e.isPermanent()) {
      _unavailable = -1L;
    } else if (_unavailableEx.getUnavailableSeconds() > 0) {
      _unavailable = (System.currentTimeMillis() + 1000 * _unavailableEx.getUnavailableSeconds());
    } else {
      _unavailable = (System.currentTimeMillis() + 5000L);
    }
  }
  
  private void makeUnavailable(final Throwable e)
  {
    if ((e instanceof UnavailableException))
    {
      makeUnavailable((UnavailableException)e);
    }
    else
    {
      ServletContext ctx = _servletHandler.getServletContext();
      if (ctx == null) {
        LOG.info("unavailable", e);
      } else {
        ctx.log("unavailable", e);
      }
      _unavailableEx = new UnavailableException(String.valueOf(e), -1) {};
      _unavailable = -1L;
    }
  }
  
  private void initServlet()
    throws ServletException
  {
    Object old_run_as = null;
    try
    {
      if (_servlet == null) {
        _servlet = newInstance();
      }
      if (_config == null) {
        _config = new Config();
      }
      if (_identityService != null) {
        old_run_as = _identityService.setRunAs(_identityService.getSystemUserIdentity(), _runAsToken);
      }
      _servlet.init(_config);
    }
    catch (UnavailableException e)
    {
      makeUnavailable(e);
      _servlet = null;
      _config = null;
      throw e;
    }
    catch (ServletException e)
    {
      makeUnavailable(e.getCause() == null ? e : e.getCause());
      _servlet = null;
      _config = null;
      throw e;
    }
    catch (Exception e)
    {
      makeUnavailable(e);
      _servlet = null;
      _config = null;
      throw new ServletException(toString(), e);
    }
    finally
    {
      if (_identityService != null) {
        _identityService.unsetRunAs(old_run_as);
      }
    }
  }
  
  public String getContextPath()
  {
    return _config.getServletContext().getContextPath();
  }
  
  public Map<String, String> getRoleRefMap()
  {
    return _roleMap;
  }
  
  public String getRunAsRole()
  {
    return _runAsRole;
  }
  
  public void setRunAsRole(String role)
  {
    _runAsRole = role;
  }
  
  public void handle(Request baseRequest, ServletRequest request, ServletResponse response)
    throws ServletException, UnavailableException, IOException
  {
    if (_class == null) {
      throw new UnavailableException("Servlet Not Initialized");
    }
    Servlet servlet = _servlet;
    synchronized (this)
    {
      if ((_unavailable != 0L) || (!_initOnStartup)) {
        servlet = getServlet();
      }
      if (servlet == null) {
        throw new UnavailableException("Could not instantiate " + _class);
      }
    }
    boolean servlet_error = true;
    Object old_run_as = null;
    boolean suspendable = baseRequest.isAsyncSupported();
    try
    {
      if (_forcedPath != null) {
        request.setAttribute("org.apache.catalina.jsp_file", _forcedPath);
      }
      if (_identityService != null) {
        old_run_as = _identityService.setRunAs(baseRequest.getResolvedUserIdentity(), _runAsToken);
      }
      if (!isAsyncSupported()) {
        baseRequest.setAsyncSupported(false);
      }
      MultipartConfigElement mpce = ((Registration)getRegistration()).getMultipartConfig();
      if (mpce != null) {
        request.setAttribute("org.eclipse.multipartConfig", mpce);
      }
      servlet.service(request, response);
      servlet_error = false;
    }
    catch (UnavailableException e)
    {
      makeUnavailable(e);
      throw _unavailableEx;
    }
    finally
    {
      baseRequest.setAsyncSupported(suspendable);
      if (_identityService != null) {
        _identityService.unsetRunAs(old_run_as);
      }
      if (servlet_error) {
        request.setAttribute("javax.servlet.error.servlet_name", getName());
      }
    }
  }
  
  protected class Config
    extends Holder.HolderConfig
    implements ServletConfig
  {
    protected Config()
    {
      super();
    }
    
    public String getServletName()
    {
      return getName();
    }
  }
  
  public class Registration
    extends Holder.HolderRegistration
    implements ServletRegistration.Dynamic
  {
    protected MultipartConfigElement _multipartConfig;
    
    public Registration()
    {
      super();
    }
    
    public Set<String> addMapping(String... urlPatterns)
    {
      illegalStateIfContextStarted();
      Set<String> clash = null;
      for (String pattern : urlPatterns) {
        if (_servletHandler.getServletMapping(pattern) != null)
        {
          if (clash == null) {
            clash = new HashSet();
          }
          clash.add(pattern);
        }
      }
      if (clash != null) {
        return clash;
      }
      ServletMapping mapping = new ServletMapping();
      mapping.setServletName(ServletHolder.this.getName());
      mapping.setPathSpecs(urlPatterns);
      _servletHandler.addServletMapping(mapping);
      
      return Collections.emptySet();
    }
    
    public Collection<String> getMappings()
    {
      ServletMapping[] mappings = _servletHandler.getServletMappings();
      List<String> patterns = new ArrayList();
      if (mappings != null) {
        for (ServletMapping mapping : mappings) {
          if (mapping.getServletName().equals(getName()))
          {
            String[] specs = mapping.getPathSpecs();
            if ((specs != null) && (specs.length > 0)) {
              patterns.addAll(Arrays.asList(specs));
            }
          }
        }
      }
      return patterns;
    }
    
    public String getRunAsRole()
    {
      return _runAsRole;
    }
    
    public void setLoadOnStartup(int loadOnStartup)
    {
      illegalStateIfContextStarted();
      setInitOrder(loadOnStartup);
    }
    
    public int getInitOrder()
    {
      return ServletHolder.this.getInitOrder();
    }
    
    public void setMultipartConfig(MultipartConfigElement element)
    {
      _multipartConfig = element;
    }
    
    public MultipartConfigElement getMultipartConfig()
    {
      return _multipartConfig;
    }
    
    public void setRunAsRole(String role)
    {
      _runAsRole = role;
    }
    
    public Set<String> setServletSecurity(ServletSecurityElement securityElement)
    {
      return _servletHandler.setServletSecurity(this, securityElement);
    }
  }
  
  public ServletRegistration.Dynamic getRegistration()
  {
    if (_registration == null) {
      _registration = new Registration();
    }
    return _registration;
  }
  
  private class SingleThreadedWrapper
    implements Servlet
  {
    Stack<Servlet> _stack = new Stack();
    
    private SingleThreadedWrapper() {}
    
    public void destroy()
    {
      synchronized (this)
      {
        while (_stack.size() > 0)
        {
          try
          {
            ((Servlet)_stack.pop()).destroy();
          }
          catch (Exception e) {}
          ServletHolder.LOG.warn(e);
        }
      }
    }
    
    public ServletConfig getServletConfig()
    {
      return _config;
    }
    
    public String getServletInfo()
    {
      return null;
    }
    
    public void init(ServletConfig config)
      throws ServletException
    {
      synchronized (this)
      {
        if (_stack.size() == 0) {
          try
          {
            Servlet s = newInstance();
            s.init(config);
            _stack.push(s);
          }
          catch (ServletException e)
          {
            throw e;
          }
          catch (Exception e)
          {
            throw new ServletException(e);
          }
        }
      }
    }
    
    public void service(ServletRequest req, ServletResponse res)
      throws ServletException, IOException
    {
      Servlet s;
      synchronized (this)
      {
        Servlet s;
        if (_stack.size() > 0) {
          s = (Servlet)_stack.pop();
        } else {
          try
          {
            s = newInstance();
            s.init(_config);
          }
          catch (ServletException e)
          {
            throw e;
          }
          catch (Exception e)
          {
            throw new ServletException(e);
          }
        }
      }
      try
      {
        s.service(req, res);
      }
      finally
      {
        synchronized (this)
        {
          _stack.push(s);
        }
      }
    }
  }
  
  protected Servlet newInstance()
    throws ServletException, IllegalAccessException, InstantiationException
  {
    try
    {
      ServletContext ctx = getServletHandler().getServletContext();
      if (ctx == null) {
        return (Servlet)getHeldClass().newInstance();
      }
      return ((ServletContextHandler.Context)ctx).createServlet(getHeldClass());
    }
    catch (ServletException se)
    {
      Throwable cause = se.getRootCause();
      if ((cause instanceof InstantiationException)) {
        throw ((InstantiationException)cause);
      }
      if ((cause instanceof IllegalAccessException)) {
        throw ((IllegalAccessException)cause);
      }
      throw se;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.servlet.ServletHolder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.servlet;

import javax.servlet.descriptor.TaglibDescriptor;

public class ServletContextHandler$TagLib
  implements TaglibDescriptor
{
  private String _uri;
  private String _location;
  
  public String getTaglibURI()
  {
    return _uri;
  }
  
  public void setTaglibURI(String uri)
  {
    _uri = uri;
  }
  
  public String getTaglibLocation()
  {
    return _location;
  }
  
  public void setTaglibLocation(String location)
  {
    _location = location;
  }
  
  public String toString()
  {
    return "TagLibDescriptor: taglib-uri=" + _uri + " location=" + _location;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.servlet.ServletContextHandler.TagLib
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.ServletSecurityElement;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.continuation.ContinuationThrowable;
import org.eclipse.jetty.http.HttpException;
import org.eclipse.jetty.http.PathMap;
import org.eclipse.jetty.http.PathMap.Entry;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.RuntimeIOException;
import org.eclipse.jetty.security.IdentityService;
import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.server.AbstractHttpConnection;
import org.eclipse.jetty.server.Dispatcher;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServletRequestHttpWrapper;
import org.eclipse.jetty.server.ServletResponseHttpWrapper;
import org.eclipse.jetty.server.UserIdentity.Scope;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandler.Context;
import org.eclipse.jetty.server.handler.ScopedHandler;
import org.eclipse.jetty.util.LazyList;
import org.eclipse.jetty.util.MultiException;
import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.component.Container;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

public class ServletHandler
  extends ScopedHandler
{
  private static final Logger LOG = Log.getLogger(ServletHandler.class);
  public static final String __DEFAULT_SERVLET = "default";
  private ServletContextHandler _contextHandler;
  private ContextHandler.Context _servletContext;
  private FilterHolder[] _filters = new FilterHolder[0];
  private FilterMapping[] _filterMappings;
  private boolean _filterChainsCached = true;
  private int _maxFilterChainsCacheSize = 512;
  private boolean _startWithUnavailable = true;
  private IdentityService _identityService;
  private ServletHolder[] _servlets = new ServletHolder[0];
  private ServletMapping[] _servletMappings;
  private final Map<String, FilterHolder> _filterNameMap = new HashMap();
  private List<FilterMapping> _filterPathMappings;
  private MultiMap<String> _filterNameMappings;
  private final Map<String, ServletHolder> _servletNameMap = new HashMap();
  private PathMap _servletPathMap;
  protected final ConcurrentMap<String, FilterChain>[] _chainCache = new ConcurrentMap[31];
  protected final Queue<String>[] _chainLRU = new Queue[31];
  
  public void setServer(Server server)
  {
    Server old = getServer();
    if ((old != null) && (old != server))
    {
      getServer().getContainer().update(this, _filters, null, "filter", true);
      getServer().getContainer().update(this, _filterMappings, null, "filterMapping", true);
      getServer().getContainer().update(this, _servlets, null, "servlet", true);
      getServer().getContainer().update(this, _servletMappings, null, "servletMapping", true);
    }
    super.setServer(server);
    if ((server != null) && (old != server))
    {
      server.getContainer().update(this, null, _filters, "filter", true);
      server.getContainer().update(this, null, _filterMappings, "filterMapping", true);
      server.getContainer().update(this, null, _servlets, "servlet", true);
      server.getContainer().update(this, null, _servletMappings, "servletMapping", true);
    }
  }
  
  protected synchronized void doStart()
    throws Exception
  {
    _servletContext = ContextHandler.getCurrentContext();
    _contextHand
1 2 3 4 5

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-2017. Infinite Loop Ltd