org.eclipse.equinox.http.servlet_1.1.300.v20120912-130548

16:43:57.395 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.http.servlet_1.1.300.v20120912-130548.jar
package org.eclipse.equinox.http.servlet;

import java.util.Dictionary;
import javax.servlet.Filter;
import javax.servlet.ServletException;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;

public abstract interface ExtendedHttpService
  extends HttpService
{
  public abstract void registerFilter(String paramString, Filter paramFilter, Dictionary paramDictionary, HttpContext paramHttpContext)
    throws ServletException, NamespaceException;
  
  public abstract void unregisterFilter(Filter paramFilter);
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.ExtendedHttpService
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet;

import org.eclipse.equinox.http.servlet.internal.ProxyServlet;

public class HttpServiceServlet
  extends ProxyServlet
{
  private static final long serialVersionUID = -3647550992964861187L;
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.HttpServiceServlet
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
import javax.servlet.GenericServlet;
import javax.servlet.ServletConfig;
import org.eclipse.equinox.http.servlet.ExtendedHttpService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.http.HttpService;

public class Activator
  implements BundleActivator
{
  private static final String DEFAULT_SERVICE_DESCRIPTION = "Equinox Servlet Bridge";
  private static final String DEFAULT_SERVICE_VENDOR = "Eclipse.org";
  private static final String[] HTTP_SERVICES_CLASSES = { HttpService.class.getName(), ExtendedHttpService.class.getName() };
  private static BundleContext context;
  private static Map serviceRegistrations = new HashMap();
  
  public void start(BundleContext bundleContext)
    throws Exception
  {
    startHttpServiceProxy(bundleContext);
  }
  
  public void stop(BundleContext bundleContext)
    throws Exception
  {
    stopHttpServiceProxy(bundleContext);
  }
  
  private static synchronized void startHttpServiceProxy(BundleContext bundleContext)
  {
    context = bundleContext;
    Object[] proxyServlets = serviceRegistrations.keySet().toArray();
    for (int i = 0; i < proxyServlets.length; i++)
    {
      ServiceRegistration registration = registerHttpService((ProxyServlet)proxyServlets[i]);
      serviceRegistrations.put(proxyServlets[i], registration);
    }
  }
  
  private static synchronized void stopHttpServiceProxy(BundleContext bundleContext)
  {
    Object[] proxyServlets = serviceRegistrations.keySet().toArray();
    for (int i = 0; i < proxyServlets.length; i++)
    {
      ServiceRegistration registration = (ServiceRegistration)serviceRegistrations.put(proxyServlets[i], null);
      registration.unregister();
    }
    serviceRegistrations.clear();
    context = null;
  }
  
  static synchronized void addProxyServlet(ProxyServlet proxyServlet)
  {
    ServiceRegistration registration = null;
    if (context != null) {
      registration = registerHttpService(proxyServlet);
    }
    serviceRegistrations.put(proxyServlet, registration);
  }
  
  private static ServiceRegistration registerHttpService(ProxyServlet proxyServlet)
  {
    HttpServiceFactory factory = new HttpServiceFactory(proxyServlet);
    Dictionary serviceProperties = new Hashtable(2);
    ServletConfig config = proxyServlet.getServletConfig();
    Enumeration initparameterNames = config.getInitParameterNames();
    while (initparameterNames.hasMoreElements())
    {
      String name = (String)initparameterNames.nextElement();
      serviceProperties.put(name, config.getInitParameter(name));
    }
    if (serviceProperties.get("service.vendor") == null) {
      serviceProperties.put("service.vendor", "Eclipse.org");
    }
    if (serviceProperties.get("service.description") == null) {
      serviceProperties.put("service.description", "Equinox Servlet Bridge");
    }
    return context.registerService(HTTP_SERVICES_CLASSES, factory, serviceProperties);
  }
  
  static synchronized void removeProxyServlet(ProxyServlet proxyServlet)
  {
    ServiceRegistration registration = (ServiceRegistration)serviceRegistrations.remove(proxyServlet);
    if (registration != null) {
      registration.unregister();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.internal.Activator
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import java.io.IOException;
import java.net.URL;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osgi.framework.Bundle;
import org.osgi.service.http.HttpContext;

public class DefaultHttpContext
  implements HttpContext
{
  private Bundle bundle;
  
  public DefaultHttpContext(Bundle bundle)
  {
    this.bundle = bundle;
  }
  
  public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response)
    throws IOException
  {
    return true;
  }
  
  public URL getResource(String name)
  {
    return bundle.getResource(name);
  }
  
  public String getMimeType(String name)
  {
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.internal.DefaultHttpContext
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import java.io.IOException;
import java.util.List;
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;

public class FilterChainImpl
  implements FilterChain
{
  private List matchingFilterRegistrations;
  private ServletRegistration registration;
  private int filterIndex = 0;
  private int filterCount;
  
  public FilterChainImpl(List matchingFilterRegistrations, ServletRegistration registration)
  {
    this.matchingFilterRegistrations = matchingFilterRegistrations;
    this.registration = registration;
    filterCount = matchingFilterRegistrations.size();
  }
  
  public void doFilter(ServletRequest request, ServletResponse response)
    throws IOException, ServletException
  {
    if (filterIndex < filterCount)
    {
      FilterRegistration filterRegistration = (FilterRegistration)matchingFilterRegistrations.get(filterIndex++);
      filterRegistration.doFilter((HttpServletRequest)request, (HttpServletResponse)response, this);
      return;
    }
    registration.service((HttpServletRequest)request, (HttpServletResponse)response);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.internal.FilterChainImpl
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;

public class FilterConfigImpl
  implements FilterConfig
{
  private static final Dictionary EMPTY_PARAMS = new Hashtable(0);
  private static final String FILTER_NAME = "filter-name";
  private Filter filter;
  private Dictionary initparams;
  private ServletContext servletContext;
  
  public FilterConfigImpl(Filter filter, Dictionary initparams, ServletContext servletContext)
  {
    this.filter = filter;
    this.initparams = (initparams != null ? initparams : EMPTY_PARAMS);
    this.servletContext = servletContext;
  }
  
  public String getFilterName()
  {
    String filterName = (String)initparams.get("filter-name");
    return filterName != null ? filterName : filter.getClass().getName();
  }
  
  public ServletContext getServletContext()
  {
    return servletContext;
  }
  
  public String getInitParameter(String name)
  {
    return (String)initparams.get(name);
  }
  
  public Enumeration getInitParameterNames()
  {
    return initparams.keys();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.internal.FilterConfigImpl
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import javax.servlet.Filter;
import org.osgi.service.http.HttpContext;

public class FilterRegistration
  extends Registration
  implements Comparable
{
  private static long nextSequenceNumber = 1L;
  private final Filter filter;
  private final HttpContext httpContext;
  private final ClassLoader registeredContextClassLoader;
  private final String prefix;
  private final String suffix;
  private final int priority;
  private final long sequenceNumber;
  
  public FilterRegistration(Filter filter, HttpContext context, String alias, int priority)
  {
    this.filter = filter;
    httpContext = context;
    registeredContextClassLoader = Thread.currentThread().getContextClassLoader();
    
    int lastSlash = alias.lastIndexOf('/');
    String lastSegment = alias.substring(alias.lastIndexOf('/') + 1);
    if (lastSegment.startsWith("*."))
    {
      prefix = alias.substring(0, lastSlash);
      suffix = lastSegment.substring(1);
    }
    else
    {
      prefix = (alias.equals("/") ? "" : alias);
      suffix = null;
    }
    this.priority = priority;
    synchronized (FilterRegistration.class)
    {
      sequenceNumber = (nextSequenceNumber++);
    }
  }
  
  /* Error */
  public void destroy()
  {
    // Byte code:
    //   0: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   3: invokevirtual 163	java/lang/Thread:getContextClassLoader	()Ljava/lang/ClassLoader;
    //   6: astore_1
    //   7: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   10: aload_0
    //   11: getfield 148	org/eclipse/equinox/http/servlet/internal/FilterRegistration:registeredContextClassLoader	Ljava/lang/ClassLoader;
    //   14: invokevirtual 164	java/lang/Thread:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   17: aload_0
    //   18: invokespecial 168	org/eclipse/equinox/http/servlet/internal/Registration:destroy	()V
    //   21: aload_0
    //   22: getfield 151	org/eclipse/equinox/http/servlet/internal/FilterRegistration:filter	Ljavax/servlet/Filter;
    //   25: invokeinterface 169 1 0
    //   30: goto +13 -> 43
    //   33: astore_2
    //   34: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   37: aload_1
    //   38: invokevirtual 164	java/lang/Thread:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   41: aload_2
    //   42: athrow
    //   43: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   46: aload_1
    //   47: invokevirtual 164	java/lang/Thread:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   50: return
    // Line number table:
    //   Java source line #54	-> byte code offset #0
    //   Java source line #56	-> byte code offset #7
    //   Java source line #57	-> byte code offset #17
    //   Java source line #58	-> byte code offset #21
    //   Java source line #59	-> byte code offset #33
    //   Java source line #60	-> byte code offset #34
    //   Java source line #61	-> byte code offset #41
    //   Java source line #60	-> byte code offset #43
    //   Java source line #62	-> byte code offset #50
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	51	0	this	FilterRegistration
    //   6	41	1	original	ClassLoader
    //   33	9	2	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   7	33	33	finally
  }
  
  /* Error */
  public void init(javax.servlet.FilterConfig filterConfig)
    throws javax.servlet.ServletException
  {
    // Byte code:
    //   0: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   3: invokevirtual 163	java/lang/Thread:getContextClassLoader	()Ljava/lang/ClassLoader;
    //   6: astore_2
    //   7: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   10: aload_0
    //   11: getfield 148	org/eclipse/equinox/http/servlet/internal/FilterRegistration:registeredContextClassLoader	Ljava/lang/ClassLoader;
    //   14: invokevirtual 164	java/lang/Thread:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   17: aload_0
    //   18: getfield 151	org/eclipse/equinox/http/servlet/internal/FilterRegistration:filter	Ljavax/servlet/Filter;
    //   21: aload_1
    //   22: invokeinterface 170 2 0
    //   27: goto +13 -> 40
    //   30: astore_3
    //   31: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   34: aload_2
    //   35: invokevirtual 164	java/lang/Thread:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   38: aload_3
    //   39: athrow
    //   40: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   43: aload_2
    //   44: invokevirtual 164	java/lang/Thread:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   47: return
    // Line number table:
    //   Java source line #66	-> byte code offset #0
    //   Java source line #68	-> byte code offset #7
    //   Java source line #69	-> byte code offset #17
    //   Java source line #70	-> byte code offset #30
    //   Java source line #71	-> byte code offset #31
    //   Java source line #72	-> byte code offset #38
    //   Java source line #71	-> byte code offset #40
    //   Java source line #73	-> byte code offset #47
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	48	0	this	FilterRegistration
    //   0	48	1	filterConfig	javax.servlet.FilterConfig
    //   6	38	2	original	ClassLoader
    //   30	9	3	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   7	30	30	finally
  }
  
  /* Error */
  public void doFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain)
    throws java.io.IOException, javax.servlet.ServletException
  {
    // Byte code:
    //   0: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   3: invokevirtual 163	java/lang/Thread:getContextClassLoader	()Ljava/lang/ClassLoader;
    //   6: astore 4
    //   8: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   11: aload_0
    //   12: getfield 148	org/eclipse/equinox/http/servlet/internal/FilterRegistration:registeredContextClassLoader	Ljava/lang/ClassLoader;
    //   15: invokevirtual 164	java/lang/Thread:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   18: aload_0
    //   19: getfield 152	org/eclipse/equinox/http/servlet/internal/FilterRegistration:httpContext	Lorg/osgi/service/http/HttpContext;
    //   22: aload_1
    //   23: aload_2
    //   24: invokeinterface 172 3 0
    //   29: ifeq +31 -> 60
    //   32: aload_0
    //   33: getfield 151	org/eclipse/equinox/http/servlet/internal/FilterRegistration:filter	Ljavax/servlet/Filter;
    //   36: aload_1
    //   37: aload_2
    //   38: aload_3
    //   39: invokeinterface 171 4 0
    //   44: goto +16 -> 60
    //   47: astore 5
    //   49: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   52: aload 4
    //   54: invokevirtual 164	java/lang/Thread:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   57: aload 5
    //   59: athrow
    //   60: invokestatic 165	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   63: aload 4
    //   65: invokevirtual 164	java/lang/Thread:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   68: return
    // Line number table:
    //   Java source line #77	-> byte code offset #0
    //   Java source line #79	-> byte code offset #8
    //   Java source line #80	-> byte code offset #18
    //   Java source line #81	-> byte code offset #32
    //   Java source line #82	-> byte code offset #47
    //   Java source line #83	-> byte code offset #49
    //   Java source line #84	-> byte code offset #57
    //   Java source line #83	-> byte code offset #60
    //   Java source line #85	-> byte code offset #68
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	69	0	this	FilterRegistration
    //   0	69	1	request	javax.servlet.http.HttpServletRequest
    //   0	69	2	response	javax.servlet.http.HttpServletResponse
    //   0	69	3	chain	javax.servlet.FilterChain
    //   6	58	4	original	ClassLoader
    //   47	11	5	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   8	47	47	finally
  }
  
  public Filter getFilter()
  {
    return filter;
  }
  
  public HttpContext getHttpContext()
  {
    return httpContext;
  }
  
  public boolean matches(String dispatchPathInfo)
  {
    if (!dispatchPathInfo.startsWith(prefix)) {
      return false;
    }
    if (prefix.length() == dispatchPathInfo.length()) {
      return suffix == null;
    }
    if (dispatchPathInfo.charAt(prefix.length()) != '/') {
      return false;
    }
    if (suffix == null) {
      return true;
    }
    return (dispatchPathInfo.endsWith(suffix)) && (dispatchPathInfo.length() > prefix.length() + suffix.length());
  }
  
  public int compareTo(Object other)
  {
    FilterRegistration otherFilterRegistration = (FilterRegistration)other;
    int priorityDifference = priority - priority;
    if (priorityDifference != 0) {
      return -priorityDifference;
    }
    return sequenceNumber > sequenceNumber ? 1 : -1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.internal.FilterRegistration
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;

public class HttpServiceFactory
  implements ServiceFactory
{
  private ProxyServlet proxy;
  
  public HttpServiceFactory(ProxyServlet proxy)
  {
    this.proxy = proxy;
  }
  
  public Object getService(Bundle bundle, ServiceRegistration registration)
  {
    return new HttpServiceImpl(bundle, proxy);
  }
  
  public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
  {
    ((HttpServiceImpl)service).shutdown();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.internal.HttpServiceFactory
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import java.util.Dictionary;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import org.eclipse.equinox.http.servlet.ExtendedHttpService;
import org.osgi.framework.Bundle;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;

public class HttpServiceImpl
  implements HttpService, ExtendedHttpService
{
  private Bundle bundle;
  private ProxyServlet proxy;
  private Set aliases = new HashSet();
  private Set filters = new HashSet();
  private boolean shutdown = false;
  
  public HttpServiceImpl(Bundle bundle, ProxyServlet proxy)
  {
    this.bundle = bundle;
    this.proxy = proxy;
  }
  
  synchronized void shutdown()
  {
    for (Iterator it = aliases.iterator(); it.hasNext();)
    {
      String alias = (String)it.next();
      proxy.unregister(alias, false);
    }
    aliases.clear();
    for (Iterator it = filters.iterator(); it.hasNext();)
    {
      Filter filter = (Filter)it.next();
      proxy.unregisterFilter(filter, false);
    }
    filters.clear();
    shutdown = true;
  }
  
  private void checkShutdown()
  {
    if (shutdown) {
      throw new IllegalStateException("Service instance is already shutdown");
    }
  }
  
  public synchronized void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext context)
    throws ServletException, NamespaceException
  {
    checkShutdown();
    if (context == null) {
      context = createDefaultHttpContext();
    }
    proxy.registerServlet(alias, servlet, initparams, context);
    aliases.add(alias);
  }
  
  public synchronized void registerResources(String alias, String name, HttpContext context)
    throws NamespaceException
  {
    checkShutdown();
    if (context == null) {
      context = createDefaultHttpContext();
    }
    proxy.registerResources(alias, name, context);
    aliases.add(alias);
  }
  
  public synchronized void unregister(String alias)
  {
    checkShutdown();
    if (aliases.remove(alias)) {
      proxy.unregister(alias, true);
    } else {
      throw new IllegalArgumentException("Alias not found: " + alias);
    }
  }
  
  public synchronized HttpContext createDefaultHttpContext()
  {
    checkShutdown();
    return new DefaultHttpContext(bundle);
  }
  
  public void registerFilter(String alias, Filter filter, Dictionary initparams, HttpContext context)
    throws ServletException
  {
    checkShutdown();
    if (context == null) {
      context = createDefaultHttpContext();
    }
    proxy.registerFilter(alias, filter, initparams, context);
    filters.add(filter);
  }
  
  public void unregisterFilter(Filter filter)
  {
    checkShutdown();
    if (filters.remove(filter)) {
      proxy.unregisterFilter(filter, true);
    } else {
      throw new IllegalArgumentException("Filter not found.");
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.internal.HttpServiceImpl
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestWrapper;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpSession;

public class HttpServletRequestAdaptor
  extends HttpServletRequestWrapper
{
  private String alias;
  private Servlet servlet;
  private boolean isRequestDispatcherInclude;
  static final String INCLUDE_REQUEST_URI_ATTRIBUTE = "javax.servlet.include.request_uri";
  static final String INCLUDE_CONTEXT_PATH_ATTRIBUTE = "javax.servlet.include.context_path";
  static final String INCLUDE_SERVLET_PATH_ATTRIBUTE = "javax.servlet.include.servlet_path";
  static final String INCLUDE_PATH_INFO_ATTRIBUTE = "javax.servlet.include.path_info";
  
  public HttpServletRequestAdaptor(HttpServletRequest req, String alias, Servlet servlet)
  {
    super(req);
    this.alias = alias;
    this.servlet = servlet;
    isRequestDispatcherInclude = (req.getAttribute("javax.servlet.include.request_uri") != null);
  }
  
  public String getAuthType()
  {
    String authType = (String)super.getAttribute("org.osgi.service.http.authentication.type");
    if (authType != null) {
      return authType;
    }
    return super.getAuthType();
  }
  
  public String getRemoteUser()
  {
    String remoteUser = (String)super.getAttribute("org.osgi.service.http.authentication.remote.user");
    if (remoteUser != null) {
      return remoteUser;
    }
    return super.getRemoteUser();
  }
  
  public String getPathInfo()
  {
    if (isRequestDispatcherInclude) {
      return super.getPathInfo();
    }
    if (alias.equals("/")) {
      return super.getPathInfo();
    }
    String pathInfo = super.getPathInfo().substring(alias.length());
    if (pathInfo.length() == 0) {
      return null;
    }
    return pathInfo;
  }
  
  public String getServletPath()
  {
    if (isRequestDispatcherInclude) {
      return super.getServletPath();
    }
    if (alias.equals("/")) {
      return "";
    }
    return alias;
  }
  
  public String getContextPath()
  {
    if (isRequestDispatcherInclude) {
      return super.getContextPath();
    }
    return super.getContextPath() + super.getServletPath();
  }
  
  public Object getAttribute(String attributeName)
  {
    if (isRequestDispatcherInclude)
    {
      if (attributeName.equals("javax.servlet.include.context_path"))
      {
        String contextPath = (String)super.getAttribute("javax.servlet.include.context_path");
        if ((contextPath == null) || (contextPath.equals("/"))) {
          contextPath = "";
        }
        String servletPath = (String)super.getAttribute("javax.servlet.include.servlet_path");
        if ((servletPath == null) || (servletPath.equals("/"))) {
          servletPath = "";
        }
        return contextPath + servletPath;
      }
      if (attributeName.equals("javax.servlet.include.servlet_path"))
      {
        if (alias.equals("/")) {
          return "";
        }
        return alias;
      }
      if (attributeName.equals("javax.servlet.include.path_info"))
      {
        String pathInfo = (String)super.getAttribute("javax.servlet.include.path_info");
        if (alias.equals("/")) {
          return pathInfo;
        }
        pathInfo = pathInfo.substring(alias.length());
        if (pathInfo.length() == 0) {
          return null;
        }
        return pathInfo;
      }
    }
    return super.getAttribute(attributeName);
  }
  
  public RequestDispatcher getRequestDispatcher(String arg0)
  {
    return new RequestDispatcherAdaptor(super.getRequestDispatcher(super.getServletPath() + arg0));
  }
  
  public static String getDispatchPathInfo(HttpServletRequest req)
  {
    if (req.getAttribute("javax.servlet.include.request_uri") != null) {
      return (String)req.getAttribute("javax.servlet.include.path_info");
    }
    return req.getPathInfo();
  }
  
  public static String getDispatchServletPath(HttpServletRequest req)
  {
    if (req.getAttribute("javax.servlet.include.request_uri") != null)
    {
      String servletPath = (String)req.getAttribute("javax.servlet.include.servlet_path");
      return servletPath == null ? "" : servletPath;
    }
    return req.getServletPath();
  }
  
  public HttpSession getSession()
  {
    HttpSession session = super.getSession();
    if (session != null) {
      return new HttpSessionAdaptor(session, servlet);
    }
    return null;
  }
  
  public HttpSession getSession(boolean create)
  {
    HttpSession session = super.getSession(create);
    if (session != null) {
      return new HttpSessionAdaptor(session, servlet);
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.internal.HttpServletRequestAdaptor
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import java.util.Enumeration;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;

public class HttpSessionAdaptor
  implements HttpSession
{
  private HttpSession session;
  private Servlet servlet;
  
  public HttpSessionAdaptor(HttpSession session, Servlet servlet)
  {
    this.session = session;
    this.servlet = servlet;
  }
  
  public ServletContext getServletContext()
  {
    return servlet.getServletConfig().getServletContext();
  }
  
  public Object getAttribute(String arg0)
  {
    return session.getAttribute(arg0);
  }
  
  public Enumeration getAttributeNames()
  {
    return session.getAttributeNames();
  }
  
  public long getCreationTime()
  {
    return session.getCreationTime();
  }
  
  public String getId()
  {
    return session.getId();
  }
  
  public long getLastAccessedTime()
  {
    return session.getLastAccessedTime();
  }
  
  public int getMaxInactiveInterval()
  {
    return session.getMaxInactiveInterval();
  }
  
  /**
   * @deprecated
   */
  public HttpSessionContext getSessionContext()
  {
    return session.getSessionContext();
  }
  
  /**
   * @deprecated
   */
  public Object getValue(String arg0)
  {
    return session.getValue(arg0);
  }
  
  /**
   * @deprecated
   */
  public String[] getValueNames()
  {
    return session.getValueNames();
  }
  
  public void invalidate()
  {
    session.invalidate();
  }
  
  public boolean isNew()
  {
    return session.isNew();
  }
  
  /**
   * @deprecated
   */
  public void putValue(String arg0, Object arg1)
  {
    session.putValue(arg0, arg1);
  }
  
  public void removeAttribute(String arg0)
  {
    session.removeAttribute(arg0);
  }
  
  /**
   * @deprecated
   */
  public void removeValue(String arg0)
  {
    session.removeValue(arg0);
  }
  
  public void setAttribute(String arg0, Object arg1)
  {
    session.setAttribute(arg0, arg1);
  }
  
  public void setMaxInactiveInterval(int arg0)
  {
    session.setMaxInactiveInterval(arg0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.internal.HttpSessionAdaptor
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import java.io.File;
import java.util.Hashtable;
import org.osgi.service.http.HttpContext;

public class ProxyContext$ContextAttributes
  extends Hashtable
{
  private static final long serialVersionUID = 1916670423277243587L;
  private int referenceCount;
  final ProxyContext this$0;
  
  public ProxyContext$ContextAttributes(ProxyContext arg1, HttpContext httpContext)
  {
    this$0 = ???;
    if (proxyContextTempDir != null)
    {
      File contextTempDir = new File(proxyContextTempDir, "hc_" + httpContext.hashCode());
      contextTempDir.mkdirs();
      put("javax.servlet.context.tempdir", contextTempDir);
    }
  }
  
  public void destroy()
  {
    File contextTempDir = (File)get("javax.servlet.context.tempdir");
    if (contextTempDir != null) {
      ProxyContext.deleteDirectory(contextTempDir);
    }
  }
  
  public void addReference()
  {
    referenceCount += 1;
  }
  
  public void removeReference()
  {
    referenceCount -= 1;
  }
  
  public int referenceCount()
  {
    return referenceCount;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.internal.ProxyContext.ContextAttributes
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import java.io.File;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.osgi.service.http.HttpContext;

public class ProxyContext
{
  private static final String JAVAX_SERVLET_CONTEXT_TEMPDIR = "javax.servlet.context.tempdir";
  private String servletPath;
  private HashMap attributesMap = new HashMap();
  File proxyContextTempDir;
  
  public ProxyContext(ServletContext servletContext)
  {
    File tempDir = (File)servletContext.getAttribute("javax.servlet.context.tempdir");
    if (tempDir != null)
    {
      proxyContextTempDir = new File(tempDir, "proxytemp");
      deleteDirectory(proxyContextTempDir);
      proxyContextTempDir.mkdirs();
    }
  }
  
  public void destroy()
  {
    if (proxyContextTempDir != null) {
      deleteDirectory(proxyContextTempDir);
    }
  }
  
  synchronized void initializeServletPath(HttpServletRequest req)
  {
    if (servletPath == null) {
      servletPath = HttpServletRequestAdaptor.getDispatchServletPath(req);
    }
  }
  
  synchronized String getServletPath()
  {
    return servletPath == null ? "" : servletPath;
  }
  
  synchronized void createContextAttributes(HttpContext httpContext)
  {
    ContextAttributes attributes = (ContextAttributes)attributesMap.get(httpContext);
    if (attributes == null)
    {
      attributes = new ContextAttributes(httpContext);
      attributesMap.put(httpContext, attributes);
    }
    attributes.addReference();
  }
  
  synchronized void destroyContextAttributes(HttpContext httpContext)
  {
    ContextAttributes attributes = (ContextAttributes)attributesMap.get(httpContext);
    attributes.removeReference();
    if (attributes.referenceCount() == 0)
    {
      attributesMap.remove(httpContext);
      attributes.destroy();
    }
  }
  
  synchronized Dictionary getContextAttributes(HttpContext httpContext)
  {
    return (Dictionary)attributesMap.get(httpContext);
  }
  
  protected static boolean deleteDirectory(File directory)
  {
    if ((directory.exists()) && (directory.isDirectory()))
    {
      File[] files = directory.listFiles();
      for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
          deleteDirectory(files[i]);
        } else {
          files[i].delete();
        }
      }
    }
    return directory.delete();
  }
  
  public class ContextAttributes
    extends Hashtable
  {
    private static final long serialVersionUID = 1916670423277243587L;
    private int referenceCount;
    
    public ContextAttributes(HttpContext httpContext)
    {
      if (proxyContextTempDir != null)
      {
        File contextTempDir = new File(proxyContextTempDir, "hc_" + httpContext.hashCode());
        contextTempDir.mkdirs();
        put("javax.servlet.context.tempdir", contextTempDir);
      }
    }
    
    public void destroy()
    {
      File contextTempDir = (File)get("javax.servlet.context.tempdir");
      if (contextTempDir != null) {
        ProxyContext.deleteDirectory(contextTempDir);
      }
    }
    
    public void addReference()
    {
      referenceCount += 1;
    }
    
    public void removeReference()
    {
      referenceCount -= 1;
    }
    
    public int referenceCount()
    {
      return referenceCount;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.servlet.internal.ProxyContext
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.servlet.internal;

import java.io.IOException;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
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 javax.servlet.FilterChain;
import javax.servlet.GenericServlet;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.NamespaceException;

public class ProxyServlet
  extends HttpServlet
{
  private static final long serialVersionUID = 4117456123807468871L;
  private Map servletRegistrations = new HashMap();
  private Set registeredServlets = new HashSet();
  private Map filterRegistrations = new HashMap();
  private ProxyContext proxyContext;
  
  public void init(ServletConfig config)
    throws ServletException
  {
    super.init(config);
    proxyContext = new ProxyContext(config.getServletContext());
    Activator.addProxyServlet(this);
  }
  
  public void destroy()
  {
    Activator.removeProxyServlet(this);
    proxyContext.destroy();
    proxyContext = null;
    super.destroy();
  }
  
  protected void service(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
  {
    proxyContext.initializeServletPath(req);
    String alias = HttpServletRequestAdaptor.getDispatchPathInfo(req);
    if (alias == null) {
      alias = "/";
    }
    if (processAlias(req, resp, alias, null)) {
      return;
    }
    String extensionAlias = findExtensionAlias(alias);
    alias = alias.substring(0, alias.lastIndexOf('/'));
    while (alias.length() != 0)
    {
      if (processAlias(req, resp, alias, extensionAlias)) {
        return;
      }
      alias = alias.substring(0, alias.lastIndexOf('/'));
    }
    if (extensionAlias != null) {
      extensionAlias = extensionAlias.substring(1);
    }
    if (processAlias(req, resp, "/", extensionAlias)) {
      return;
    }
    resp.sendError(404, "ProxyServlet: " + req.getRequestURI());
  }
  
  private String findExtensionAlias(String alias)
  {
    String lastSegment = alias.substring(alias.lastIndexOf('/') + 1);
    int dot = lastSegment.lastIndexOf('.');
    if (dot == -1) {
      return null;
    }
    String extension = lastSegment.substring(dot + 1);
    if (extension.length() == 0) {
      return null;
    }
    return "/*." + extension;
  }
  
  private boolean processAlias(HttpServletRequest req, HttpServletResponse resp, String alias, String extensionAlias)
    throws ServletException, IOException
  {
    ServletRegistration registration = null;
    List matchingFilterRegistrations = Collections.EMPTY_LIST;
    String dispatchPathInfo = HttpServletRequestAdaptor.getDispatchPathInfo(req);
    if (dispatchPathInfo == null) {
      dispatchPathInfo = "/";
    }
    synchronized (this)
    {
      if (extensionAlias == null)
      {
        registration = (ServletRegistration)servletRegistrations.get(alias);
      }
      else
      {
        registration = (ServletRegistration)servletRegistrations.get(alias + extensionAlias);
        if (registration != null)
        {
          if (!(registration.getServlet() instanceof ResourceServlet)) {
            alias = HttpServletRequestAdaptor.getDispatchPathInfo(req);
          }
        }
        else {
          registration = (ServletRegistration)servletRegistrations.get(alias);
        }
      }
      if (registration != null)
      {
        registration.addReference();
        if (!filterRegistrations.isEmpty())
        {
          matchingFilterRegistrations = new ArrayList();
          for (Iterator it = filterRegistrations.values().iterator(); it.hasNext();)
          {
            filterRegistration = (FilterRegistration)it.next();
            if (filterRegistration.matches(dispatchPathInfo))
            {
              matchingFilterRegistrations.add(filterRegistration);
              filterRegistration.addReference();
            }
          }
        }
      }
    }
    if (registration != null)
    {
      Iterator it;
      FilterRegistration filterRegistration;
      try
      {
        HttpServletRequest wrappedRequest = new HttpServletRequestAdaptor(req, alias, registration.getServlet());
        if (matchingFilterRegistrations.isEmpty())
        {
          registration.service(wrappedRequest, resp);
        }
        else
        {
          Collections.sort(matchingFilterRegistrations);
          FilterChain chain = new FilterChainImpl(matchingFilterRegistrations, registration);
          chain.doFilter(wrappedRequest, resp);
        }
      }
      finally
      {
        registration.removeReference();
        for (Iterator it = matchingFilterRegistrations.iterator(); it.hasNext();)
        {
          FilterRegistration filterRegistration = (FilterRegistration)it.next();
          filterRegistration.removeReference();
        }
      }
      return true;
    }
    return false;
  }
  
  /* Error */
  synchronized void unregister(String alias, boolean destroy)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 347	org/eclipse/equinox/http/servlet/internal/ProxyServlet:servletRegistrations	Ljava/util/Map;
    //   4: aload_1
    //   5: invokeinterface 421 2 0
    //   10: checkcast 209	org/eclipse/equinox/http/servlet/internal/ServletRegistration
    //   13: astore_3
    //   14: aload_3
    //   15: ifnull +55 -> 70
    //   18: aload_0
    //   19: getfield 348	org/eclipse/equinox/http/servlet/internal/ProxyServlet:registeredServlets	Ljava/util/Set;
    //   22: aload_3
    //   23: 
1 2 3

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