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


Java HttpSessionAttributeListener类代码示例

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


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

示例1: onAddListener

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的package包/类
/**
 * This method is used by injected code to register listeners for
 * {@link ServletContext}. If object argument is a {@link ServletContext} and
 * listener argument contains {@link HttpSessionListener} or
 * {@link HttpSessionAttributeListener}, the method will add them to list of
 * known listeners associated to {@link ServletContext}
 *
 * @param servletContext
 *          the active servlet context
 * @param listener
 *          the listener to use
 */
public void onAddListener(ServletContext servletContext, Object listener) {
  String contextPath = servletContext.getContextPath();
  ServletContextDescriptor scd = getDescriptor(servletContext);
  logger.debug("Registering listener {} for context {}", listener, contextPath);
  // As theoretically one class can implement many listener interfaces we
  // check if it implements each of supported ones
  if (listener instanceof HttpSessionListener) {
    scd.addHttpSessionListener((HttpSessionListener)listener);
  }
  if (listener instanceof HttpSessionAttributeListener) {
    scd.addHttpSessionAttributeListener((HttpSessionAttributeListener)listener);
  }
  if (ServletLevel.isServlet31) {
    // Guard the code inside block to avoid use of classes
    // that are not available in versions before Servlet 3.1
    if (listener instanceof HttpSessionIdListener) { // NOSONAR
      scd.addHttpSessionIdListener((HttpSessionIdListener)listener);
    }
  }
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:33,代码来源:SessionHelpers.java

示例2: init

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

示例3: setAttribute

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的package包/类
@Override
public void setAttribute(String name, Object value) {
    // According to the specifications, a value of null should be handled as a remove.
    if (value == null) {
        removeAttribute(name);
        return;
    }
    checkValid();
    // See how to notify our listeners: as a replacement or an addition.
    BiConsumer<HttpSessionAttributeListener, HttpSessionBindingEvent> notifier = (l, e) -> l.attributeAdded(e);
    if (unbindOriginal(name)) {
        notifier = (l, e) -> l.attributeReplaced(e);
    }
    // Update the data.
    attributes.put(name, value);
    // And perform the notification.
    notifyListeners(name, value, notifier);
}
 
开发者ID:arievanwi,项目名称:osgi.ee,代码行数:19,代码来源:OurSession.java

示例4: notifyListeners

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的package包/类
private void notifyListeners(String name, Object oldValue, Object value) {
    if (listeners != null) {
	HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, name, value);
	HttpSessionBindingEvent oldEvent = oldValue == null ? null : new HttpSessionBindingEvent(this, name,
		oldValue);
	for (int i = 0, n = listeners.size(); i < n; i++)
	    try {
		HttpSessionAttributeListener l = (HttpSessionAttributeListener) listeners.get(i);
		if (oldEvent != null)
		    l.attributeReplaced(oldEvent);
		l.attributeAdded(event);
	    } catch (ClassCastException cce) {
	    } catch (NullPointerException npe) {
	    }
    }
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-listener,代码行数:17,代码来源:Serve.java

示例5: isWeb

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的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.http.HttpSessionAttributeListener; //导入依赖的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: addListener

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

示例8: attributeAdded

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的package包/类
/**
 * Notifies listeners that attribute was added. See {@link SessionNotifier}
 * {@link #attributeAdded(RepositoryBackedSession, String, Object)}.
 * <p>
 * If the added attribute <code>value</code> is a HttpSessionBindingListener,
 * it will receive the {@link HttpSessionBindingEvent}. If there are
 * {@link HttpSessionAttributeListener} instances associated to
 * {@link ServletContext}, they will be notified via
 * {@link HttpSessionAttributeListener#attributeAdded(HttpSessionBindingEvent)}
 * .
 */
@Override
public void attributeAdded(RepositoryBackedSession session, String key, Object value) {
  // If the
  if (session instanceof HttpSession && value instanceof HttpSessionBindingListener) {
    ((HttpSessionBindingListener)value).valueBound(new HttpSessionBindingEvent((HttpSession)session, key));
  }
  HttpSessionBindingEvent event = new HttpSessionBindingEvent((HttpSession)session, key, value);
  for (HttpSessionAttributeListener listener : descriptor.getHttpSessionAttributeListeners()) {
    listener.attributeAdded(event);
  }
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:23,代码来源:HttpSessionNotifier.java

示例9: testOnAddListener

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的package包/类
@Test
public void testOnAddListener() {
  ServletContextDescriptor scd = new ServletContextDescriptor(servletContext);
  when(servletContext.getAttribute(Attributes.SERVLET_CONTEXT_DESCRIPTOR)).thenReturn(scd);
  sessionHelpers.onAddListener(servletContext, "Dummy");
  assertTrue(scd.getHttpSessionListeners().isEmpty());
  assertTrue(scd.getHttpSessionIdListeners().isEmpty());
  assertTrue(scd.getHttpSessionAttributeListeners().isEmpty());
  HttpSessionListener listener = mock(HttpSessionListener.class);
  HttpSessionIdListener idListener = mock(HttpSessionIdListener.class);
  HttpSessionAttributeListener attributeListener = mock(HttpSessionAttributeListener.class);
  HttpSessionListener multiListener = mock(HttpSessionListener.class,
      withSettings().extraInterfaces(HttpSessionAttributeListener.class));
  HttpSessionAttributeListener attributeMultiListener = (HttpSessionAttributeListener)multiListener;
  sessionHelpers.onAddListener(servletContext, listener);
  assertThat(scd.getHttpSessionListeners(), hasItem(listener));
  assertTrue(scd.getHttpSessionIdListeners().isEmpty());
  assertTrue(scd.getHttpSessionAttributeListeners().isEmpty());
  sessionHelpers.onAddListener(servletContext, idListener);
  assertThat(scd.getHttpSessionListeners(), hasItem(listener));
  assertThat(scd.getHttpSessionIdListeners(), hasItem(idListener));
  assertTrue(scd.getHttpSessionAttributeListeners().isEmpty());
  sessionHelpers.onAddListener(servletContext, attributeListener);
  assertThat(scd.getHttpSessionListeners(), hasItem(listener));
  assertThat(scd.getHttpSessionIdListeners(), hasItem(idListener));
  assertThat(scd.getHttpSessionAttributeListeners(), hasItem(attributeListener));
  sessionHelpers.onAddListener(servletContext, multiListener);
  assertThat(scd.getHttpSessionListeners(), hasItem(listener));
  assertThat(scd.getHttpSessionListeners(), hasItem(multiListener));
  assertThat(scd.getHttpSessionIdListeners(), hasItem(idListener));
  assertThat(scd.getHttpSessionAttributeListeners(), hasItem(attributeListener));
  assertThat(scd.getHttpSessionAttributeListeners(), hasItem(attributeMultiListener));
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:34,代码来源:TestSessionHelpers.java

示例10: testAttributeAdded

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的package包/类
@Test
public void testAttributeAdded() {
  HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class);
  descriptor.addHttpSessionAttributeListener(listener);
  notifier.attributeAdded(session, "Test", "value");
  verify(listener).attributeAdded(any(HttpSessionBindingEvent.class));
  HttpSessionBindingListener bindingListener = mock(HttpSessionBindingListener.class);
  notifier.attributeAdded(session, "Test", bindingListener);
  verify(listener, times(2)).attributeAdded(any(HttpSessionBindingEvent.class));
  verify(bindingListener).valueBound(any(HttpSessionBindingEvent.class));
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:12,代码来源:TestHttpSessionNotifier.java

示例11: testAttributeReplaced

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的package包/类
@Test
public void testAttributeReplaced() {
  HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class);
  notifier.attributeReplaced(session, "Test", "very-old-value");
  verify(listener, never()).attributeReplaced(any(HttpSessionBindingEvent.class));
  descriptor.addHttpSessionAttributeListener(listener);
  notifier.attributeReplaced(session, "Test", "old-value");
  verify(listener).attributeReplaced(any(HttpSessionBindingEvent.class));
  HttpSessionBindingListener bindingListener = mock(HttpSessionBindingListener.class);
  notifier.attributeReplaced(session, "Test", bindingListener);
  verify(listener, times(2)).attributeReplaced(any(HttpSessionBindingEvent.class));
  verify(bindingListener).valueUnbound(any(HttpSessionBindingEvent.class));
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:14,代码来源:TestHttpSessionNotifier.java

示例12: testAttributeRemoved

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的package包/类
@Test
public void testAttributeRemoved() {
  notifier.attributeRemoved(session, "Test", "very-old-value");
  HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class);
  descriptor.addHttpSessionAttributeListener(listener);
  notifier.attributeRemoved(session, "Test", "old-value");
  verify(listener).attributeRemoved(any(HttpSessionBindingEvent.class));
  HttpSessionBindingListener bindingListener = mock(HttpSessionBindingListener.class);
  notifier.attributeRemoved(session, "Test", bindingListener);
  verify(listener, times(2)).attributeRemoved(any(HttpSessionBindingEvent.class));
  verify(bindingListener).valueUnbound(any(HttpSessionBindingEvent.class));
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:13,代码来源:TestHttpSessionNotifier.java

示例13: sessionDidActivate

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的package包/类
public void sessionDidActivate(HttpSessionEvent se) {
	for (EventListener listener: PluginWebInstanceRepository.getListeners()) {
		if (listener instanceof HttpSessionAttributeListener) {
			((HttpSessionActivationListener) listener).sessionDidActivate(se);
		}
	}
}
 
开发者ID:balancebeam,项目名称:puzzle,代码行数:8,代码来源:PluginHookListener.java

示例14: attributeAdded

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的package包/类
public void attributeAdded(HttpSessionBindingEvent se) {
	for (EventListener listener: PluginWebInstanceRepository.getListeners()) {
		if (listener instanceof HttpSessionAttributeListener) {
			((HttpSessionAttributeListener) listener).attributeAdded(se);
		}
	}
}
 
开发者ID:balancebeam,项目名称:puzzle,代码行数:8,代码来源:PluginHookListener.java

示例15: attributeRemoved

import javax.servlet.http.HttpSessionAttributeListener; //导入依赖的package包/类
public void attributeRemoved(HttpSessionBindingEvent se) {
	for (EventListener listener: PluginWebInstanceRepository.getListeners()) {
		if (listener instanceof HttpSessionAttributeListener) {
			((HttpSessionAttributeListener) listener).attributeRemoved(se);
		}
	}
}
 
开发者ID:balancebeam,项目名称:puzzle,代码行数:8,代码来源:PluginHookListener.java


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