• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ServletContextListener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: prepareAndgetContextListener

import javax.servlet.ServletContextListener; //导入依赖的package包/类
/**
 * Prepares the logger context. Locates the context and
 * sets the configuration file.
 * @return the logger context
 */
private ServletContextListener prepareAndgetContextListener() {
    try {
        if (StringUtils.isNotBlank(this.loggerContextPackageName)) {
            final Collection<URL> set = ClasspathHelper.forPackage(this.loggerContextPackageName);
            final Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(set).setScanners(new SubTypesScanner()));
            final Set<Class<? extends ServletContextListener>> subTypesOf = reflections.getSubTypesOf(ServletContextListener.class);
            final ServletContextListener loggingContext = subTypesOf.iterator().next().newInstance();
            this.context.setInitParameter(this.logConfigurationField, this.logConfigurationFile.getURI().toString());
            return loggingContext;
        }
        return null;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:21,代码来源:CasLoggerContextInitializer.java


示例2: contextInitialized

import javax.servlet.ServletContextListener; //导入依赖的package包/类
public void contextInitialized(ServletContextEvent sce) {
    ctx = WebApplicationContextUtils.getWebApplicationContext(sce
            .getServletContext());

    if (ctx == null) {
        logger.warn("cannot find applicationContext");

        return;
    }

    Collection<ServletContextListener> servletContextListeners = ctx
            .getBeansOfType(ServletContextListener.class).values();

    for (ServletContextListener servletContextListener : servletContextListeners) {
        servletContextListener.contextInitialized(sce);
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:18,代码来源:ProxyServletListener.java


示例3: addListener

import javax.servlet.ServletContextListener; //导入依赖的package包/类
@Override
public void addListener(final Class<? extends EventListener> listenerClass) {
    ensureNotInitialized();
    ensureNotProgramaticListener();
    if (ApplicationListeners.listenerState() != NO_LISTENER &&
            ServletContextListener.class.isAssignableFrom(listenerClass)) {
        throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener();
    }
    InstanceFactory<? extends EventListener> factory = null;
    try {
        factory = deploymentInfo.getClassIntrospecter().createInstanceFactory(listenerClass);
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    final ListenerInfo listener = new ListenerInfo(listenerClass, factory);
    deploymentInfo.addListener(listener);
    deployment.getApplicationListeners().addListener(new ManagedListener(listener, true));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:ServletContextImpl.java


示例4: callContextInitialized

import javax.servlet.ServletContextListener; //导入依赖的package包/类
@Override
public void callContextInitialized(ServletContextListener l, ServletContextEvent e)
{
    try
    {
        //toggle state of the dynamic API so that the listener cannot use it
        if(isProgrammaticListener(l))
            this.getServletContext().setEnabled(false);

        super.callContextInitialized(l, e);
    }
    finally
    {
        //untoggle the state of the dynamic API
        this.getServletContext().setEnabled(true);
    }
}
 
开发者ID:xiaomin0322,项目名称:marathon-auth-plugin,代码行数:18,代码来源:ServletContextHandler.java


示例5: testContextLoaderListenerWithDefaultContext

import javax.servlet.ServletContextListener; //导入依赖的package包/类
@Test
public void testContextLoaderListenerWithDefaultContext() {
	MockServletContext sc = new MockServletContext("");
	sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
			"/org/springframework/web/context/WEB-INF/applicationContext.xml " +
			"/org/springframework/web/context/WEB-INF/context-addition.xml");
	ServletContextListener listener = new ContextLoaderListener();
	ServletContextEvent event = new ServletContextEvent(sc);
	listener.contextInitialized(event);
	WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
	assertTrue("Correct WebApplicationContext exposed in ServletContext", context instanceof XmlWebApplicationContext);
	assertTrue(WebApplicationContextUtils.getRequiredWebApplicationContext(sc) instanceof XmlWebApplicationContext);
	LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle");
	assertTrue("Has father", context.containsBean("father"));
	assertTrue("Has rod", context.containsBean("rod"));
	assertTrue("Has kerry", context.containsBean("kerry"));
	assertTrue("Not destroyed", !lb.isDestroyed());
	assertFalse(context.containsBean("beans1.bean1"));
	assertFalse(context.containsBean("beans1.bean2"));
	listener.contextDestroyed(event);
	assertTrue("Destroyed", lb.isDestroyed());
	assertNull(sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
	assertNull(WebApplicationContextUtils.getWebApplicationContext(sc));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:ContextLoaderTests.java


示例6: testContextLoaderWithInvalidContext

import javax.servlet.ServletContextListener; //导入依赖的package包/类
@Test
public void testContextLoaderWithInvalidContext() throws Exception {
	MockServletContext sc = new MockServletContext("");
	sc.addInitParameter(ContextLoader.CONTEXT_CLASS_PARAM,
			"org.springframework.web.context.support.InvalidWebApplicationContext");
	ServletContextListener listener = new ContextLoaderListener();
	ServletContextEvent event = new ServletContextEvent(sc);
	try {
		listener.contextInitialized(event);
		fail("Should have thrown ApplicationContextException");
	}
	catch (ApplicationContextException ex) {
		// expected
		assertTrue(ex.getCause() instanceof ClassNotFoundException);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:ContextLoaderTests.java


示例7: newListenerInstance

import javax.servlet.ServletContextListener; //导入依赖的package包/类
private void newListenerInstance(){
	if(listenerMetadatas.isEmpty()){
		return;
	}
	ClassLoader classloader= pluginContext.getClassLoader();
	try {
		for(String lisenterClass: listenerMetadatas){
			Class<?> clazz = classloader.loadClass(lisenterClass);
			EventListener listener = (EventListener)clazz.newInstance();
			injectComponentAware(listener);
			if(listener instanceof ServletContextListener){
				((ServletContextListener)listener).contextInitialized(new ServletContextEvent(getServletContext()));
			}
			listenerIntances.add(listener);
		}
		PluginWebInstanceRepository.registerListeners(listenerIntances);
		logger.info("Complete to new and register listener instance");
		
	} catch (Exception e) {
		throw new PuzzleException("New Plugin ["+pluginContext.getName()+"] Listener instance failure",e);
	} 
}
 
开发者ID:balancebeam,项目名称:puzzle,代码行数:23,代码来源:PluginServletManager.java


示例8: start

import javax.servlet.ServletContextListener; //导入依赖的package包/类
/**
 * Initializes the Shiro Security Framework.
 */
@Override
public void start(BundleContext context) throws Exception {
	cacheProviderTracker = new CacheProviderTracker(context, CacheProvider.class);
	cacheProviderTracker.open();
	// Register the Shiro EnvironmentLoaderListener first.
	Dictionary<String, Object> shiroListenerProps = new Hashtable<>();
	shiroListenerProps.put(Constants.SERVICE_VENDOR, "AdeptJ");
	shiroListenerProps.put("osgi.http.whiteboard.listener", "true");
	servRegShiroListener = context.registerService(ServletContextListener.class, new ExtEnvironmentLoaderListener(),
			shiroListenerProps);
	// Now Register the ShiroFilter.
	Dictionary<String, Object> shiroFilterProps = new Hashtable<>();
	shiroFilterProps.put(Constants.SERVICE_VENDOR, "AdeptJ");
	shiroFilterProps.put("osgi.http.whiteboard.filter.name", "Shiro Filter");
	shiroFilterProps.put("osgi.http.whiteboard.filter.pattern", "/*");
	shiroFilterProps.put("osgi.http.whiteboard.filter.asyncSupported", "true");
	shiroFilterProps.put("osgi.http.whiteboard.filter.dispatcher",
			new String[] { "REQUEST", "INCLUDE", "FORWARD", "ASYNC", "ERROR" });
	servRegShiroFilter = context.registerService(Filter.class, new ShiroFilter(), shiroFilterProps);
}
 
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:24,代码来源:ShiroActivator.java


示例9: onStartup

import javax.servlet.ServletContextListener; //导入依赖的package包/类
@Override
public void onStartup(ServletContext webappContext) throws ServletException {
	
	ModuleDataExtractor extractor = new ModuleDataExtractor(module);
	environment.assureModule(module);
	String fullRestResource = "/" + module.getContext() + "/*";

	ServerData serverData = new ServerData(environment.getModuleBean(module).getPort(), 
			Arrays.asList(),
			rootContext, fullRestResource, module);
	List<FilterData> filterDataList = extractor.createFilteredDataList(serverData);
	List<ServletData> servletDataList = extractor.createServletDataList(serverData);
	new ServletConfigurer(serverData, LinkedListX.fromIterable(servletDataList)).addServlets(webappContext);

	new FilterConfigurer(serverData, LinkedListX.fromIterable(filterDataList)).addFilters(webappContext);
	PersistentList<ServletContextListener> servletContextListenerData = LinkedListX.fromIterable(module.getListeners(serverData)).filter(i->!(i instanceof ContextLoader));
    PersistentList<ServletRequestListener> servletRequestListenerData =	LinkedListX.fromIterable(module.getRequestListeners(serverData));
	
	new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData).addListeners(webappContext);
	
}
 
开发者ID:aol,项目名称:micro-server,代码行数:22,代码来源:BootFrontEndApplicationConfigurator.java


示例10: getListeners

import javax.servlet.ServletContextListener; //导入依赖的package包/类
default List<ServletContextListener> getListeners(ServerData data) {
    List<ServletContextListener> list = new ArrayList<>();
    if (data.getRootContext() instanceof WebApplicationContext) {
        list.add(new ContextLoaderListener(
                                           (WebApplicationContext) data.getRootContext()));
    }

    ListX<Plugin> modules = PluginLoader.INSTANCE.plugins.get();

    ListX<ServletContextListener> listeners = modules.stream()
                                                       .filter(module -> module.servletContextListeners() != null)
                                                       .flatMapI(Plugin::servletContextListeners)
                                                       .map(fn -> fn.apply(data))
                                                       .to().listX();

    return listeners.plusAll(list);
}
 
开发者ID:aol,项目名称:micro-server,代码行数:18,代码来源:Module.java


示例11: addListeners

import javax.servlet.ServletContextListener; //导入依赖的package包/类
public void addListeners(ServletContext webappContext) {

	serverData.getRootContext()
			.getBeansOfType(ServletContextListener.class)
			.values()
			
			.stream()
			
			.peek(this::logListener)
			.forEach(listener -> webappContext.addListener(listener));
	listenerData.forEach(it -> webappContext.addListener(it));

	serverData.getRootContext()
			.getBeansOfType(ServletRequestListener.class)
			.values()
			.stream()
			.peek(this::logListener)
			.forEach(listener -> webappContext.addListener(listener));
	listenerRequestData.forEach(it -> webappContext.addListener(it));

}
 
开发者ID:aol,项目名称:micro-server,代码行数:22,代码来源:ServletContextListenerConfigurer.java


示例12: startServer

import javax.servlet.ServletContextListener; //导入依赖的package包/类
@Override
protected void startServer(int port, final Action<ServerHttpExchange> requestAction) throws
  Exception {
  server = new Server();
  ServerConnector connector = new ServerConnector(server);
  connector.setPort(port);
  server.addConnector(connector);
  ServletContextHandler handler = new ServletContextHandler();
  handler.addEventListener(new ServletContextListener() {
    @Override
    public void contextInitialized(ServletContextEvent event) {
      ServletContext context = event.getServletContext();
      Servlet servlet = new AsityServlet().onhttp(requestAction);
      ServletRegistration.Dynamic reg = context.addServlet(AsityServlet.class.getName(), servlet);
      reg.setAsyncSupported(true);
      reg.addMapping(TEST_URI);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
    }
  });
  server.setHandler(handler);
  server.start();
}
 
开发者ID:cettia,项目名称:asity,代码行数:26,代码来源:ServletServerHttpExchangeTest.java


示例13: testServletContextListener

import javax.servlet.ServletContextListener; //导入依赖的package包/类
private void testServletContextListener(ServletContext servletContext) throws Exception {
    ResteasyAutoConfiguration resteasyAutoConfiguration = new ResteasyAutoConfiguration();
    BeanFactoryPostProcessor beanFactoryPostProcessor = ResteasyAutoConfiguration.springBeanProcessor();
    ServletContextListener servletContextListener = resteasyAutoConfiguration.resteasyBootstrapListener(beanFactoryPostProcessor);
    Assert.assertNotNull(servletContextListener);

    ServletContextEvent sce = new ServletContextEvent(servletContext);
    servletContextListener.contextInitialized(sce);

    ResteasyProviderFactory servletContextProviderFactory = (ResteasyProviderFactory) servletContext.getAttribute(ResteasyProviderFactory.class.getName());
    Dispatcher servletContextDispatcher = (Dispatcher) servletContext.getAttribute(Dispatcher.class.getName());
    Registry servletContextRegistry = (Registry) servletContext.getAttribute(Registry.class.getName());

    Assert.assertNotNull(servletContextProviderFactory);
    Assert.assertNotNull(servletContextDispatcher);
    Assert.assertNotNull(servletContextRegistry);

    // Exercising fully cobertura branch coverage
    servletContextListener.contextDestroyed(sce);
    ServletContextListener servletContextListener2 = resteasyAutoConfiguration.resteasyBootstrapListener(beanFactoryPostProcessor);
    servletContextListener2.contextDestroyed(sce);
}
 
开发者ID:paypal,项目名称:resteasy-spring-boot,代码行数:23,代码来源:ResteasyAutoConfigurationTest.java


示例14: init

import javax.servlet.ServletContextListener; //导入依赖的package包/类
/**
 * Init method called by the main servlet when the wrapping servlet is initialized. This means that the context is
 * taken into service by the system.
 *
 * @param parent The parent servlet context. Just for some delegation actions
 */
void init(ServletContext parent) {
    // Set up the tracking of event listeners.
    BundleContext bc = getOwner().getBundleContext();
    delegate = parent;
    Collection<Class<? extends EventListener>> toTrack = Arrays.asList(HttpSessionListener.class,
            ServletRequestListener.class, HttpSessionAttributeListener.class, ServletRequestAttributeListener.class,
            ServletContextListener.class);
    Collection<String> objectFilters = toTrack.stream().
            map((c) -> "(" + Constants.OBJECTCLASS + "=" + c.getName() + ")").collect(Collectors.toList());
    String filterString = "|" + String.join("", objectFilters);
    eventListenerTracker = startTracking(filterString,
            new Tracker<EventListener, EventListener>(bc, getContextPath(), (e) -> e, (e) -> { /* No destruct */}));
    // Initialize the servlets.
    ServletContextEvent event = new ServletContextEvent(this);
    call(ServletContextListener.class, (l) -> l.contextInitialized(event));
    servlets.values().forEach((s) -> init(s));
    // And the filters.
    filters.values().forEach((f) -> init(f));
    // Set up the tracking of servlets and filters.
    servletTracker = startTracking(Constants.OBJECTCLASS + "=" + Servlet.class.getName(),
            new Tracker<Servlet, String>(bc, getContextPath(), this::addServlet, this::removeServlet));
    filterTracker = startTracking(Constants.OBJECTCLASS + "=" + Filter.class.getName(),
            new Tracker<Filter, String>(bc, getContextPath(), this::addFilter, this::removeFilter));
}
 
开发者ID:arievanwi,项目名称:osgi.ee,代码行数:31,代码来源:OurServletContext.java


示例15: startServer

import javax.servlet.ServletContextListener; //导入依赖的package包/类
@Override
protected void startServer() throws Exception {
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.addConnector(connector);
    ServletContextHandler handler = new ServletContextHandler();
    handler.addEventListener(new ServletContextListener() {
        @Override
        public void contextInitialized(ServletContextEvent event) {
            ServletContext context = event.getServletContext();
            Servlet servlet = new VibeAtmosphereServlet().onhttp(performer.serverAction());
            ServletRegistration.Dynamic reg = context.addServlet(VibeAtmosphereServlet.class.getName(), servlet);
            reg.setAsyncSupported(true);
            reg.setInitParameter(ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTOR, Boolean.TRUE.toString());
            reg.addMapping("/test");
        }

        @Override
        public void contextDestroyed(ServletContextEvent sce) {}
    });
    server.setHandler(handler);
    server.start();
}
 
开发者ID:vibe-project,项目名称:vibe-java-platform,代码行数:25,代码来源:AtmosphereServerHttpExchangeTest.java


示例16: startServer

import javax.servlet.ServletContextListener; //导入依赖的package包/类
@Override
protected void startServer() throws Exception {
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.addConnector(connector);
    ServletContextHandler handler = new ServletContextHandler();
    handler.addEventListener(new ServletContextListener() {
        @Override
        public void contextInitialized(ServletContextEvent event) {
            ServletContext context = event.getServletContext();
            Servlet servlet = new VibeAtmosphereServlet().onwebsocket(performer.serverAction());
            ServletRegistration.Dynamic reg = context.addServlet(VibeAtmosphereServlet.class.getName(), servlet);
            reg.setAsyncSupported(true);
            reg.setInitParameter(ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTOR, Boolean.TRUE.toString());
            reg.addMapping("/test");
        }

        @Override
        public void contextDestroyed(ServletContextEvent sce) {}
    });
    server.setHandler(handler);
    server.start();
}
 
开发者ID:vibe-project,项目名称:vibe-java-platform,代码行数:25,代码来源:AtmosphereServerWebSocketTest.java


示例17: startServer

import javax.servlet.ServletContextListener; //导入依赖的package包/类
@Override
protected void startServer() throws Exception {
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.addConnector(connector);
    ServletContextHandler handler = new ServletContextHandler();
    handler.addEventListener(new ServletContextListener() {
        @Override
        public void contextInitialized(ServletContextEvent event) {
            ServletContext context = event.getServletContext();
            Servlet servlet = new VibeServlet().onhttp(performer.serverAction());
            ServletRegistration.Dynamic reg = context.addServlet(VibeServlet.class.getName(), servlet);
            reg.setAsyncSupported(true);
            reg.addMapping("/test");
        }

        @Override
        public void contextDestroyed(ServletContextEvent sce) {}
    });
    server.setHandler(handler);
    server.start();
}
 
开发者ID:vibe-project,项目名称:vibe-java-platform,代码行数:24,代码来源:ServletServerHttpExchangeTest.java


示例18: isWeb

import javax.servlet.ServletContextListener; //导入依赖的package包/类
private static boolean isWeb(final Class<?> beanClass) {
    if (Servlet.class.isAssignableFrom(beanClass)
        || Filter.class.isAssignableFrom(beanClass)) {
        return true;
    }
    if (EventListener.class.isAssignableFrom(beanClass)) {
        return HttpSessionAttributeListener.class.isAssignableFrom(beanClass)
               || ServletContextListener.class.isAssignableFrom(beanClass)
               || ServletRequestListener.class.isAssignableFrom(beanClass)
               || ServletContextAttributeListener.class.isAssignableFrom(beanClass)
               || HttpSessionListener.class.isAssignableFrom(beanClass)
               || HttpSessionBindingListener.class.isAssignableFrom(beanClass)
               || HttpSessionActivationListener.class.isAssignableFrom(beanClass)
               || HttpSessionIdListener.class.isAssignableFrom(beanClass)
               || ServletRequestAttributeListener.class.isAssignableFrom(beanClass);
    }

    return false;
}
 
开发者ID:apache,项目名称:tomee,代码行数:20,代码来源:WebContext.java


示例19: addListener

import javax.servlet.ServletContextListener; //导入依赖的package包/类
@Override
public <T extends EventListener> void addListener(T t) {
    if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
        throw new IllegalStateException(
                sm.getString("applicationContext.addListener.ise",
                        getContextPath()));
    }

    boolean match = false;
    if (t instanceof ServletContextAttributeListener ||
            t instanceof ServletRequestListener ||
            t instanceof ServletRequestAttributeListener ||
            t instanceof HttpSessionAttributeListener) {
        context.addApplicationEventListener(t);
        match = true;
    }

    if (t instanceof HttpSessionListener
            || (t instanceof ServletContextListener &&
                    newServletContextListenerAllowed)) {
        // Add listener directly to the list of instances rather than to
        // the list of class names.
        context.addApplicationLifecycleListener(t);
        match = true;
    }

    if (match) return;

    if (t instanceof ServletContextListener) {
        throw new IllegalArgumentException(sm.getString(
                "applicationContext.addListener.iae.sclNotAllowed",
                t.getClass().getName()));
    } else {
        throw new IllegalArgumentException(sm.getString(
                "applicationContext.addListener.iae.wrongType",
                t.getClass().getName()));
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:39,代码来源:ApplicationContext.java


示例20: contextDestroyed

import javax.servlet.ServletContextListener; //导入依赖的package包/类
public void contextDestroyed(ServletContextEvent sce) {
    if (ctx == null) {
        logger.warn("cannot find applicationContext");

        return;
    }

    Collection<ServletContextListener> servletContextListeners = ctx
            .getBeansOfType(ServletContextListener.class).values();

    for (ServletContextListener servletContextListener : servletContextListeners) {
        servletContextListener.contextDestroyed(sce);
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:15,代码来源:ProxyServletListener.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java XMLReader类代码示例发布时间:2022-05-20
下一篇:
Java HttpParams类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap