webapp.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,683 行 · 第 1/5 页

JAVA
2,683
字号
	Invocation oldInvocation = new Invocation();	oldInvocation.copyFrom(invocation);	oldInvocation.setWebApp(_oldWebApp);	_oldWebApp.buildInvocation(oldInvocation);		invocation = new VersionInvocation(invocation, this,					   oldInvocation,					   oldInvocation.getWebApp(),					   _oldWebAppExpireTime);      }      return invocation;    } catch (Throwable e) {      FilterChain chain = new ExceptionFilterChain(e);      chain = new WebAppFilterChain(chain, this);      invocation.setDependency(AlwaysModified.create());      invocation.setFilterChain(chain);      return invocation;    } finally {      thread.setContextClassLoader(oldLoader);    }  }  /**   * Clears all caches, including the invocation cache, the filter cache, and the proxy cache.   */  public void clearCache()  {    DispatchServer server = getDispatchServer();    if (server != null)      server.clearCache();        WebAppContainer parent = _parent;    if (parent != null)      parent.clearCache();        // server/1kg1    synchronized (_filterChainCache) {      _filterChainCache.clear();      _dispatcherCache = null;    }  }  /**   * Fills the invocation for an include request.   */  public void buildIncludeInvocation(Invocation invocation)    throws ServletException  {    buildDispatchInvocation(invocation, _includeFilterMapper);  }  /**   * Fills the invocation for a forward request.   */  public void buildForwardInvocation(Invocation invocation)    throws ServletException  {    buildDispatchInvocation(invocation, _forwardFilterMapper);  }  /**   * Fills the invocation for an error request.   */  public void buildErrorInvocation(Invocation invocation)    throws ServletException  {    buildDispatchInvocation(invocation, _errorFilterMapper);  }  /**   * Fills the invocation for a login request.   */  public void buildLoginInvocation(Invocation invocation)    throws ServletException  {    buildDispatchInvocation(invocation, _loginFilterMapper);  }  /**   * Fills the invocation for a rewrite-dispatch/dispatch request.   */  public void buildDispatchInvocation(Invocation invocation)    throws ServletException  {    buildDispatchInvocation(invocation, _filterMapper);  }  /**   * Fills the invocation for subrequests.   */  public void buildDispatchInvocation(Invocation invocation,                                      FilterMapper filterMapper)    throws ServletException  {    invocation.setWebApp(this);    Thread thread = Thread.currentThread();    ClassLoader oldLoader = thread.getContextClassLoader();    thread.setContextClassLoader(getClassLoader());    try {      FilterChain chain;      /*        if (! _isActive) {        int code = HttpServletResponse.SC_SERVICE_UNAVAILABLE;        chain = new ErrorFilterChain(code);        invocation.setFilterChain(chain);        invocation.setDependency(AlwaysModified.create());        return;        }      */      if (_configException != null) {        chain = new ExceptionFilterChain(_configException);        invocation.setDependency(AlwaysModified.create());      }      else if (! _lifecycle.waitForActive(_activeWaitTime)) {        Exception exn = new UnavailableException(L.l("'{0}' is not currently available.",                                                     getContextPath()));        chain = new ExceptionFilterChain(exn);        invocation.setDependency(AlwaysModified.create());      }      else {        chain = _servletMapper.mapServlet(invocation);	if (_includeRewriteDispatch != null	    && filterMapper == _includeFilterMapper) {	  chain = _includeRewriteDispatch.map(invocation.getContextURI(),					      invocation.getQueryString(),					      chain);	}	else if (_forwardRewriteDispatch != null		 && filterMapper == _forwardFilterMapper) {	  chain = _forwardRewriteDispatch.map(invocation.getContextURI(),					      invocation.getQueryString(),					      chain);	}        filterMapper.buildDispatchChain(invocation, chain);        chain = invocation.getFilterChain();        chain = new DispatchFilterChain(chain, this);        if (_cache != null && filterMapper == _includeFilterMapper) {          chain = _cache.createFilterChain(chain, this);        }      }      invocation.setFilterChain(chain);    } finally {      thread.setContextClassLoader(oldLoader);    }  }  /**   * Returns a dispatcher for the named servlet.   */  public RequestDispatcher getRequestDispatcher(String url)  {    if (url == null)      throw new IllegalArgumentException(L.l("request dispatcher url can't be null."));    else if (! url.startsWith("/"))      throw new IllegalArgumentException(L.l("request dispatcher url '{0}' must be absolute", url));    RequestDispatcherImpl disp = getDispatcherCache().get(url);    if (disp != null && ! disp.isModified())      return disp;    Invocation includeInvocation = new SubInvocation();    Invocation forwardInvocation = new SubInvocation();    Invocation errorInvocation = new SubInvocation();    Invocation dispatchInvocation = new SubInvocation();    InvocationDecoder decoder = new InvocationDecoder();    String rawURI = escapeURL(_contextPath + url);    try {      decoder.splitQuery(includeInvocation, rawURI);      decoder.splitQuery(forwardInvocation, rawURI);      decoder.splitQuery(errorInvocation, rawURI);      decoder.splitQuery(dispatchInvocation, rawURI);      if (_parent != null) {        _parent.buildIncludeInvocation(includeInvocation);        _parent.buildForwardInvocation(forwardInvocation);        _parent.buildErrorInvocation(errorInvocation);        _parent.buildDispatchInvocation(dispatchInvocation);      }      else if (! _lifecycle.waitForActive(_activeWaitTime)) {	throw new IllegalStateException(L.l("'{0}' is restarting and is not yet ready to receive requests",					    _contextPath));      }      else {        FilterChain chain = _servletMapper.mapServlet(includeInvocation);        _includeFilterMapper.buildDispatchChain(includeInvocation, chain);        includeInvocation.setWebApp(this);        chain = _servletMapper.mapServlet(forwardInvocation);        _forwardFilterMapper.buildDispatchChain(forwardInvocation, chain);        forwardInvocation.setWebApp(this);        chain = _servletMapper.mapServlet(errorInvocation);        _errorFilterMapper.buildDispatchChain(errorInvocation, chain);        errorInvocation.setWebApp(this);        chain = _servletMapper.mapServlet(dispatchInvocation);        _filterMapper.buildDispatchChain(dispatchInvocation, chain);        dispatchInvocation.setWebApp(this);      }      disp = new RequestDispatcherImpl(includeInvocation,                                       forwardInvocation,                                       errorInvocation,				       dispatchInvocation,                                       this);      getDispatcherCache().put(url, disp);      return disp;    } catch (RuntimeException e) {      throw e;    } catch (Exception e) {      log.log(Level.FINE, e.toString(), e);      return null;    }  }  /**   * Access logging for high-level errors   */  public void accessLog(HttpServletRequest req, HttpServletResponse res)    throws IOException  {    AbstractAccessLog log = getAccessLog();    if (log != null)      log.log(req, res, this);  }  private LruCache<String,RequestDispatcherImpl> getDispatcherCache()  {    LruCache<String,RequestDispatcherImpl> cache = _dispatcherCache;    if (cache != null)      return cache;    synchronized (this) {      cache = new LruCache<String,RequestDispatcherImpl>(1024);      _dispatcherCache = cache;      return cache;    }  }  private String escapeURL(String url)  {    return url;    /* jsp/15dx       CharBuffer cb = CharBuffer.allocate();       int length = url.length();       for (int i = 0; i < length; i++) {       char ch = url.charAt(i);       if (ch < 0x80)       cb.append(ch);       else if (ch < 0x800) {       cb.append((char) (0xc0 | (ch >> 6)));       cb.append((char) (0x80 | (ch & 0x3f)));       }       else {       cb.append((char) (0xe0 | (ch >> 12)));       cb.append((char) (0x80 | ((ch >> 6) & 0x3f)));       cb.append((char) (0x80 | (ch & 0x3f)));       }       }       return cb.close();    */  }  /**   * Returns a dispatcher for the named servlet.   */  public RequestDispatcher getLoginDispatcher(String url)  {    if (url == null)      throw new IllegalArgumentException(L.l("request dispatcher url can't be null."));    else if (! url.startsWith("/"))      throw new IllegalArgumentException(L.l("request dispatcher url '{0}' must be absolute", url));    Invocation loginInvocation = new Invocation();    Invocation errorInvocation = new Invocation();    InvocationDecoder decoder = new InvocationDecoder();    String rawURI = _contextPath + url;    try {      decoder.splitQuery(loginInvocation, rawURI);      decoder.splitQuery(errorInvocation, rawURI);      if (! _lifecycle.waitForActive(_activeWaitTime)) {	throw new IllegalStateException(L.l("'{0}' is restarting and it not yet ready to receive requests",					    _contextPath));      }      else if (_parent != null) {        _parent.buildInvocation(loginInvocation);        _parent.buildErrorInvocation(errorInvocation);      }      else {        FilterChain chain = _servletMapper.mapServlet(loginInvocation);        _filterMapper.buildDispatchChain(loginInvocation, chain);        chain = _servletMapper.mapServlet(errorInvocation);        _errorFilterMapper.buildDispatchChain(errorInvocation, chain);      }      RequestDispatcherImpl disp;      disp = new RequestDispatcherImpl(loginInvocation,                                       loginInvocation,                                       errorInvocation,				       loginInvocation,                                       this);      disp.setLogin(true);      return disp;    } catch (Exception e) {      log.log(Level.FINE, e.toString(), e);      return null;    }  }  /**   * Returns a dispatcher for the named servlet.   */  public RequestDispatcher getNamedDispatcher(String servletName)  {    try {      FilterChain chain = _servletManager.createServletChain(servletName);      FilterChain includeChain        = _includeFilterMapper.buildFilterChain(chain, servletName);      FilterChain forwardChain        = _forwardFilterMapper.buildFilterChain(chain, servletName);      return new NamedDispatcherImpl(includeChain, forwardChain, null, this);    } catch (Exception e) {      log.log(Level.FINEST, e.toString(), e);      return null;    }  }  /**   * Maps from a URI to a real path.   */  @Override  public String getRealPath(String uri)  {    if (uri == null)      throw new NullPointerException();        String realPath = _realPathCache.get(uri);    if (realPath != null)      return realPath;    String fullURI = getContextPath() + "/" + uri;    try {      fullURI = InvocationDecoder.normalizeUri(fullURI);    } catch (Exception e) {      log.log(Level.WARNING, e.toString(), e);    }    WebApp app = (WebApp) getContext(fullURI);    if (app == null)      return null;    String cp = app.getContextPath();    String tail = fullURI.substring(cp.length());    realPath = app.getRealPathImpl(tail);    if (log.isLoggable(Level.FINEST))      log.finest("real-path " + uri + " -> " + realPath);    _realPathCache.put(uri, realPath);    return realPath;  }  /**   * Maps from a URI to a real path.   */  public String getRealPathImpl(String uri)  {    return createRewriteRealPath().mapToRealPath(uri);  }  /**   * Returns the mime type for a uri   */  public String getMimeType(String uri)  {    if (uri == null)      return null;    String fullURI = getContextPath() + "/" + uri;    try {      fullURI = InvocationDecoder.normalizeUri(fullURI);    } catch (Exception e) {      log.log(Level.WARNING, e.toString(), e);    }    WebApp app = (WebApp) getContext(fullURI);    if (app == null)      return null;    int p = uri.lastIndexOf('.');    if (p < 0)      return null;    else      return app.getMimeTypeImpl(uri.substring(p));  }  /**   * Maps from a URI to a real path.   */  public String getMimeTypeImpl(String ext)  {    return _mimeMapping.get(ext);  }  /**   * Error logging   *   * @param message message to log   * @param e stack trace of the error   */  public void log(String message, Throwable e)  {    if (e != null)      log.log(Level.WARNING, this + " " + message, e);    else      log.info(this + " " + message);  }  /**   * Gets the login manager.   */  public AbstractLogin getLogin()  {    if (_loginFactory != null) {      synchronized (_loginFactory) {	_login = _loginFactory.getLoginObject();      }      return _login;    }    else      return _loginManager;  }  /**   * Gets the authenticator   */  public ServletAuthenticator getAuthenticator()  {    AbstractLogin login = getLogin();    if (login != null)      return login.getAuthenticator();    else      return null;  }  /**   * Gets the session manager.   */  public SessionManager getSessionManager()  {    if (_sessionManager == null) {      if (_lifecycle.isStopped())        throw new IllegalStateException(L.l("Resin is shutting down."));      if (_isInheritSession && _parent != null)        _sessionManager = _parent.getSessionManager();      if (_sessionManager == null) {        Thread thread = Thread.currentThread();        ClassLoader oldLoader = thread.getContextClassLoader();        try {          thread.setContextClassLoader(getClassLoader());          _sessionManager = new SessionManager(this);        } catch (Throwable e) {          log.log(Level.WARNING, e.toString(), e);        } finally {          thread.setContextClassLoader(oldLoader);        }      }    }    return _sessionManager;  }  /**   * Gets the error page manager.   */  public ErrorPageManager getErrorPageManager()  {    return _errorPageManager;  }  /**   * Called when a request starts the webApp.   */  final boolean enterWebApp()  {    synchronized (_countLock) {      _requestCount++;      _lastRequestTime = Alarm.getCurrentT

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?