org.apache.catalina.Container类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(14.7k)|赞(0)|评价(0)|浏览(217)

本文整理了Java中org.apache.catalina.Container类的一些代码示例,展示了Container类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Container类的具体详情如下:
包路径:org.apache.catalina.Container
类名称:Container

Container介绍

[英]A Container is an object that can execute requests received from a client, and return responses based on those requests. A Container may optionally support a pipeline of Valves that process the request in an order configured at runtime, by implementing the Pipeline interface as well.

Containers will exist at several conceptual levels within Catalina. The following examples represent common cases:

  • Engine - Representation of the entire Catalina servlet engine, most likely containing one or more subcontainers that are either Host or Context implementations, or other custom groups.
  • Host - Representation of a virtual host containing a number of Contexts.
  • Context - Representation of a single ServletContext, which will typically contain one or more Wrappers for the supported servlets.
  • Wrapper - Representation of an individual servlet definition (which may support multiple servlet instances if the servlet itself implements SingleThreadModel).
    A given deployment of Catalina need not include Containers at all of the levels described above. For example, an administration application embedded within a network device (such as a router) might only contain a single Context and a few Wrappers, or even a single Wrapper if the application is relatively small. Therefore, Container implementations need to be designed so that they will operate correctly in the absence of parent Containers in a given deployment.

A Container may also be associated with a number of support components that provide functionality which might be shared (by attaching it to a parent Container) or individually customized. The following support components are currently recognized:

  • Loader - Class loader to use for integrating new Java classes for this Container into the JVM in which Catalina is running.
  • Logger - Implementation of the log() method signatures of the ServletContext interface.
  • Manager - Manager for the pool of Sessions associated with this Container.
  • Realm - Read-only interface to a security domain, for authenticating user identities and their corresponding roles.
  • Resources - JNDI directory context enabling access to static resources, enabling custom linkages to existing server components when Catalina is embedded in a larger server.
    [中]容器是一个对象,它可以执行从客户端接收的请求,并根据这些请求返回响应。容器还可以通过实现管道接口,选择性地支持以运行时配置的顺序处理请求的阀门管道。
    容器将在Catalina的几个概念层面上存在。以下示例代表常见情况:
    *引擎—整个Catalina servlet引擎的表示,很可能包含一个或多个子容器,这些子容器是主机或上下文实现,或者其他自定义组。
    *主机-表示包含多个上下文的虚拟主机。
    *Context—单个ServletContext的表示,它通常包含一个或多个受支持的servlet的包装器。
    *包装器—单个servlet定义的表示(如果servlet本身实现SingleThreadModel,则可能支持多个servlet实例)。
    Catalina的给定部署不需要包含上述所有级别的容器。例如,嵌入在网络设备(如路由器)中的管理应用程序可能只包含一个上下文和几个包装器,如果应用程序相对较小,甚至可能只包含一个包装器。因此,容器实现需要设计成在给定部署中没有父容器的情况下能够正确运行。
    容器还可以与许多支持组件相关联,这些组件提供的功能可以共享(通过将容器附加到父容器)或单独定制。目前已识别以下支持组件:
    *Loader—用于将此容器的新Java类集成到运行Catalina的JVM中的类加载器。
    *Logger-实现ServletContext接口的log()方法签名。
    *Manager—与此容器关联的会话池的管理器。
    *领域-安全域的只读接口,用于验证用户身份及其相应角色。
    *Resources-JNDI目录上下文支持对静态资源的访问,当Catalina嵌入到更大的服务器中时,支持到现有服务器组件的自定义链接。

代码示例

代码示例来源:origin: magro/memcached-session-manager

protected MemcachedNodesManager createMemcachedNodesManager(final String memcachedNodes, final String failoverNodes) {
  final Context context = _manager.getContext();
  final String webappVersion = Reflections.invoke(context, "getWebappVersion", null);
  final StorageKeyFormat storageKeyFormat = StorageKeyFormat.of(_storageKeyPrefix, context.getParent().getName(), context.getName(), webappVersion);
  return MemcachedNodesManager.createFor( memcachedNodes, failoverNodes, storageKeyFormat, _storageClientCallback);
}

代码示例来源:origin: psi-probe/psi-probe

