org.eclipse.jetty.webapp.WebAppContext.getServletHandler()方法的使用及代码示例

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

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

WebAppContext.getServletHandler介绍

暂无

代码示例

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

/**
 * {@inheritDoc}
 */
@Override
public void end(WebAppContext context, Descriptor descriptor)
{
  context.getServletHandler().setFilters(_filterHolders.toArray(new FilterHolder[_filterHolderMap.size()]));
  context.getServletHandler().setServlets(_servletHolders.toArray(new ServletHolder[_servletHolderMap.size()]));
  context.getServletHandler().setFilterMappings(_filterMappings.toArray(new FilterMapping[_filterMappings.size()]));
  context.getServletHandler().setServletMappings(_servletMappings.toArray(new ServletMapping[_servletMappings.size()]));
  _filterHolderMap.clear();
  _filterHolders.clear();
  _filterMappings.clear();
  _servletHolderMap.clear();
  _servletHolders.clear();
  _servletMappings.clear();
}

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

private void performInjectionForComponentUis(final Collection<WebAppContext> componentUiExtensionWebContexts,
                       final NiFiWebConfigurationContext configurationContext, final FilterHolder securityFilter) {
  if (CollectionUtils.isNotEmpty(componentUiExtensionWebContexts)) {
    for (final WebAppContext customUiContext : componentUiExtensionWebContexts) {
      // set the NiFi context in each custom ui servlet context
      final ServletContext customUiServletContext = customUiContext.getServletHandler().getServletContext();
      customUiServletContext.setAttribute("nifi-web-configuration-context", configurationContext);
      // add the security filter to any ui extensions wars
      if (securityFilter != null) {
        customUiContext.addFilter(securityFilter, "/*", EnumSet.allOf(DispatcherType.class));
      }
    }
  }
}

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

/**
 * {@inheritDoc}
 */
@Override
public void start(WebAppContext context, Descriptor descriptor)
{
  for (FilterHolder h : context.getServletHandler().getFilters())
  {
    _filterHolderMap.put(h.getName(),h);
    _filterHolders.add(h);
  }
  if (context.getServletHandler().getFilterMappings()!=null)
    _filterMappings.addAll(Arrays.asList(context.getServletHandler().getFilterMappings()));
  for (ServletHolder h : context.getServletHandler().getServlets())
  {
    _servletHolderMap.put(h.getName(),h);
    _servletHolders.add(h);
  }
  if (context.getServletHandler().getServletMappings()!=null)
    _servletMappings.addAll(Arrays.asList(context.getServletHandler().getServletMappings()));
}

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

/**
 * Setup cross-origin requests (CORS) filter.
 * @param b - builder
 */
private void setupCORSFilter(Builder b) {
 FilterHolder holder = new FilterHolder();
 holder.setClassName(CrossOriginFilter.class.getName());
 Map<String, String> params = new HashMap<>();
 params.put(CrossOriginFilter.ALLOWED_ORIGINS, b.allowedOrigins);
 params.put(CrossOriginFilter.ALLOWED_METHODS, b.allowedMethods);
 params.put(CrossOriginFilter.ALLOWED_HEADERS, b.allowedHeaders);
 holder.setInitParameters(params);
 ServletHandler handler = webAppContext.getServletHandler();
 handler.addFilterWithMapping(holder, "/*", FilterMapping.ALL);
}

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

/**
 * Secure the web server with kerberos (AuthenticationFilter).
 */
void setupSpnegoFilter(Builder b) throws IOException {
 Map<String, String> params = new HashMap<String, String>();
 params.put("kerberos.principal",
  SecurityUtil.getServerPrincipal(b.spnegoPrincipal, b.host));
 params.put("kerberos.keytab", b.spnegoKeytab);
 params.put(AuthenticationFilter.AUTH_TYPE, "kerberos");
 FilterHolder holder = new FilterHolder();
 holder.setClassName(AuthenticationFilter.class.getName());
 holder.setInitParameters(params);
 ServletHandler handler = webAppContext.getServletHandler();
 handler.addFilterWithMapping(
  holder, "/*", FilterMapping.ALL);
}

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

/**
 * Add Jetty's {@code DefaultServlet} to the given {@link WebAppContext}.
 * @param context the jetty {@link WebAppContext}
 */
protected final void addDefaultServlet(WebAppContext context) {
  Assert.notNull(context, "Context must not be null");
  ServletHolder holder = new ServletHolder();
  holder.setName("default");
  holder.setClassName("org.eclipse.jetty.servlet.DefaultServlet");
  holder.setInitParameter("dirAllowed", "false");
  holder.setInitOrder(1);
  context.getServletHandler().addServletWithMapping(holder, "/");
  context.getServletHandler().getServletMapping("/").setDefault(true);
}

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

