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


Java ServletRequestListener类代码示例

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


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

示例1: onStartup

import javax.servlet.ServletRequestListener; //导入依赖的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

示例2: addListeners

import javax.servlet.ServletRequestListener; //导入依赖的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

示例3: init

import javax.servlet.ServletRequestListener; //导入依赖的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

示例4: destroy

import javax.servlet.ServletRequestListener; //导入依赖的package包/类
public void destroy() {
    final boolean openejbRequestDestroyed = getAttribute("openejb_requestDestroyed") == null;
    if (listeners != null && !listeners.isEmpty()) {
        if (begin != null && end != null && openejbRequestDestroyed) {
            end.requestDestroyed(new ServletRequestEvent(getServletContext(), this));
        }
        final ServletRequestEvent event = new ServletRequestEvent(getServletContext(), this);
        for (final ServletRequestListener listener : listeners) {
            listener.requestDestroyed(event);
        }
    }
    if (begin != null && openejbRequestDestroyed) {
        setAttribute("openejb_requestDestroyed", "ok");
        begin.requestDestroyed(new ServletRequestEvent(getServletContext(), this));
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:17,代码来源:HttpRequestImpl.java

示例5: isWeb

import javax.servlet.ServletRequestListener; //导入依赖的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

示例6: addListener

import javax.servlet.ServletRequestListener; //导入依赖的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

示例7: fireRequestInitEvent

import javax.servlet.ServletRequestListener; //导入依赖的package包/类
@Override
public boolean fireRequestInitEvent(ServletRequest request) {

    Object instances[] = getApplicationEventListeners();

    if ((instances != null) && (instances.length > 0)) {

        ServletRequestEvent event = 
                new ServletRequestEvent(getServletContext(), request);

        for (int i = 0; i < instances.length; i++) {
            if (instances[i] == null)
                continue;
            if (!(instances[i] instanceof ServletRequestListener))
                continue;
            ServletRequestListener listener =
                (ServletRequestListener) instances[i];
            
            try {
                listener.requestInitialized(event);
            } catch (Throwable t) {
                ExceptionUtils.handleThrowable(t);
                getLogger().error(sm.getString(
                        "standardContext.requestListener.requestInit",
                        instances[i].getClass().getName()), t);
                request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:33,代码来源:StandardContext.java

示例8: fireRequestDestroyEvent

import javax.servlet.ServletRequestListener; //导入依赖的package包/类
@Override
public boolean fireRequestDestroyEvent(ServletRequest request) {
    Object instances[] = getApplicationEventListeners();

    if ((instances != null) && (instances.length > 0)) {

        ServletRequestEvent event = 
            new ServletRequestEvent(getServletContext(), request);

        for (int i = 0; i < instances.length; i++) {
            int j = (instances.length -1) -i;
            if (instances[j] == null)
                continue;
            if (!(instances[j] instanceof ServletRequestListener))
                continue;
            ServletRequestListener listener =
                (ServletRequestListener) instances[j];
            
            try {
                listener.requestDestroyed(event);
            } catch (Throwable t) {
                ExceptionUtils.handleThrowable(t);
                getLogger().error(sm.getString(
                        "standardContext.requestListener.requestInit",
                        instances[j].getClass().getName()), t);
                request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:33,代码来源:StandardContext.java

示例9: requestDestroyed

import javax.servlet.ServletRequestListener; //导入依赖的package包/类
public void requestDestroyed(final ServletRequest request) {
    final ServletRequestEvent sre = new ServletRequestEvent(servletContext, request);
    for (int i = servletRequestListeners.length - 1; i >= 0; --i) {
        ManagedListener listener = servletRequestListeners[i];
        try {
            this.<ServletRequestListener>get(listener).requestDestroyed(sre);
        } catch (Exception e) {
            UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("requestDestroyed", listener.getListenerInfo().getListenerClass(), e);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:ApplicationListeners.java

示例10: addListener

import javax.servlet.ServletRequestListener; //导入依赖的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:how2j,项目名称:lazycat,代码行数:33,代码来源:ApplicationContext.java

示例11: fireRequestInitEvent

import javax.servlet.ServletRequestListener; //导入依赖的package包/类
@Override
public boolean fireRequestInitEvent(ServletRequest request) {

	Object instances[] = getApplicationEventListeners();

	if ((instances != null) && (instances.length > 0)) {

		ServletRequestEvent event = new ServletRequestEvent(getServletContext(), request);

		for (int i = 0; i < instances.length; i++) {
			if (instances[i] == null)
				continue;
			if (!(instances[i] instanceof ServletRequestListener))
				continue;
			ServletRequestListener listener = (ServletRequestListener) instances[i];

			try {
				listener.requestInitialized(event);
			} catch (Throwable t) {
				ExceptionUtils.handleThrowable(t);
				getLogger().error(sm.getString("standardContext.requestListener.requestInit",
						instances[i].getClass().getName()), t);
				request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
				return false;
			}
		}
	}
	return true;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:30,代码来源:StandardContext.java

示例12: fireRequestDestroyEvent

import javax.servlet.ServletRequestListener; //导入依赖的package包/类
@Override
public boolean fireRequestDestroyEvent(ServletRequest request) {
	Object instances[] = getApplicationEventListeners();

	if ((instances != null) && (instances.length > 0)) {

		ServletRequestEvent event = new ServletRequestEvent(getServletContext(), request);

		for (int i = 0; i < instances.length; i++) {
			int j = (instances.length - 1) - i;
			if (instances[j] == null)
				continue;
			if (!(instances[j] instanceof ServletRequestListener))
				continue;
			ServletRequestListener listener = (ServletRequestListener) instances[j];

			try {
				listener.requestDestroyed(event);
			} catch (Throwable t) {
				ExceptionUtils.handleThrowable(t);
				getLogger().error(sm.getString("standardContext.requestListener.requestInit",
						instances[j].getClass().getName()), t);
				request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
				return false;
			}
		}
	}
	return true;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:30,代码来源:StandardContext.java

示例13: loadListeners

import javax.servlet.ServletRequestListener; //导入依赖的package包/类
private void loadListeners(WebAppConfiguration wac)
    throws ClassNotFoundException, IllegalAccessException,
    InstantiationException, WebAppConfigurationException {
  for (WebAppListener listener : wac.getListeners()) {
    String className = listener.getListenerClass();
    Class<?> clazz = classLoader.loadClass(className);
    Object obj = clazz.newInstance();
    boolean used = false;
    if (obj instanceof ServletContextAttributeListener) {
      scaListeners.add((ServletContextAttributeListener) obj);
      used = true;
    }
    if (obj instanceof ServletContextListener) {
      scListeners.add((ServletContextListener) obj);
      used = true;
    }
    if (obj instanceof ServletRequestListener) {
      srListeners.add((ServletRequestListener) obj);
      used = true;
    }
    if (obj instanceof ServletRequestAttributeListener) {
      sraListeners.add((ServletRequestAttributeListener) obj);
      used = true;
    }
    if (obj instanceof HttpSessionAttributeListener) {
      sessionAttributeListeners.add((HttpSessionAttributeListener) obj);
      used = true;
    }
    if (obj instanceof HttpSessionListener) {
      sessionListeners.add((HttpSessionListener) obj);
      used = true;
    }
    if (!used) {
      throw new WebAppConfigurationException("Don't know what to do with '"
          + className + "'");
    }
  }
}
 
开发者ID:bboypscmylife,项目名称:opengse,代码行数:39,代码来源:WebAppImpl.java

示例14: testContributeListeners_ServletRequestListener

import javax.servlet.ServletRequestListener; //导入依赖的package包/类
@Test
public void testContributeListeners_ServletRequestListener() throws Exception {

    ServletRequestListener srListener = mock(ServletRequestListener.class);

    startApp(b -> JettyModule.extend(b).addListener(srListener));

    verify(srListener, times(0)).requestInitialized(any());
    verify(srListener, times(0)).requestDestroyed(any());

    WebTarget base = ClientBuilder.newClient().target("http://localhost:8080");

    base.path("/a").request().get();
    Thread.sleep(100);
    verify(srListener, times(1)).requestInitialized(any());
    verify(srListener, times(1)).requestDestroyed(any());

    base.path("/b").request().get();
    Thread.sleep(100);
    verify(srListener, times(2)).requestInitialized(any());
    verify(srListener, times(2)).requestDestroyed(any());

    // not_found request
    base.path("/c").request().get();
    Thread.sleep(100);
    verify(srListener, times(3)).requestInitialized(any());
    verify(srListener, times(3)).requestDestroyed(any());
}
 
开发者ID:bootique,项目名称:bootique-jetty,代码行数:29,代码来源:JettyModuleIT.java

示例15: getRequestListeners

import javax.servlet.ServletRequestListener; //导入依赖的package包/类
default List<ServletRequestListener> getRequestListeners(ServerData data) {

        return PluginLoader.INSTANCE.plugins.get()
                                            .stream()
                                            .filter(module -> module.servletRequestListeners() != null)
                                            .flatMapI(Plugin::servletRequestListeners)
                                            .map(fn -> fn.apply(data))
                                             .to().listX();

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


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