@Override
public String getConfigBase() {
 File configBase = new File(System.getProperty("catalina.base"), "conf");
 Container baseHost = null;
 Container thisContainer = host;
 while (thisContainer != null) {
  if (thisContainer instanceof Host) {
   baseHost = thisContainer;
  }
  thisContainer = thisContainer.getParent();
 }
 if (baseHost != null) {
  configBase = new File(configBase, baseHost.getName());
 }
 return configBase.getAbsolutePath();
}

代码示例来源:origin: magro/memcached-session-manager

public void shutdown() {
  _log.info( "Stopping services." );
  _manager.getContext().getParent().getPipeline().removeValve(_trackingHostValve);
  _manager.getContext().getPipeline().removeValve(_trackingContextValve);
  _backupSessionService.shutdown();
  if ( _lockingStrategy != null ) {
    _lockingStrategy.shutdown();
  }
  if ( _storage != null ) {
    _storage.shutdown();
    _storage = null;
  }
  _transcoderFactory = null;
  _invalidSessionsCache.clear();
}

代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9

/**
 * Unregister context.
 */
private void unregisterContext(Context context) {
  // Don't un-map a context that is paused
  if (context.getPaused()){
    return;
  }
  String contextPath = context.getPath();
  if ("/".equals(contextPath)) {
    contextPath = "";
  }
  String hostName = context.getParent().getName();
  if(log.isDebugEnabled())
    log.debug(sm.getString("mapperListener.unregisterContext",
        contextPath, connector));
  mapper.removeContextVersion(hostName, contextPath,
      context.getWebappVersion());
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

ErrorPage errorPage) {
if (container.getLogger().isDebugEnabled()) {
  container.getLogger().debug("Processing " + errorPage);
    request.getContext().getServletContext();
  RequestDispatcher rd =
    servletContext.getRequestDispatcher(errorPage.getLocation());
    container.getLogger().error(
      sm.getString("standardHostValue.customStatusFailed", errorPage.getLocation()));
    return false;
    rd.include(request.getRequest(), response.getResponse());
  } else {
    response.setContentLength(-1);
    rd.forward(request.getRequest(), response.getResponse());
  ExceptionUtils.handleThrowable(t);
  container.getLogger().error("Exception Processing " + errorPage, t);
  return false;

代码示例来源:origin: com.ovea.tajin.server/tajin-server-tomcat7

/**
 * Perform the internal processing required to passivate
 * this session.
 */
public void passivate() {
  // Notify interested session event listeners
  fireSessionEvent(Session.SESSION_PASSIVATED_EVENT, null);
  // Notify ActivationListeners
  HttpSessionEvent event = null;
  String keys[] = keys();
  for (int i = 0; i < keys.length; i++) {
    Object attribute = attributes.get(keys[i]);
    if (attribute instanceof HttpSessionActivationListener) {
      if (event == null)
        event = new HttpSessionEvent(getSession());
      try {
        ((HttpSessionActivationListener)attribute)
          .sessionWillPassivate(event);
      } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        manager.getContainer().getLogger().error
          (sm.getString("standardSession.attributeEvent"), t);
      }
    }
  }
}

代码示例来源:origin: org.apache.catalina/com.springsource.org.apache.catalina

@Override
public void sessionDestroyed(HttpSessionEvent se) {
  // Close all Comet connections associated with this session
  Request[] reqs = (Request[])
    se.getSession().getAttribute(cometRequestsAttribute);
  if (reqs != null) {
    for (int i = 0; i < reqs.length; i++) {
      Request req = reqs[i];
      try {
        CometEventImpl event = req.getEvent();
        event.setEventType(CometEvent.EventType.END);
        event.setEventSubType(CometEvent.EventSubType.SESSION_END);
        ((CometProcessor)
            req.getWrapper().getServlet()).event(event);
        event.close();
      } catch (Exception e) {
        req.getWrapper().getParent().getLogger().warn(sm.getString(
            "cometConnectionManagerValve.listenerEvent"), e);
      }
    }
  }
}

代码示例来源:origin: codefollower/Tomcat-Research

/**
 * Unregister wrapper.
 */
private void unregisterWrapper(Wrapper wrapper) {
  String contextPath = ((Context) wrapper.getParent()).getPath();
  String wrapperName = wrapper.getName();
  if ("/".equals(contextPath)) {
    contextPath = "";
  }
  String version = ((Context) wrapper.getParent()).getWebappVersion();
  String hostName = wrapper.getParent().getParent().getName();
  String[] mappings = wrapper.findMappings();
  for (String mapping : mappings) {
    mapper.removeWrapper(hostName, contextPath, version,  mapping);
  }
  if(log.isDebugEnabled()) {
    log.debug(sm.getString("mapperListener.unregisterWrapper",
        wrapperName, contextPath, service));
  }
}

代码示例来源:origin: org.apache.openejb/openejb-tomcat-catalina

public void clearWsContainer(String virtualHost, String contextRoot, String servletName) {
  if (virtualHost == null) virtualHost = engine.getDefaultHost();
  Container host = engine.findChild(virtualHost);
  if (host == null) {
    throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'.  Do you have a matchiing Host entry in the server.xml?");
  }
  Context context = (Context) host.findChild("/" + contextRoot);
  if (context == null) {
    throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName());
  }
  Wrapper wrapper = (Wrapper) context.findChild(servletName);
  if (wrapper == null) {
    throw new IllegalArgumentException("Could not find servlet " + contextRoot + " in web application context " + context.getName());
  }
  // clear the webservice ref in the servlet context
  String webServicecontainerId = wrapper.findInitParameter(WsServlet.WEBSERVICE_CONTAINER);
  if (webServicecontainerId != null) {
    context.getServletContext().removeAttribute(webServicecontainerId);
    wrapper.removeInitParameter(WsServlet.WEBSERVICE_CONTAINER);
  }
}

