当前位置: 首页>>代码示例>>Java>>正文


Java ServletRegistration类代码示例

本文整理汇总了Java中javax.servlet.ServletRegistration的典型用法代码示例。如果您正苦于以下问题:Java ServletRegistration类的具体用法?Java ServletRegistration怎么用?Java ServletRegistration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServletRegistration类属于javax.servlet包,在下文中一共展示了ServletRegistration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: contextInitialized

import javax.servlet.ServletRegistration; //导入依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {

    ServletContext ctx = sce.getServletContext();

    ServletRegistration.Dynamic sd = ctx.addServlet("DynamicServlet",
            "com.creditease.monitorframework.fat.DynamicServlet");

    sd.addMapping("/DynamicServlet");
    sd.setInitParameter("test", "test");
    sd.setLoadOnStartup(1);
    sd.setAsyncSupported(false);

    FilterRegistration.Dynamic fd = ctx.addFilter("DynamicFilter",
            "com.creditease.monitorframework.fat.filters.DynamicFilter");

    fd.addMappingForUrlPatterns(null, true, "/DynamicServlet");
    fd.setInitParameter("test2", "test2");
    fd.setAsyncSupported(false);

    ctx.addListener("com.creditease.monitorframework.fat.listeners.TestServletInitListener");
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:23,代码来源:DynamicServletInit.java

示例2: initMetrics

import javax.servlet.ServletRegistration; //导入依赖的package包/类
/**
 * Initializes Metrics.
 */
private void initMetrics(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Initializing Metrics registries");
    servletContext.setAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE,
        metricRegistry);
    servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY,
        metricRegistry);

    log.debug("Registering Metrics Filter");
    FilterRegistration.Dynamic metricsFilter = servletContext.addFilter("webappMetricsFilter",
        new InstrumentedFilter());

    metricsFilter.addMappingForUrlPatterns(disps, true, "/*");
    metricsFilter.setAsyncSupported(true);

    log.debug("Registering Metrics Servlet");
    ServletRegistration.Dynamic metricsAdminServlet =
        servletContext.addServlet("metricsServlet", new MetricsServlet());

    metricsAdminServlet.addMapping("/management/metrics/*");
    metricsAdminServlet.setAsyncSupported(true);
    metricsAdminServlet.setLoadOnStartup(2);
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:26,代码来源:WebConfigurer.java

示例3: collectUrlPatterns

import javax.servlet.ServletRegistration; //导入依赖的package包/类
static String[] collectUrlPatterns(ServletContext servletContext, Class<?> servletCls) {
  List<ServletRegistration> servlets = servletContext.getServletRegistrations()
      .values()
      .stream()
      .filter(predicate -> {
        return predicate.getClassName().equals(servletCls.getName());
      })
      .collect(Collectors.toList());
  if (servlets.isEmpty()) {
    return new String[] {};
  }

  ServletRegistration servletRegistration = servlets.get(0);
  Collection<String> mappings = servletRegistration.getMappings();
  if (servlets.size() > 1) {
    LOGGER.info("Found {} {} registered, select the first one, mappings={}.",
        servlets.size(),
        servletCls.getName(),
        mappings);
  }
  return filterUrlPatterns(mappings);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:23,代码来源:ServletUtils.java

示例4: addDispatcherContext

import javax.servlet.ServletRegistration; //导入依赖的package包/类
private void addDispatcherContext(ServletContext container) {
  // Create the dispatcher servlet's Spring application context
  AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
  dispatcherContext.register(SpringDispatcherConfig.class); 
  
	 
  // Declare  <servlet> and <servlet-mapping> for the DispatcherServlet
  ServletRegistration.Dynamic dispatcher = container.addServlet("ch08-servlet", 
  		new DispatcherServlet(dispatcherContext));
  dispatcher.addMapping("/");
  dispatcher.setLoadOnStartup(1);
  dispatcher.setAsyncSupported(true); 
  
  //FilterRegistration.Dynamic springSecurityFilterChain = container.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());
   // springSecurityFilterChain.addMappingForUrlPatterns(null, false, "/*");
   // springSecurityFilterChain.setAsyncSupported(true);

}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:19,代码来源:SpringWebinitializer.java

示例5: addDispatcherContext

import javax.servlet.ServletRegistration; //导入依赖的package包/类
private void addDispatcherContext(ServletContext container) {
	// Create the dispatcher servlet's Spring application context
	AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
	dispatcherContext.register(SpringDispatcherConfig.class);

	// Declare <servlet> and <servlet-mapping> for the DispatcherServlet
	ServletRegistration.Dynamic dispatcher = container.addServlet("ch03-servlet",
			new DispatcherServlet(dispatcherContext));
	dispatcher.addMapping("*.html");
	dispatcher.setLoadOnStartup(1);

	FilterRegistration.Dynamic corsFilter = container.addFilter("corsFilter", new CorsFilter());
	corsFilter.setInitParameter("cors.allowed.methods", "GET, POST, HEAD, OPTIONS, PUT, DELETE");
	corsFilter.addMappingForUrlPatterns(null, true, "/*");

	FilterRegistration.Dynamic filter = container.addFilter("hiddenmethodfilter", new HiddenHttpMethodFilter());
	filter.addMappingForServletNames(null, true, "/*");

	FilterRegistration.Dynamic multipartFilter = container.addFilter("multipartFilter", new MultipartFilter());
	multipartFilter.addMappingForUrlPatterns(null, true, "/*");

}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:23,代码来源:SpringWebinitializer.java

示例6: regiesterVIServlet

import javax.servlet.ServletRegistration; //导入依赖的package包/类
protected static final void regiesterVIServlet(ServletContext context,Logger logger){

        try {
            ServletRegistration.Dynamic asr = context.addServlet("VIApiServlet", VIApiServlet.class);

            if (asr != null) {
                asr.setLoadOnStartup(Integer.MAX_VALUE);
                asr.addMapping("/@in/api/*");
            } else {
                logger.warn("Servlet VIApiServlet already exists");
            }

            ServletRegistration ssr = context.addServlet("VIHttpServlet", StaticContentServlet.class);
            if (ssr != null) {
                ssr.addMapping("/@in/*");
            } else {
                logger.warn("Servlet VIHttpServlet already exists");
            }

        }catch (Throwable e){
            logger.error("VI register servlet failed",e);
        }
    }
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:24,代码来源:ServletRegister.java

示例7: onStartup

import javax.servlet.ServletRegistration; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    //On charge le contexte de l'app
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setDisplayName("scrumtracker");
    rootContext.register(ApplicationContext.class);

    //Context loader listener
    servletContext.addListener(new ContextLoaderListener(rootContext));

    //Dispatcher servlet
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
}
 
