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

x33g5p2x  于2022-02-02 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(181)

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

Wrapper介绍

[英]A Wrapper is a Container that represents an individual servlet definition from the deployment descriptor of the web application. It provides a convenient mechanism to use Interceptors that see every single request to the servlet represented by this definition.

Implementations of Wrapper are responsible for managing the servlet life cycle for their underlying servlet class, including calling init() and destroy() at appropriate times, as well as respecting the existence of the SingleThreadModel declaration on the servlet class itself.

The parent Container attached to a Wrapper will generally be an implementation of Context, representing the servlet context (and therefore the web application) within which this servlet executes.

Child Containers are not allowed on Wrapper implementations, so the addChild() method should throw an IllegalArgumentException.
[中]包装器是一个容器,表示web应用程序部署描述符中的单个servlet定义。它提供了一种方便的机制来使用拦截器,拦截器可以查看对这个定义所表示的servlet的每个请求。
Wrapper的实现负责管理其底层servlet类的servlet生命周期,包括在适当的时间调用init()和destroy(),并考虑servlet类本身是否存在SingleThreadModel声明。
附加到包装器的父容器通常是上下文的一个实现,表示servlet执行所在的servlet上下文(以及web应用程序)。
包装器实现中不允许使用子容器,因此addChild()方法应该抛出IllegalArgumentException

代码示例

代码示例来源:origin: org.springframework.boot/spring-boot

private void addDefaultServlet(Context context) {
  Wrapper defaultServlet = context.createWrapper();
  defaultServlet.setName("default");
  defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet");
  defaultServlet.addInitParameter("debug", "0");
  defaultServlet.addInitParameter("listings", "false");
  defaultServlet.setLoadOnStartup(1);
  // Otherwise the default location of a Spring DispatcherServlet cannot be set
  defaultServlet.setOverridable(true);
  context.addChild(defaultServlet);
  context.addServletMappingDecoded("/", "default");
}

代码示例来源:origin: org.springframework.boot/spring-boot

private void load(Wrapper wrapper) {
  try {
    wrapper.load();
  }
  catch (ServletException ex) {
    String message = sm.getString("standardContext.loadOnStartup.loadException",
        getName(), wrapper.getName());
    if (getComputedFailCtxIfServletStartFails()) {
      throw new WebServerException(message, ex);
    }
    getLogger().error(message, StandardWrapper.getRootCause(ex));
  }
}

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

/**
 * Gets the application servlet maps.
 *
 * @param context the context
 * @return the application servlet maps
 */
public static List<ServletMapping> getApplicationServletMaps(Context context) {
 String[] sms = context.findServletMappings();
 List<ServletMapping> servletMaps = new ArrayList<>(sms.length);
 for (String servletMapping : sms) {
  if (servletMapping != null) {
   String sn = context.findServletMapping(servletMapping);
   if (sn != null) {
    ServletMapping sm = new ServletMapping();
    sm.setApplicationName(context.getName().length() > 0 ? context.getName() : "/");
    sm.setUrl(servletMapping);
    sm.setServletName(sn);
    Container container = context.findChild(sn);
    if (container instanceof Wrapper) {
     Wrapper wrapper = (Wrapper) container;
     sm.setServletClass(wrapper.getServletClass());
     sm.setAvailable(!wrapper.isUnavailable());
    }
    servletMaps.add(sm);
   }
  }
 }
 return servletMaps;
}

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

context.setWebappVersion("3.1");
context.setName("Oryx");
context.addWelcomeFile("index.html");
addErrorPages(context);
wrapper.addInitParameter("javax.ws.rs.Application", OryxApplication.class.getName());
wrapper.addMapping("/*");
wrapper.setLoadOnStartup(1);
wrapper.setMultipartConfigElement(new MultipartConfigElement(""));

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