代码示例来源:origin: org.mobicents.arquillian.container/mss-tomcat-embedded-6

@Override
public synchronized void removeContext(Context context) {
  if( log.isDebugEnabled() )
    log.debug("Removing context[" + context.getPath() + "]");
  boolean isContextExists = isContextExists(context);
  if(!isContextExists)
    return;
  
  // Remove this Context from the associated Host
  if( log.isDebugEnabled() )
    log.debug(" Removing this Context");
  context.getParent().removeChild(context);
}

代码示例来源:origin: org.apache.geronimo.ext.tomcat/catalina-ha

/**
 * Reset DeltaRequest from session
 * @param session HttpSession from current request or cross context session
 */
protected void resetDeltaRequest(Session session) {
  if(log.isDebugEnabled()) {
    log.debug(sm.getString("ReplicationValve.resetDeltaRequest" , 
      session.getManager().getContainer().getName() ));
  }
  ((DeltaSession)session).resetDeltaRequest();
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

protected void processChildren(Container container) {
    ClassLoader originalClassLoader = null;
    try {
      if (container instanceof Context) {
        Loader loader = ((Context) container).getLoader();
        // Loader will be null for FailedContext instances
        if (loader == null) {
          return;
        }
        // Ensure background processing for Contexts and Wrappers
        // is performed under the web app's class loader
        originalClassLoader = ((Context) container).bind(false, null);
      }
      container.backgroundProcess();
      Container[] children = container.findChildren();
      for (int i = 0; i < children.length; i++) {
        if (children[i].getBackgroundProcessorDelay() <= 0) {
          processChildren(children[i]);
        }
      }
    } catch (Throwable t) {
      ExceptionUtils.handleThrowable(t);
      log.error(sm.getString("containerBase.backgroundProcess.error"), t);
    } finally {
      if (container instanceof Context) {
        ((Context) container).unbind(false, originalClassLoader);
      }
    }
  }
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

/**
 * Close the specified database connection.
 */
protected void close() {
  // Do nothing if the database connection is already closed
  if (conn == null) {
    return;
  }
  // Close our prepared statements (if any)
  try {
    ps.close();
  } catch (Throwable f) {
    ExceptionUtils.handleThrowable(f);
  }
  this.ps = null;
  // Close this database connection, and log any errors
  try {
    conn.close();
  } catch (SQLException e) {
    container.getLogger().error(sm.getString("jdbcAccessLogValve.close"), e); // Just log it here
  } finally {
    this.conn = null;
  }
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

public SingleSignOnSessionKey(Session session) {
  this.sessionId = session.getId();
  Context context = session.getManager().getContext();
  this.contextName = context.getName();
  this.hostName = context.getParent().getName();
}

代码示例来源:origin: com.ovea.tajin.server/tajin-server-tomcat7

@Override
public void lifecycleEvent(LifecycleEvent event) {
  if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType())) {
    // The container is getting stopped, close all current connections 
    Iterator<Request> iterator = cometRequests.iterator();
    while (iterator.hasNext()) {
      Request request = iterator.next();
      // Remove the session tracking attribute as it isn't
      // serializable or required.
      HttpSession session = request.getSession(false);
      if (session != null) {
        session.removeAttribute(cometRequestsAttribute);
      }
      // Close the comet connection
      try {
        CometEventImpl cometEvent = request.getEvent();
        cometEvent.setEventType(CometEvent.EventType.END);
        cometEvent.setEventSubType(
            CometEvent.EventSubType.WEBAPP_RELOAD);
        getNext().event(request, request.getResponse(), cometEvent);
        cometEvent.close();
      } catch (Exception e) {
        container.getLogger().warn(
            sm.getString("cometConnectionManagerValve.event"),
            e);
      }
    }
    cometRequests.clear();
  }
}

