當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。