本文整理汇总了Java中javax.servlet.http.HttpSessionIdListener类的典型用法代码示例。如果您正苦于以下问题:Java HttpSessionIdListener类的具体用法?Java HttpSessionIdListener怎么用?Java HttpSessionIdListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpSessionIdListener类属于javax.servlet.http包,在下文中一共展示了HttpSessionIdListener类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAddListener
import javax.servlet.http.HttpSessionIdListener; //导入依赖的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);
}
}
}
示例2: isWeb
import javax.servlet.http.HttpSessionIdListener; //导入依赖的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;
}
示例3: sessionIdChanged
import javax.servlet.http.HttpSessionIdListener; //导入依赖的package包/类
@Override
public void sessionIdChanged(RepositoryBackedSession session, String oldId) {
// Session id change is only supported for Servlet 3.1+
if (!ServletLevel.isServlet31) {
return;
}
if (session instanceof HttpSession) {
HttpSessionEvent event = new HttpSessionEvent((HttpSession)session);
for (EventListener listener : descriptor.getHttpSessionIdListeners()) {
((HttpSessionIdListener)listener).sessionIdChanged(event, oldId);
}
}
}
示例4: testOnAddListener
import javax.servlet.http.HttpSessionIdListener; //导入依赖的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));
}
示例5: callSessionIdListeners
import javax.servlet.http.HttpSessionIdListener; //导入依赖的package包/类
/**
* Call any session id listeners registered.
* Usually done by renewSessionId() method, but that is not used in appengine.
* @param session
* @param oldId
*/
public void callSessionIdListeners (AbstractSession session, String oldId) {
HttpSessionEvent event = new HttpSessionEvent(session);
for (HttpSessionIdListener l:_sessionIdListeners)
{
l.sessionIdChanged(event, oldId);
}
}
示例6: httpSessionIdChanged
import javax.servlet.http.HttpSessionIdListener; //导入依赖的package包/类
public void httpSessionIdChanged(final HttpSession session, final String oldSessionId) {
final HttpSessionEvent sre = new HttpSessionEvent(session);
for (int i = 0; i < httpSessionIdListeners.length; ++i) {
this.<HttpSessionIdListener>get(httpSessionIdListeners[i]).sessionIdChanged(sre, oldSessionId);
}
}
示例7: getHttpSessionIdListener
import javax.servlet.http.HttpSessionIdListener; //导入依赖的package包/类
HttpSessionIdListener getHttpSessionIdListener() {
return this.sessionIdListener;
}
示例8: initHttpSessionIdListener
import javax.servlet.http.HttpSessionIdListener; //导入依赖的package包/类
private void initHttpSessionIdListener(EventListener listener) {
if (listener instanceof HttpSessionIdListener) {
this.sessionIdListener = (HttpSessionIdListener) listener;
}
}