Java 类javax.servlet.http.HttpSessionListener 实例源码
项目:lemon
文件:SessionEventHttpSessionListenerAdapter.java
public void onApplicationEvent(AbstractSessionEvent event) {
if (this.listeners.isEmpty()) {
return;
}
HttpSessionEvent httpSessionEvent = createHttpSessionEvent(event);
for (HttpSessionListener listener : this.listeners) {
if (event instanceof SessionDestroyedEvent) {
listener.sessionDestroyed(httpSessionEvent);
}
else if (event instanceof SessionCreatedEvent) {
listener.sessionCreated(httpSessionEvent);
}
}
}
项目:Equella
文件:UserSessionDestructionListener.java
@SuppressWarnings("nls")
private synchronized List<HttpSessionListener> getListeners()
{
if( listenerTracker == null )
{
PluginService pluginService = AbstractPluginService.get();
if( pluginService == null )
{
// We're not initialised yet, probably because Tomcat is trying
// to tell us about a bunch of existing sessions from other
// cluster nodes while we're still starting up.
return Collections.emptyList();
}
listenerTracker = new PluginTracker<HttpSessionListener>(pluginService, "com.tle.web.core",
"webSessionListener", null, new PluginTracker.ExtensionParamComparator("order")).setBeanKey("bean");
}
return listenerTracker.getBeanList();
}
项目:HttpSessionReplacer
文件:SessionHelpers.java
/**
* 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);
}
}
}
项目:kc-rice
文件:BootstrapListener.java
private void addListener(String name, String classname) {
LOG.debug("Adding listener: " + name + "=" + classname);
Object listenerObject = GlobalResourceLoader.getResourceLoader().getObject(new ObjectDefinition(classname));
if (listenerObject == null) {
LOG.error("Listener '" + name + "' class not found: " + classname);
return;
}
if (!(listenerObject instanceof HttpSessionListener)) {
LOG.error("Class '" + listenerObject.getClass() + "' does not implement servlet javax.servlet.http.HttpSessionListener");
return;
}
HttpSessionListener listener = (HttpSessionListener) listenerObject;
listeners.put(name, listener);
}
项目:nano-framework
文件:AbstractSessionManager.java
@Override
public final void removeSession(final AbstractSession session, boolean invalidate) {
final String clusterId = getClusterId(session);
final boolean removed = removeSession(clusterId);
if (removed) {
_sessionsStats.decrement();
_sessionTimeStats.set(Math.round((System.currentTimeMillis() - session.getCreationTime()) / 1000.0));
_sessionIdManager.removeSession(session);
if (invalidate) {
_sessionIdManager.invalidateAll(session.getClusterId());
}
if (invalidate && _sessionListeners != null) {
final HttpSessionEvent event = new HttpSessionEvent(session);
for (int i = LazyList.size(_sessionListeners); i-- > 0;) {
((HttpSessionListener) LazyList.get(_sessionListeners, i)).sessionDestroyed(event);
}
}
if (!invalidate) {
session.willPassivate();
}
}
}
项目:osgi.ee
文件:OurServletContext.java
/**
* 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));
}
项目:spring-session
文件:SessionEventHttpSessionListenerAdapter.java
@Override
public void onApplicationEvent(AbstractSessionEvent event) {
if (this.listeners.isEmpty()) {
return;
}
HttpSessionEvent httpSessionEvent = createHttpSessionEvent(event);
for (HttpSessionListener listener : this.listeners) {
if (event instanceof SessionDestroyedEvent) {
listener.sessionDestroyed(httpSessionEvent);
}
else if (event instanceof SessionCreatedEvent) {
listener.sessionCreated(httpSessionEvent);
}
}
}
项目:jsmart-web
文件:SessionControl.java
@Override
public void sessionCreated(HttpSessionEvent event) {
HttpSession session = event.getSession();
synchronized (session) {
session.setAttribute(Constants.SESSION_RESET_ATTR, "#");
HANDLER.instantiateAuthBean(session);
if (CONFIG.getContent().getSessionTimeout() > 0) {
session.setMaxInactiveInterval(CONFIG.getContent().getSessionTimeout() * 60);
}
for (HttpSessionListener sessionListener : HANDLER.sessionListeners) {
HANDLER.executeInjection(sessionListener);
sessionListener.sessionCreated(event);
}
}
}
项目:rice
文件:BootstrapListener.java
private void addListener(String name, String classname) {
LOG.debug("Adding listener: " + name + "=" + classname);
Object listenerObject = GlobalResourceLoader.getResourceLoader().getObject(new ObjectDefinition(classname));
if (listenerObject == null) {
LOG.error("Listener '" + name + "' class not found: " + classname);
return;
}
if (!(listenerObject instanceof HttpSessionListener)) {
LOG.error("Class '" + listenerObject.getClass() + "' does not implement servlet javax.servlet.http.HttpSessionListener");
return;
}
HttpSessionListener listener = (HttpSessionListener) listenerObject;
listeners.put(name, listener);
}
项目:couchbase-lite-java-listener
文件:Serve.java
public synchronized void setListeners(List l) {
if (listeners == null) {
listeners = l;
if (listeners != null) {
HttpSessionEvent event = new HttpSessionEvent(this);
for (int i = 0; i < listeners.size(); i++)
try {
((HttpSessionListener) listeners.get(i)).sessionCreated(event);
} catch (ClassCastException cce) {
//servletContext. log("Wrong session listener type."+cce);
} catch (NullPointerException npe) {
//servletContext. log("Null session listener.");
}
}
}
}
项目:tomee
文件:WebContext.java
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;
}
项目:kuali_rice
文件:BootstrapListener.java
private void addListener(String name, String classname) {
LOG.debug("Adding listener: " + name + "=" + classname);
Object listenerObject = GlobalResourceLoader.getResourceLoader().getObject(new ObjectDefinition(classname));
if (listenerObject == null) {
LOG.error("Listener '" + name + "' class not found: " + classname);
return;
}
if (!(listenerObject instanceof HttpSessionListener)) {
LOG.error("Class '" + listenerObject.getClass() + "' does not implement servlet javax.servlet.http.HttpSessionListener");
return;
}
HttpSessionListener listener = (HttpSessionListener) listenerObject;
listeners.put(name, listener);
}
项目:tomcat7
文件:StandardSession.java
/**
* Inform the listeners about the new session.
*
*/
public void tellNew() {
// Notify interested session event listeners
fireSessionEvent(Session.SESSION_CREATED_EVENT, null);
// Notify interested application event listeners
Context context = (Context) manager.getContainer();
Object listeners[] = context.getApplicationLifecycleListeners();
if (listeners != null) {
HttpSessionEvent event =
new HttpSessionEvent(getSession());
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof HttpSessionListener))
continue;
HttpSessionListener listener =
(HttpSessionListener) listeners[i];
try {
context.fireContainerEvent("beforeSessionCreated",
listener);
listener.sessionCreated(event);
context.fireContainerEvent("afterSessionCreated", listener);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
try {
context.fireContainerEvent("afterSessionCreated",
listener);
} catch (Exception e) {
// Ignore
}
manager.getContainer().getLogger().error
(sm.getString("standardSession.sessionEvent"), t);
}
}
}
}
项目:tomcat7
文件:ApplicationContext.java
@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()));
}
}
项目:lemon
文件:ProxyServletListener.java
public void sessionCreated(HttpSessionEvent se) {
if (ctx == null) {
logger.warn("cannot find applicationContext");
return;
}
Collection<HttpSessionListener> httpSessionListeners = ctx
.getBeansOfType(HttpSessionListener.class).values();
for (HttpSessionListener httpSessionListener : httpSessionListeners) {
httpSessionListener.sessionCreated(se);
}
}
项目:lemon
文件:ProxyServletListener.java
public void sessionDestroyed(HttpSessionEvent se) {
if (ctx == null) {
logger.warn("cannot find applicationContext");
return;
}
Collection<HttpSessionListener> httpSessionListeners = ctx
.getBeansOfType(HttpSessionListener.class).values();
for (HttpSessionListener httpSessionListener : httpSessionListeners) {
httpSessionListener.sessionDestroyed(se);
}
}
项目:Equella
文件:UserSessionDestructionListener.java
@Override
public void sessionCreated(HttpSessionEvent event)
{
for( HttpSessionListener listener : getListeners() )
{
listener.sessionCreated(event);
}
}
项目:Equella
文件:UserSessionDestructionListener.java
@Override
public void sessionDestroyed(HttpSessionEvent event)
{
for( HttpSessionListener listener : getListeners() )
{
listener.sessionDestroyed(event);
}
}
项目:lams
文件:StandardSession.java
/**
* Inform the listeners about the new session.
*
*/
public void tellNew() {
// Notify interested session event listeners
fireSessionEvent(Session.SESSION_CREATED_EVENT, null);
// Notify interested application event listeners
Context context = (Context) manager.getContainer();
Object listeners[] = context.getApplicationLifecycleListeners();
if (listeners != null) {
HttpSessionEvent event =
new HttpSessionEvent(getSession());
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof HttpSessionListener))
continue;
HttpSessionListener listener =
(HttpSessionListener) listeners[i];
try {
fireContainerEvent(context,
"beforeSessionCreated",
listener);
listener.sessionCreated(event);
fireContainerEvent(context,
"afterSessionCreated",
listener);
} catch (Throwable t) {
try {
fireContainerEvent(context,
"afterSessionCreated",
listener);
} catch (Exception e) {
;
}
manager.getContainer().getLogger().error
(sm.getString("standardSession.sessionEvent"), t);
}
}
}
}
项目:lams
文件:ApplicationListeners.java
public void sessionDestroyed(final HttpSession session) {
final HttpSessionEvent sre = new HttpSessionEvent(session);
for (int i = httpSessionListeners.length - 1; i >= 0; --i) {
ManagedListener listener = httpSessionListeners[i];
this.<HttpSessionListener>get(listener).sessionDestroyed(sre);
}
}
项目:apache-tomcat-7.0.73-with-comment
文件:StandardSession.java
/**
* Inform the listeners about the new session.
*
*/
public void tellNew() {
// Notify interested session event listeners
fireSessionEvent(Session.SESSION_CREATED_EVENT, null);
// Notify interested application event listeners
Context context = (Context) manager.getContainer();
Object listeners[] = context.getApplicationLifecycleListeners();
if (listeners != null) {
HttpSessionEvent event =
new HttpSessionEvent(getSession());
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof HttpSessionListener))
continue;
HttpSessionListener listener =
(HttpSessionListener) listeners[i];
try {
context.fireContainerEvent("beforeSessionCreated",
listener);
listener.sessionCreated(event);
context.fireContainerEvent("afterSessionCreated", listener);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
try {
context.fireContainerEvent("afterSessionCreated",
listener);
} catch (Exception e) {
// Ignore
}
manager.getContainer().getLogger().error
(sm.getString("standardSession.sessionEvent"), t);
}
}
}
}
项目:apache-tomcat-7.0.73-with-comment
文件:ApplicationContext.java
@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()));
}
}
项目:lazycat
文件:StandardSession.java
/**
* Inform the listeners about the new session.
*
*/
public void tellNew() {
// Notify interested session event listeners
fireSessionEvent(Session.SESSION_CREATED_EVENT, null);
// Notify interested application event listeners
Context context = (Context) manager.getContainer();
Object listeners[] = context.getApplicationLifecycleListeners();
if (listeners != null) {
HttpSessionEvent event = new HttpSessionEvent(getSession());
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof HttpSessionListener))
continue;
HttpSessionListener listener = (HttpSessionListener) listeners[i];
try {
context.fireContainerEvent("beforeSessionCreated", listener);
listener.sessionCreated(event);
context.fireContainerEvent("afterSessionCreated", listener);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
try {
context.fireContainerEvent("afterSessionCreated", listener);
} catch (Exception e) {
// Ignore
}
manager.getContainer().getLogger().error(sm.getString("standardSession.sessionEvent"), t);
}
}
}
}
项目:lazycat
文件:ApplicationContext.java
@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()));
}
}
项目:HttpSessionReplacer
文件:HttpSessionNotifier.java
@Override
public void sessionCreated(RepositoryBackedSession session) {
if (session instanceof HttpSession) {
HttpSessionEvent event = new HttpSessionEvent((HttpSession)session);
for (HttpSessionListener listener : descriptor.getHttpSessionListeners()) {
listener.sessionCreated(event);
}
}
}
项目:HttpSessionReplacer
文件:TestSessionHelpers.java
@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));
}
项目:HttpSessionReplacer
文件:TestHttpSessionNotifier.java
@Test
public void testSessionCreated() {
HttpSessionListener listener = mock(HttpSessionListener.class);
descriptor.addHttpSessionListener(listener);
notifier.sessionCreated(session);
verify(listener).sessionCreated(any(HttpSessionEvent.class));
HttpSessionListener listener2 = mock(HttpSessionListener.class);
descriptor.addHttpSessionListener(listener2);
notifier.sessionCreated(session);
verify(listener, times(2)).sessionCreated(any(HttpSessionEvent.class));
verify(listener2).sessionCreated(any(HttpSessionEvent.class));
}
项目:HttpSessionReplacer
文件:TestHttpSessionNotifier.java
@Test
public void testSessionDestroyed() {
HttpSessionListener listener = mock(HttpSessionListener.class);
descriptor.addHttpSessionListener(listener);
notifier.sessionDestroyed(session, false);
verify(listener).sessionDestroyed(any(HttpSessionEvent.class));
HttpSessionListener listener2 = mock(HttpSessionListener.class);
descriptor.addHttpSessionListener(listener2);
notifier.sessionDestroyed(session, false);
verify(listener, times(2)).sessionDestroyed(any(HttpSessionEvent.class));
verify(listener2).sessionDestroyed(any(HttpSessionEvent.class));
}
项目:HttpSessionReplacer
文件:TestHttpSessionNotifier.java
@Test
public void testShutdown() {
HttpSessionListener listener = mock(HttpSessionListener.class);
descriptor.addHttpSessionListener(listener);
notifier.sessionDestroyed(session, true);
verify(listener).sessionDestroyed(any(HttpSessionEvent.class));
HttpSessionListener listener2 = mock(HttpSessionListener.class);
descriptor.addHttpSessionListener(listener2);
notifier.sessionDestroyed(session, true);
verify(listener, times(2)).sessionDestroyed(any(HttpSessionEvent.class));
verify(listener2).sessionDestroyed(any(HttpSessionEvent.class));
}
项目:puzzle
文件:PluginHookListener.java
public void sessionCreated(HttpSessionEvent se) {
for (EventListener listener: PluginWebInstanceRepository.getListeners()) {
if (listener instanceof HttpSessionListener) {
((HttpSessionListener) listener).sessionCreated(se);
}
}
}
项目:puzzle
文件:PluginHookListener.java
public void sessionDestroyed(HttpSessionEvent se) {
for (EventListener listener: PluginWebInstanceRepository.getListeners()) {
if (listener instanceof HttpSessionListener) {
((HttpSessionListener) listener).sessionDestroyed(se);
}
}
}
项目:opengse
文件:WebAppImpl.java
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 + "'");
}
}
}
项目:opengse
文件:WebAppSessionWrapper.java
public WebAppSessionWrapper(HttpSession delegate, ServletContext context,
HttpSessionListener sessionListener,
HttpSessionAttributeListener sessionAttributeListener) {
super(delegate);
this.context = context;
this.sessionListener = sessionListener;
this.sessionAttributeListener = sessionAttributeListener;
fireSessionCreated();
}
项目:bootique-jetty
文件:JettyModuleIT.java
@Test
public void testContributeListeners_SessionListener() throws Exception {
// TODO: test session destroy event...
doAnswer(i -> {
HttpServletRequest request = (HttpServletRequest) i.getArgumentAt(0, ServletRequest.class);
request.getSession(true);
return null;
}).when(mockServlet1).service(any(ServletRequest.class), any(ServletResponse.class));
HttpSessionListener sessionListener = mock(HttpSessionListener.class);
startApp(b -> JettyModule.extend(b)
.addServlet(mockServlet1, "s1", "/a/*", "/b/*")
.addListener(sessionListener));
verify(sessionListener, times(0)).sessionCreated(any());
verify(sessionListener, times(0)).sessionDestroyed(any());
WebTarget base = ClientBuilder.newClient().target("http://localhost:8080");
base.path("/a").request().get();
Thread.sleep(100);
verify(sessionListener, times(1)).sessionCreated(any());
verify(sessionListener, times(0)).sessionDestroyed(any());
base.path("/b").request().get();
Thread.sleep(100);
verify(sessionListener, times(2)).sessionCreated(any());
verify(sessionListener, times(0)).sessionDestroyed(any());
// not_found request
base.path("/c").request().get();
Thread.sleep(100);
verify(sessionListener, times(2)).sessionCreated(any());
verify(sessionListener, times(0)).sessionDestroyed(any());
}
项目:bootique-jetty
文件:JettyModuleIT.java
@Test
public void testContributeListeners_SessionListener_SessionsDisabled() throws Exception {
doAnswer(i -> {
HttpServletRequest request = (HttpServletRequest) i.getArgumentAt(0, ServletRequest.class);
try {
request.getSession(true);
} catch (IllegalStateException e) {
// expected, ignoring...
}
return null;
}).when(mockServlet1).service(any(ServletRequest.class), any(ServletResponse.class));
HttpSessionListener sessionListener = mock(HttpSessionListener.class);
startApp(b -> {
JettyModule.extend(b)
.addServlet(mockServlet1, "s1", "/a/*", "/b/*")
.addListener(sessionListener);
BQCoreModule.extend(b).setProperty("bq.jetty.sessions", "false");
});
verify(sessionListener, times(0)).sessionCreated(any());
verify(sessionListener, times(0)).sessionDestroyed(any());
WebTarget base = ClientBuilder.newClient().target("http://localhost:8080");
base.path("/a").request().get();
Thread.sleep(100);
verify(sessionListener, times(0)).sessionCreated(any());
verify(sessionListener, times(0)).sessionDestroyed(any());
}
项目:kc-rice
文件:BootstrapListener.java
/**
* {@inheritDoc}
* @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
*/
public void sessionCreated(final HttpSessionEvent event) {
LOG.debug("Begin BootstrapListener session created...");
init();
for (HttpSessionListener listener : listeners.values()) {
listener.sessionCreated(event);
}
LOG.debug("...end BootstrapListener session created.");
}
项目:kc-rice
文件:BootstrapListener.java
/**
* {@inheritDoc}
* @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
*/
public void sessionDestroyed(final HttpSessionEvent event) {
LOG.debug("Begin BootstrapListener session destroyed...");
init();
for (HttpSessionListener listener : listeners.values()) {
listener.sessionDestroyed(event);
}
LOG.debug("...end BootstrapListener session destroyed.");
}
项目:winstone
文件:WebAppConfiguration.java
private void addListenerInstance(final Object listenerInstance,
final List<ServletContextAttributeListener> contextAttributeListeners,
final List<ServletContextListener> contextListeners,
final List<ServletRequestAttributeListener> requestAttributeListeners,
final List<ServletRequestListener> requestListeners, final List<HttpSessionActivationListener> sessionActivationListeners,
final List<HttpSessionAttributeListener> sessionAttributeListeners, final List<HttpSessionListener> sessionListeners) {
if (listenerInstance instanceof ServletContextAttributeListener) {
contextAttributeListeners.add((ServletContextAttributeListener) listenerInstance);
}
if (listenerInstance instanceof ServletContextListener) {
contextListeners.add((ServletContextListener) listenerInstance);
}
if (listenerInstance instanceof ServletRequestAttributeListener) {
requestAttributeListeners.add((ServletRequestAttributeListener) listenerInstance);
}
if (listenerInstance instanceof ServletRequestListener) {
requestListeners.add((ServletRequestListener) listenerInstance);
}
if (listenerInstance instanceof HttpSessionActivationListener) {
sessionActivationListeners.add((HttpSessionActivationListener) listenerInstance);
}
if (listenerInstance instanceof HttpSessionAttributeListener) {
sessionAttributeListeners.add((HttpSessionAttributeListener) listenerInstance);
}
if (listenerInstance instanceof HttpSessionListener) {
sessionListeners.add((HttpSessionListener) listenerInstance);
}
}
项目:mondo-collab-framework
文件:LensSessionManager.java
public static void initializeHttpSessionListener() {
BundleContext bundleContext = FrameworkUtil.getBundle(HttpServiceServlet.class).getBundleContext();
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, Boolean.TRUE.toString());
properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
"(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)");
bundleContext.registerService(new String[] { HttpSessionListener.class.getName() }, SERVICE_LISTENER,
properties);
}
项目:quick4j-dwsm
文件:AbstractSessionManager.java
private void fireSessionCreatedEvent(HttpSession session){
for (EventListener listener : listeners){
if(listener instanceof HttpSessionListener){
((HttpSessionListener) listener).sessionCreated(new HttpSessionEvent(session));
}
}
}