开发者ID:scrumtracker,项目名称:scrumtracker2017,代码行数:17,代码来源:ApplicationInitializer.java

示例8: addEndpointMappingToCasServlet

import javax.servlet.ServletRegistration; //导入依赖的package包/类
/**
 * Add endpoint mapping to cas servlet.
 *
 * @param sce the sce
 * @param mapping the mapping
 */
protected final void addEndpointMappingToCasServlet(final ServletContextEvent sce, final String mapping) {
    logger.info("Adding [{}] to {} servlet context", mapping, WebUtils.CAS_SERVLET_NAME);
    final ServletRegistration registration = getCasServletRegistration(sce);
    if (registration != null) {

        registration.addMapping(mapping);
        logger.info("Added [{}] to {} servlet context", mapping, WebUtils.CAS_SERVLET_NAME);
    }
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:16,代码来源:AbstractServletContextInitializer.java

示例9: onStartup

import javax.servlet.ServletRegistration; //导入依赖的package包/类
@Override
public void onStartup(ServletContext container) {
	// Create the 'root' Spring application context
	AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
	rootContext.register(AppConfig.class);

	// Manage the lifecycle of the root application context
	container.addListener(new ContextLoaderListener(rootContext));

	// Create the dispatcher servlet's Spring application context
	AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();

	// Register and map the dispatcher servlet
	ServletRegistration.Dynamic dispatcher = container
			.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/");
}
 
开发者ID:auth0-blog,项目名称:embedded-spring-5,代码行数:19,代码来源:AppConfig.java

示例10: addServlet

import javax.servlet.ServletRegistration; //导入依赖的package包/类
@Override
public ServletRegistration.Dynamic addServlet(final String servletName, final String className) {
    ensureNotProgramaticListener();
    ensureNotInitialized();
    try {
        if (deploymentInfo.getServlets().containsKey(servletName)) {
            return null;
        }
        ServletInfo servlet = new ServletInfo(servletName, (Class<? extends Servlet>) deploymentInfo.getClassLoader().loadClass(className));
        readServletAnnotations(servlet);
        deploymentInfo.addServlet(servlet);
        ServletHandler handler = deployment.getServlets().addServlet(servlet);
        return new ServletRegistrationImpl(servlet, handler.getManagedServlet(), deployment);
    } catch (ClassNotFoundException e) {
        throw UndertowServletMessages.MESSAGES.cannotLoadClass(className, e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ServletContextImpl.java

示例11: collectDynInfo

import javax.servlet.ServletRegistration; //导入依赖的package包/类
public void collectDynInfo(String methodName, Object res, Object[] args) {

        if (methodName.equals("addServlet")) {

            servlets.add((ServletRegistration.Dynamic) res);
        }
        else if (methodName.equals("addFilter")) {

            filters.add((FilterRegistration.Dynamic) res);
        }
        else if (methodName.equals("addListener")) {

            String listenerClassName;
            if (args[0].getClass().isAssignableFrom(String.class)) {
                listenerClassName = args[0].toString();
            }
            else if (args[0].getClass().isAssignableFrom(Class.class)) {
                listenerClassName = ((Class<?>) args[0]).getName();
            }
            else {
                listenerClassName = args[0].getClass().getName();
            }

            listeners.add(listenerClassName);
        }
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:27,代码来源:DynamicServletContextProcessor.java

示例12: init

import javax.servlet.ServletRegistration; //导入依赖的package包/类
@Override
public void init(ServletConfig servletConfig) throws ServletException {
	// 初始化相关Helper类
	HelperLoader.init();
	// 获取ServletContext对象(用于注册Servlet)
	ServletContext servletContext = servletConfig.getServletContext();
	// 注册处理jsp的servlet
	ServletRegistration jspServlet = servletContext
			.getServletRegistration("jsp");
	jspServlet.addMapping(ConfigHelper.getAppJspPath() + "*");
	// 注册处理静态资源的默认Servlet
	ServletRegistration defaultServlet = servletContext
			.getServletRegistration("default");
	defaultServlet.addMapping(ConfigHelper.getAppAssetPath() + "*");
}
 
开发者ID:longjiazuo,项目名称:light-framework,代码行数:16,代码来源:DispatcherServlet.java

示例13: getServletRegistrations

import javax.servlet.ServletRegistration; //导入依赖的package包/类
@Override
public Map<String, ? extends ServletRegistration> getServletRegistrations()
{
    if (!_enabled)
        throw new UnsupportedOperationException();

    HashMap<String, ServletRegistration> registrations = new HashMap<String, ServletRegistration>();
    ServletHandler handler=ServletContextHandler.this.getServletHandler();
    ServletHolder[] holders=handler.getServlets();
    if (holders!=null)
    {
        for (ServletHolder holder : holders)
            registrations.put(holder.getName(),holder.getRegistration());
    }
    return registrations;
}
 
开发者ID:xiaomin0322,项目名称:marathon-auth-plugin,代码行数:17,代码来源:ServletContextHandler.java

示例14: setServletSecurity

import javax.servlet.ServletRegistration; //导入依赖的package包/类
/**
 * Delegate for ServletRegistration.Dynamic.setServletSecurity method
 * @param registration ServletRegistration.Dynamic instance that setServletSecurity was called on
 * @param servletSecurityElement new security info
 * @return the set of exact URL mappings currently associated with the registration that are also present in the web.xml
 * security constraints and thus will be unaffected by this call.
 */
public Set<String> setServletSecurity(ServletRegistration.Dynamic registration, ServletSecurityElement servletSecurityElement)
{
    //Default implementation is to just accept them all. If using a webapp, then this behaviour is overridden in WebAppContext.setServletSecurity       
    Collection<String> pathSpecs = registration.getMappings();
    if (pathSpecs != null)
    {
        for (String pathSpec:pathSpecs)
        {
            List<ConstraintMapping> mappings = ConstraintSecurityHandler.createConstraintsWithMappingsForPath(registration.getName(), pathSpec, servletSecurityElement);
            for (ConstraintMapping m:mappings)
                ((ConstraintAware)getSecurityHandler()).addConstraintMapping(m);
        }
    }
    return Collections.emptySet();
}
 
开发者ID:xiaomin0322,项目名称:marathon-auth-plugin,代码行数:23,代码来源:ServletContextHandler.java

示例15: registerJspServlet

import javax.servlet.ServletRegistration; //导入依赖的package包/类
private void registerJspServlet(ServletContext context) {
    ServletRegistration servletRegistration = context.getServletRegistration("jsp");
    servletRegistration.addMapping("/index.jsp");
    String jspPath = PropertiesProvider.getString(FrameworkConstant.JSP_PATH);
    if (StringUtil.isNotEmpty(jspPath)) {
    	servletRegistration.addMapping(jspPath + "*");
    }
}
 
开发者ID:smxc,项目名称:garlicts,代码行数:9,代码来源:ContainerListener.java


注:本文中的javax.servlet.ServletRegistration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。