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

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

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

Context介绍

[英]A Context is a Container that represents a servlet context, and therefore an individual web application, in the Catalina servlet engine. It is therefore useful in almost every deployment of Catalina (even if a Connector attached to a web server (such as Apache) uses the web server's facilities to identify the appropriate Wrapper to handle this request. It also provides a convenient mechanism to use Interceptors that see every request processed by this particular web application.

The parent Container attached to a Context is generally a Host, but may be some other implementation, or may be omitted if it is not necessary.

The child containers attached to a Context are generally implementations of Wrapper (representing individual servlet definitions).
[中]上下文是一个容器,它表示CatalinaServlet引擎中的servlet上下文,从而表示单个web应用程序。因此,它在Catalina的几乎所有部署中都很有用(即使连接到web服务器(如Apache)的连接器使用web服务器的设施来识别处理此请求的适当包装器)。它还提供了一种方便的机制,可以使用拦截器查看此特定web应用程序处理的每个请求。
附加到上下文的父容器通常是主机,但也可以是其他实现,如果不需要,也可以省略。
附加到上下文的子容器通常是包装器的实现(表示单个servlet定义)。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public ServletContext getServletContext() {
  return this.context.getServletContext();
}

代码示例来源:origin: redisson/redisson

public RTopic getTopic() {
  String separator = keyPrefix == null || keyPrefix.isEmpty() ? "" : ":";
  final String name = keyPrefix + separator + "redisson:tomcat_session_updates:" + ((Context) getContainer()).getName();
  return redisson.getTopic(name);
}

代码示例来源:origin: apache/geode

@Override
public Principal getPrincipal() {
 if (this.principal == null && this.serializedPrincipal != null) {
  SerializablePrincipal sp = null;
  try {
   sp = (SerializablePrincipal) BlobHelper.deserializeBlob(this.serializedPrincipal);
  } catch (Exception e) {
   StringBuilder builder = new StringBuilder();
   builder.append(this).append(
     ": Serialized principal contains a byte[] that cannot be deserialized due to the following exception");
   ((DeltaSessionManager) getManager()).getLogger().warn(builder.toString(), e);
   return null;
  }
  this.principal =
    sp.getPrincipal(((DeltaSessionManager) this.manager).getTheContext().getRealm());
  if (getManager() != null) {
   DeltaSessionManager mgr = (DeltaSessionManager) getManager();
   if (mgr.getLogger().isDebugEnabled()) {
    mgr.getLogger().debug(this + ": Deserialized principal: " + this.principal);
    // mgr.logCurrentStack();
   }
  }
 }
 return this.principal;
}

代码示例来源:origin: stackoverflow.com

ContextInfo makeContextInfo(Context context) {
  // copy to another object -- not the important part
  final ContextInfo info = new ContextInfo(context.getPath());
  info.setThisPart(context.getThisPart());
  info.setNotImportant(context.getNotImportant());
  return info;
}

代码示例来源:origin: apache/geode

public StandardWrapper addServlet(String path, String name, String clazz)
  throws ServletException {
 StandardWrapper servlet = (StandardWrapper) rootContext.createWrapper();
 servlet.setName(name);
 servlet.setServletClass(clazz);
 servlet.setLoadOnStartup(1);
 rootContext.addChild(servlet);
 rootContext.addServletMapping(path, name);
 servlet.setParent(rootContext);
 // servlet.load();
 return servlet;
}

代码示例来源:origin: apache/geode

@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
 Manager manager = request.getContext().getManager();
 DeltaSessionFacade session = null;
   session = (DeltaSessionFacade) request.getSession(false);
   DeltaSessionManager dsm = ((DeltaSessionManager) manager);
   if (session != null) {
     dsm.removeTouchedSession(session.getId());
     session.commit();
     if (dsm.getTheContext().getLogger().isDebugEnabled()) {
      dsm.getTheContext().getLogger().debug(session + ": Committed.");
     if (dsm.getTheContext().getLogger().isDebugEnabled()) {
      dsm.getTheContext().getLogger().debug(session + ": Not valid so not committing.");

代码示例来源:origin: OryxProject/oryx

getServingLayer().getContext().getServletContext().getAttribute(OryxResource.INPUT_PRODUCER_KEY);

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

/**
 * Gets the application attributes.
 *
 * @param context the context
 * @return the application attributes
 */
public static List<Attribute> getApplicationAttributes(Context context) {
 List<Attribute> attrs = new ArrayList<>();
 ServletContext servletCtx = context.getServletContext();
 for (String attrName : Collections.list(servletCtx.getAttributeNames())) {
  Object attrValue = servletCtx.getAttribute(attrName);
  Attribute attr = new Attribute();
  attr.setName(attrName);
  attr.setValue(attrValue);
  attr.setType(ClassUtils.getQualifiedName(attrValue.getClass()));
  attrs.add(attr);
 }
 return attrs;
}

代码示例来源:origin: pippo-java/pippo

context.setAllowCasualMultipartParsing(true);
PippoServlet pippoServlet = new PippoServlet();
pippoServlet.setApplication(getApplication());
Wrapper wrapper = context.createWrapper();
String name = "pippoServlet";
wrapper.setLoadOnStartup(1);
wrapper.setServlet(pippoServlet);
context.addChild(wrapper);
context.addServletMapping(pippoFilterPath, name);
context.getServletContext().setAttribute(PIPPO_APPLICATION, getApplication());
context.addApplicationListener(PippoServletContextListener.class.getName());
listeners.forEach(listener -> context.addApplicationListener(listener.getName()));

代码示例来源:origin: tomcat/catalina

/**
 * Called to forward to the error page
 * 
 * @param request Request we are processing
 * @param response Response we are creating
 * @param config    Login configuration describing how authentication
 *              should be performed
 */
protected void forwardToErrorPage(Request request, Response response, LoginConfig config) {
  RequestDispatcher disp =
    context.getServletContext().getRequestDispatcher
    (config.getErrorPage());
  try {
    disp.forward(request.getRequest(), response.getResponse());
  } catch (Throwable t) {
    log.warn("Unexpected error forwarding to error page", t);
  }
}

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

/**
 * 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().getContext().getName() ));
  }
  ((DeltaSession)session).resetDeltaRequest();
}

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

/**
 * get Cluster DeltaManager
 * 
 * @param request current request
 * @return manager or null
 */
protected Manager getManager(Request request) {
  Manager manager = request.getContext().getManager();
  if (log.isDebugEnabled()) {
    if(manager != null)
      log.debug(sm.getString("jvmRoute.foundManager", manager,  request.getContext().getName()));
    else 
      log.debug(sm.getString("jvmRoute.notFoundManager", request.getContext().getName()));
  }
  return manager;
}

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

private void doConnectorAuthenticationAuthorization(org.apache.coyote.Request req, Request request) {
  String username = req.getRemoteUser().toString();
  if (username != null) {
    if (log.isDebugEnabled()) {
      log.debug(sm.getString("coyoteAdapter.authenticate", username));
    if (req.getRemoteUserNeedsAuthorization()) {
      Authenticator authenticator = request.getContext().getAuthenticator();
      if (!(authenticator instanceof AuthenticatorBase)) {
        if (log.isDebugEnabled()) {
          log.debug(sm.getString("coyoteAdapter.authorize", username));
        request.setUserPrincipal(
            request.getContext().getRealm().authenticate(username));
  String authtype = req.getAuthType().toString();
  if (authtype != null) {
    request.setAuthType(authtype);

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

/**
 * Notify interested listeners that attribute has been removed.
 */
private void notifyAttributeRemoved(String name, Object value) {
  Object listeners[] = context.getApplicationEventListeners();
  if ((listeners == null) || (listeners.length == 0)) {
    return;
  }
  ServletRequestAttributeEvent event =
   new ServletRequestAttributeEvent(context.getServletContext(),
                    getRequest(), name, value);
  for (int i = 0; i < listeners.length; i++) {
    if (!(listeners[i] instanceof ServletRequestAttributeListener)) {
      continue;
    }
    ServletRequestAttributeListener listener =
      (ServletRequestAttributeListener) listeners[i];
    try {
      listener.attributeRemoved(event);
    } catch (Throwable t) {
      ExceptionUtils.handleThrowable(t);
      context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
      // Error valve will pick this exception up and display it to user
      attributes.put(RequestDispatcher.ERROR_EXCEPTION, t);
    }
  }
}

代码示例来源:origin: redisson/redisson

@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
  String sessionId = request.getRequestedSessionId();
  Session session = request.getContext().getManager().findSession(sessionId);
  if (session != null) {
    if (!session.isValid()) {
      session.expire();
      request.getContext().getManager().remove(session);
    } else {
      manager.add(session);
      session.access();
      session.endAccess();
    }
  }
  
  try {
    getNext().invoke(request, response);
  } finally {
    manager.store(request.getSession(false));
  }
}

代码示例来源:origin: org.picketlink.distribution/picketlink-jbas7

public Principal authenticateSSL(Request request, Response response) throws IOException {
  if (containerLog.isDebugEnabled()) {
    containerLog.debug(" Looking up certificates");
  X509Certificate[] certs = (X509Certificate[]) request.getAttribute(Globals.CERTIFICATES_ATTR);
      request.getCoyoteRequest().action(ActionCode.ACTION_REQ_SSL_CERTIFICATE, null);
    } catch (IllegalStateException ise) {
      response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.certificates"));
      return null;
    certs = (X509Certificate[]) request.getAttribute(Globals.CERTIFICATES_ATTR);
    if (containerLog.isDebugEnabled()) {
      containerLog.debug("  No certificates included with this request");
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.certificates"));
    return null;
  Principal principal = getContext().getRealm().authenticate(certs);
      containerLog.debug("  Realm.authenticate() returned false");
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.unauthorized"));
    return null;

代码示例来源:origin: apache/geode

+ " as s where s.contextName = '" + context.getPath() + "'");
getLogger().debug("Query: " + query.getQueryString());
 results = (SelectResults) query.execute();
} catch (Exception ex) {
 getLogger().error("Unable to perform query during doUnload", ex);
 return;
 getLogger().debug("No sessions to unload for context " + context.getPath());
 return; // nothing to do
File store = sessionStore(context.getPath());
if (store == null) {
 return;

代码示例来源:origin: org.apache.tomcat/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.
 * @param context The class loader of this context will be used to attempt
 *  to load the class
 * @param className The class name
 * @return the loaded class or <code>null</code> if loading failed
 */
public static Class<?> loadClass(Context context, String className) {
  ClassLoader cl = context.getLoader().getClassLoader();
  Log log = context.getLogger();
  Class<?> clazz = null;
  try {
    clazz = cl.loadClass(className);
  } catch (ClassNotFoundException | NoClassDefFoundError | ClassFormatError e) {
    log.debug(sm.getString("introspection.classLoadFailed", className), e);
  } catch (Throwable t) {
    ExceptionUtils.handleThrowable(t);
    log.debug(sm.getString("introspection.classLoadFailed", className), t);
  }
  return clazz;
}

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

@Override
protected ModelAndView handleContext(String contextName, Context context,
  HttpServletRequest request, HttpServletResponse response) throws Exception {
 String attrName = ServletRequestUtils.getStringParameter(request, "attr");
 context.getServletContext().removeAttribute(attrName);
 return new ModelAndView(new RedirectView(
   request.getContextPath() + getViewName() + "?" + request.getQueryString()));
}

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

public boolean timeout() {
  AtomicBoolean result = new AtomicBoolean();
  request.getCoyoteRequest().action(ActionCode.ASYNC_TIMEOUT, result);
  if (result.get()) {
    ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
    ClassLoader newCL = request.getContext().getLoader().getClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(newCL);
      List<AsyncListenerWrapper> listenersCopy = new ArrayList<>();
      listenersCopy.addAll(listeners);
      for (AsyncListenerWrapper listener : listenersCopy) {
        try {
          listener.fireOnTimeout(event);
        } catch (Throwable t) {
          ExceptionUtils.handleThrowable(t);
          log.warn("onTimeout() failed for listener of type [" +
              listener.getClass().getName() + "]", t);
        }
      }
      request.getCoyoteRequest().action(
          ActionCode.ASYNC_IS_TIMINGOUT, result);
      return !result.get();
    } finally {
      Thread.currentThread().setContextClassLoader(oldCL);
    }
  }
  return true;
}

相关文章

微信公众号

最新文章

更多

Context类方法