代码示例来源:origin: org.apache.geronimo.ext.tomcat/catalina-ha

/**
 * Send the changed Sessionid to all clusternodes.
 * 
 * @see JvmRouteSessionIDBinderListener#messageReceived(
 *            org.apache.catalina.ha.ClusterMessage)
 * @param sessionId
 *            current failed sessionid
 * @param newSessionID
 *            new session id, bind to the new cluster node
 */
protected void sendSessionIDClusterBackup(Request request, String sessionId,
    String newSessionID) {
  CatalinaCluster c = getCluster();
  if (c != null && !(getManager(request) instanceof BackupManager)) {
    SessionIDMessage msg = new SessionIDMessage();
    msg.setOrignalSessionID(sessionId);
    msg.setBackupSessionID(newSessionID);
    Context context = request.getContext();
    msg.setContextName(context.getName());
    msg.setHost(context.getParent().getName());
    c.send(msg);
  }
}

代码示例来源:origin: org.apache.geronimo.ext.tomcat/catalina

/**
 * Set the JNDI name of a DataSource-factory to use for db access
 *
 * @param dataSourceName The JNDI name of the DataSource-factory
 */
public void setDataSourceName(String dataSourceName) {
  if (dataSourceName == null || "".equals(dataSourceName.trim())) {
    manager.getContainer().getLogger().warn(
        sm.getString(getStoreName() + ".missingDataSourceName"));
    return;
  }
  this.dataSourceName = dataSourceName;
}

代码示例来源:origin: org.glassfish.main.web/web-core

this.context = context;
if (context != null) {
  this.servletContext = context.getServletContext();
  Pipeline p = context.getParent().getPipeline();
  if (p != null) {
    hostValve = p.getBasic();
    String reqEncoding = this.servletContext.getRequestCharacterEncoding();
    if (reqEncoding != null) {
      setCharacterEncoding(reqEncoding);
      getResponse().getResponse().setCharacterEncoding(resEncoding);
initSessionTracker();

代码示例来源:origin: org.apache.geronimo.ext.tomcat/catalina

/**
 * Attempt to load a class using the given Container's class loader. If the
 * class cannot be loaded, a debug level log message will be written to the
 * Container's log and null will be returned.
 */
public static Class<?> loadClass(Container container, String className) {
  ClassLoader cl = container.getLoader().getClassLoader();
  Log log = container.getLogger();
  Class<?> clazz = null;
  try {
    clazz = cl.loadClass(className);
  } catch (ClassNotFoundException e) {
    log.debug(sm.getString("introspection.classLoadFailed"), e);
  } catch (NoClassDefFoundError e) {
    log.debug(sm.getString("introspection.classLoadFailed"), e);
  } catch (ClassFormatError e) {
    log.debug(sm.getString("introspection.classLoadFailed"), e);
  } catch (Throwable t) {
    ExceptionUtils.handleThrowable(t);
    log.debug(sm.getString("introspection.classLoadFailed"), t);
  }
  return clazz;
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

@Override
public void setContainer(Container container) {
  super.setContainer(container);
  if (appName == null) {
    appName = makeLegalForJAAS(container.getName());
    log.info(sm.getString("jaasRealm.appName", appName));
  }
}

相关文章

微信公众号

最新文章

更多