/**
 * 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, connector));
  }
}

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

int statusCode = response.getStatus();
Context context = request.getContext();
if (context == null)
  return;
if (!response.isError())
  return;
ErrorPage errorPage = context.findErrorPage(statusCode);
if (errorPage != null) {
  response.setAppCommitted(false);
  request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE,
           Integer.valueOf(statusCode));
  if (message == null)
    message = "";
  request.setAttribute(RequestDispatcher.ERROR_MESSAGE, message);
  request.setAttribute
    (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
  if (wrapper != null)
    request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME,
             wrapper.getName());
  request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI,
             request.getRequestURI());
      container.getLogger().warn("Exception Processing " + errorPage, e);

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

if (wrapper.isUnavailable()) {
  wrapper.getLogger().warn(
      sm.getString("applicationDispatcher.isUnavailable",
      wrapper.getName()));
  long available = wrapper.getAvailable();
  if ((available > 0L) && (available < Long.MAX_VALUE))
    hresponse.setDateHeader("Retry-After", available);
  hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, sm
      .getString("applicationDispatcher.isUnavailable", wrapper
          .getName()));
  unavailable = true;
    servlet = wrapper.allocate();
  wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException",
           wrapper.getName()), StandardWrapper.getRootCause(e));
  servletException = e;
} catch (Throwable e) {
  ExceptionUtils.handleThrowable(e);
  wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException",
           wrapper.getName()), e);
           wrapper.getName()), e);
  servlet = null;
  support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
               servlet, request, response);
  wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
           wrapper.getName()), e);

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

Context context = request.getContext();
if (context == null) {
  return;
  if (log.isDebugEnabled()) {
    log.debug
      (sm.getString("standardHost.clientAbort",
        realError.getCause().getMessage()));
ErrorPage errorPage = context.findErrorPage(throwable);
if ((errorPage == null) && (realError != throwable)) {
  errorPage = context.findErrorPage(realError);
    if (wrapper != null) {
      request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME,
               wrapper.getName());
    request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI,
    if (custom(request, response, errorPage)) {
      try {
        response.finishResponse();
      } catch (IOException e) {
        container.getLogger().warn("Exception Processing " + errorPage, e);

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

if (wrapper.isUnavailable()) {
  wrapper.getLogger().warn(
      sm.getString("applicationDispatcher.isUnavailable",
      wrapper.getName()));
  long available = wrapper.getAvailable();
  if ((available > 0L) && (available < Long.MAX_VALUE))
    hresponse.setDateHeader("Retry-After", available);
  hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, sm
      .getString("applicationDispatcher.isUnavailable", wrapper
          .getName()));
  unavailable = true;
    servlet = wrapper.allocate();
  wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException",
           wrapper.getName()), StandardWrapper.getRootCause(e));
  servletException = e;
} catch (Throwable e) {
  ExceptionUtils.handleThrowable(e);
  wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException",
           wrapper.getName()), e);
           wrapper.getName()), e);
  servlet = null;
  ioException = e;
} catch (IOException e) {
  wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
           wrapper.getName()), e);

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

int statusCode = response.getStatus();
Context context = request.getContext();
if (context == null) {
  return;
if (!response.isError()) {
  return;
ErrorPage errorPage = context.findErrorPage(statusCode);
if (errorPage == null) {
  errorPage = context.findErrorPage(0);
    message = "";
  request.setAttribute(RequestDispatcher.ERROR_MESSAGE, message);
  request.setAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR,
      errorPage.getLocation());
  if (wrapper != null) {
    request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME,
             wrapper.getName());
  request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI,
      container.getLogger().warn("Exception Processing " + errorPage, e);

代码示例来源:origin: org.jboss.web/jbossweb

protected void addContext(Context context) {
  mapper.addContext(context.getParent().getName(), context.getName(), context, 
      context.findWelcomeFiles(), context.getResources());
  // Add all wrappers
  for (Container child : context.findChildren()) {
    Wrapper wrapper = (Wrapper) child;
    if (wrapper.getEnabled()) {
      for (String mapping : wrapper.findMappings()) {
        boolean jspWildCard = ("jsp".equals(wrapper.getName()) 
            && mapping.endsWith("/*"));
        mapper.addWrapper(context.getParent().getName(), context.getName(), 
            mapping, wrapper, jspWildCard);
      }
    }
  }
}

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

boolean jspWildCard) {
if (findChild(name) == null)
  throw new IllegalArgumentException
    (sm.getString("standardContext.servletMap.name", name));
String adjustedPattern = adjustURLPattern(pattern);
if (!validateURLPattern(adjustedPattern))
  throw new IllegalArgumentException
    (sm.getString("standardContext.servletMap.pattern", adjustedPattern));
    Wrapper wrapper = (Wrapper) findChild(name2);
    wrapper.removeMapping(adjustedPattern);
Wrapper wrapper = (Wrapper) findChild(name);
wrapper.addMapping(adjustedPattern);
fireContainerEvent("addServletMapping", adjustedPattern);

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

/**
 * Static version of {@link #addServlet(String, String, String)}
 * @param ctx           Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servletClass  The class to be used for the Servlet
 * @return The wrapper for the servlet
 */