public void visitListener(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
  String className = node.getString("listener-class", false, true);
  EventListener listener = null;
  try
  {
    if (className != null && className.length()> 0)
    {
      //Servlet Spec 3.0 p 74
      //Duplicate listener declarations don't result in duplicate listener instances
      for (ListenerHolder holder : context.getServletHandler().getListeners())
      {
        if (holder.getClassName().equals(className))
          return;
      }
      ((WebDescriptor)descriptor).addClassName(className);
      
      ListenerHolder h = context.getServletHandler().newListenerHolder(new Source (Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
      h.setClassName(className);
      context.getServletHandler().addListener(h);
      context.getMetaData().setOrigin(className+".listener", descriptor);
    }
  }
  catch (Exception e)
  {
    LOG.warn("Could not instantiate listener " + className, e);
    return;
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

sh.setInitParameters(params);
final ServletMapping[] servletMappings =
  webAppContext.getServletHandler().getServletMappings();
for (int i = 0; i < servletMappings.length; i++) {
 if (servletMappings[i].containsPathSpec(pathSpec)) {
  webAppContext.getServletHandler()
    .setServletMappings(newServletMappings);
  break;

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

/**
 * Add the path spec to the filter path mapping.
 * @param pathSpec The path spec
 * @param webAppCtx The WebApplicationContext to add to
 */
protected void addFilterPathMapping(String pathSpec,
  WebAppContext webAppCtx) {
 for(String name : filterNames) {
  FilterMapping fmap = new FilterMapping();
  fmap.setPathSpec(pathSpec);
  fmap.setFilterName(name);
  fmap.setDispatches(FilterMapping.ALL);
  webAppCtx.getServletHandler().addFilterMapping(fmap);
 }
}

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

final ServletContext webApiServletContext = webApiContext.getServletHandler().getServletContext();
final WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(webApiServletContext);
final NiFiWebConfigurationContext configurationContext = webApplicationContext.getBean("nifiWebConfigurationContext", NiFiWebConfigurationContext.class);
final FilterHolder securityFilter = webApiContext.getServletHandler().getFilter("springSecurityFilterChain");

代码示例来源:origin: org.apache.hadoop/hadoop-common

webAppContext.getServletHandler().getServletMappings();
for (int i = 0; i < servletMappings.length; i++) {
 if (servletMappings[i].containsPathSpec(pathSpec)) {
  webAppContext.getServletHandler()
    .setServletMappings(newServletMappings);
  break;
 ServletHandler handler = webAppContext.getServletHandler();
 FilterMapping fmap = new FilterMapping();
 fmap.setPathSpec(pathSpec);

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

/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 +   * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec,
  Class<? extends HttpServlet> clazz, boolean requireAuth) {
 ServletHolder holder = new ServletHolder(clazz);
 if (name != null) {
  holder.setName(name);
 }
 webAppContext.addServlet(holder, pathSpec);
 if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
   LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
   ServletHandler handler = webAppContext.getServletHandler();
   FilterMapping fmap = new FilterMapping();
   fmap.setPathSpec(pathSpec);
   fmap.setFilterName(SPNEGO_FILTER);
   fmap.setDispatches(FilterMapping.ALL);
   handler.addFilterMapping(fmap);
 }
}

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

/**
 * Add Jetty's {@code JspServlet} to the given {@link WebAppContext}.
 * @param context the jetty {@link WebAppContext}
 */
protected final void addJspServlet(WebAppContext context) {
  Assert.notNull(context, "Context must not be null");
  ServletHolder holder = new ServletHolder();
  holder.setName("jsp");
  holder.setClassName(getJsp().getClassName());
  holder.setInitParameter("fork", "false");
  holder.setInitParameters(getJsp().getInitParameters());
  holder.setInitOrder(3);
  context.getServletHandler().addServlet(holder);
  ServletMapping mapping = new ServletMapping();
  mapping.setServletName("jsp");
  mapping.setPathSpecs(new String[] { "*.jsp", "*.jspx" });
  context.getServletHandler().addServletMapping(mapping);
}

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

final ServletContext webApiServletContext = webApiContext.getServletHandler().getServletContext();
webApiServletContext.setAttribute("nifi-ui-extensions", componentUiExtensions);
final FilterHolder securityFilter = webApiContext.getServletHandler().getFilter("springSecurityFilterChain");
  final ServletContext webContentViewerServletContext = webContentViewerContext.getServletHandler().getServletContext();
  webContentViewerServletContext.setAttribute("nifi-content-access", contentAccess);
final ServletContext webDocsServletContext = webDocsContext.getServletHandler().getServletContext();
webDocsServletContext.setAttribute("nifi-extension-mapping", extensionMapping);

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

if (holder == null)
  holder = context.getServletHandler().newFilterHolder(new Source (Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
  holder.setName(name);
  _filterHolderMap.put(name,holder);

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

holder = context.getServletHandler().newServletHolder(new Source (Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
holder.setName(name);
_servletHolderMap.put(name,holder);

代码示例来源:origin: kumuluz/kumuluzee

@Override
public List<ServletWrapper> getRegisteredServlets() {
  List<ServletWrapper> servlets = new ArrayList<>();
  Arrays.stream(this.appContext.getServletHandler().getServlets())
      .forEach(s -> servlets.add(new ServletWrapper(s.getName(), s.getContextPath())));
  return servlets;
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server

@Override
  public void deconfigure (WebAppContext context) throws Exception
  {
    ServletHandler _servletHandler = context.getServletHandler();
        context.setWelcomeFiles(null);

    if (context.getErrorHandler() instanceof ErrorPageErrorHandler)
      ((ErrorPageErrorHandler) 
          context.getErrorHandler()).setErrorPages(null);

    // TODO remove classpaths from classloader

  }
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-plus

@Override
  public void deconfigure (WebAppContext context) throws Exception
  {
    ServletHandler _servletHandler = context.getServletHandler();
        context.setWelcomeFiles(null);

    if (context.getErrorHandler() instanceof ErrorPageErrorHandler)
      ((ErrorPageErrorHandler) 
          context.getErrorHandler()).setErrorPages(null);

    // TODO remove classpaths from classloader

  }
}

代码示例来源:origin: org.apache.maven.wagon/wagon-tck-http

public void addFilter( final String pathSpec, final Filter filter )
{
  String name = "filter" + filterCount++;
  FilterMapping fm = new FilterMapping();
  fm.setPathSpec( pathSpec );
  fm.setFilterName( name );
  FilterHolder fh = new FilterHolder( filter );
  fh.setName( name );
  webappContext.getServletHandler().addFilter( fh, fm );
}

相关文章

WebAppContext类方法