public static Wrapper addServlet(Context ctx,
                 String servletName,
                 String servletClass) {
  // will do class for name and set init params
  Wrapper sw = ctx.createWrapper();
  sw.setServletClass(servletClass);
  sw.setName(servletName);
  ctx.addChild(sw);
  return sw;
}

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

context.setAllowCasualMultipartParsing(true);
PippoServlet pippoServlet = new PippoServlet();
pippoServlet.setApplication(getApplication());
Wrapper wrapper = context.createWrapper();
String name = "pippoServlet";
wrapper.setName(name);
wrapper.setLoadOnStartup(1);
wrapper.setServlet(pippoServlet);
context.addChild(wrapper);
context.addServletMapping(pippoFilterPath, name);

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

private Set<String> getNonAsyncClassNames() {
  Set<String> result = new HashSet<>();
  Wrapper wrapper = getWrapper();
  if (!wrapper.isAsyncSupported()) {
    result.add(wrapper.getServletClass());
  }
  FilterChain filterChain = getFilterChain();
  if (filterChain instanceof ApplicationFilterChain) {
    ((ApplicationFilterChain) filterChain).findNonAsyncFilters(result);
  } else {
    result.add(sm.getString("coyoteRequest.filterAsyncSupportUnknown"));
  }
  Container c = wrapper;
  while (c != null) {
    c.getPipeline().findNonAsyncValves(result);
    c = c.getParent();
  }
  return result;
}

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

@Override
public boolean setInitParameter(String name, String value) {
  if (name == null || value == null) {
    throw new IllegalArgumentException(
        sm.getString("applicationFilterRegistration.nullInitParam",
            name, value));
  }
  if (getInitParameter(name) != null) {
    return false;
  }
  wrapper.addInitParameter(name, value);
  return true;
}

代码示例来源:origin: org.apache.openejb/tomee-webservices

private void setWsContainer(Context context, Wrapper wrapper, HttpListener wsContainer) {
    // Make up an ID for the WebServiceContainer
    // put a reference the ID in the init-params
    // put the WebServiceContainer in the webapp context keyed by its ID
    String webServicecontainerID = wrapper.getName() + WsServlet.WEBSERVICE_CONTAINER + wsContainer.hashCode();
    context.getServletContext().setAttribute(webServicecontainerID, wsContainer);
    wrapper.addInitParameter(WsServlet.WEBSERVICE_CONTAINER, webServicecontainerID);
  }
}

代码示例来源:origin: nutzam/nutzboot

private void addDefaultServlet() {
  Wrapper defaultServlet = this.tomcatContext.createWrapper();
  defaultServlet.setName("default");
  defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet");
  defaultServlet.addInitParameter("debug", "0");
  defaultServlet.addInitParameter("listings", "false");
  defaultServlet.setLoadOnStartup(1);
  defaultServlet.setOverridable(true);
  this.tomcatContext.addChild(defaultServlet);
  addServletMapping("/", "default");
}

代码示例来源:origin: com.tomitribe.tribestream/tribestream-container

public ProgrammaticContext addServlet(final String name, final Class<?> type, final String mapping, final String... initParams) {
  final Wrapper wrapper = createWrapper();
  wrapper.setServletClass(type.getName());
  wrapper.setName(name);
  if (initParams != null && initParams.length > 0) {
    for (int i = 0; i < initParams.length; i+=2) {
      wrapper.addInitParameter(initParams[i], initParams[i+1]);
    }
  }
  wrapper.setLoadOnStartup(1); // otherwise we would miss reposgitry integration at least
  addChild(wrapper);
  addServletMapping(mapping, wrapper.getName(), false);
  return this;
}

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

public void enter() {
  if (securityService != null && request.getWrapper() != null) {
    oldState = securityService.enterWebApp(request.getWrapper().getRealm(), request.getPrincipal(), request.getWrapper().getRunAs());
  }
}

相关文章