Search in sources :

Example 1 with EventListener

use of java.util.EventListener in project jetty.project by eclipse.

the class WebListenerAnnotation method apply.

/**
     * @see DiscoveredAnnotation#apply()
     */
public void apply() {
    Class<? extends java.util.EventListener> clazz = (Class<? extends EventListener>) getTargetClass();
    if (clazz == null) {
        LOG.warn(_className + " cannot be loaded");
        return;
    }
    try {
        if (ServletContextListener.class.isAssignableFrom(clazz) || ServletContextAttributeListener.class.isAssignableFrom(clazz) || ServletRequestListener.class.isAssignableFrom(clazz) || ServletRequestAttributeListener.class.isAssignableFrom(clazz) || HttpSessionListener.class.isAssignableFrom(clazz) || HttpSessionAttributeListener.class.isAssignableFrom(clazz) || HttpSessionIdListener.class.isAssignableFrom(clazz)) {
            java.util.EventListener listener = (java.util.EventListener) _context.getServletContext().createInstance(clazz);
            MetaData metaData = _context.getMetaData();
            if (metaData.getOrigin(clazz.getName() + ".listener") == Origin.NotSet) {
                ListenerHolder h = _context.getServletHandler().newListenerHolder(new Source(Source.Origin.ANNOTATION, clazz.getName()));
                h.setListener(listener);
                _context.getServletHandler().addListener(h);
                _context.addEventListener(listener);
            }
        } else
            LOG.warn(clazz.getName() + " does not implement one of the servlet listener interfaces");
    } catch (Exception e) {
        LOG.warn(e);
    }
}
Also used : HttpSessionListener(javax.servlet.http.HttpSessionListener) ServletRequestListener(javax.servlet.ServletRequestListener) ListenerHolder(org.eclipse.jetty.servlet.ListenerHolder) Source(org.eclipse.jetty.servlet.Source) EventListener(java.util.EventListener) MetaData(org.eclipse.jetty.webapp.MetaData) EventListener(java.util.EventListener) HttpSessionIdListener(javax.servlet.http.HttpSessionIdListener)

Example 2 with EventListener

use of java.util.EventListener in project jetty.project by eclipse.

the class StandardDescriptorProcessor method visitListener.

public void visitListener(WebAppContext context, Descriptor descriptor, XmlParser.Node node) {
    String className = node.getString("listener-class", false, true);
    EventListener listener = null;
    try {
        if (className != null && className.length() > 0) {
            //Servlet Spec 3.0 p 74
            //Duplicate listener declarations don't result in duplicate listener instances
            EventListener[] listeners = context.getEventListeners();
            if (listeners != null) {
                for (EventListener l : listeners) {
                    if (l.getClass().getName().equals(className))
                        return;
                }
            }
            ((WebDescriptor) descriptor).addClassName(className);
            Class<? extends EventListener> listenerClass = (Class<? extends EventListener>) context.loadClass(className);
            listener = newListenerInstance(context, listenerClass, descriptor);
            if (!(listener instanceof EventListener)) {
                LOG.warn("Not an EventListener: " + listener);
                return;
            }
            context.addEventListener(listener);
            context.getMetaData().setOrigin(className + ".listener", descriptor);
        }
    } catch (Exception e) {
        LOG.warn("Could not instantiate listener " + className, e);
        return;
    }
}
Also used : EventListener(java.util.EventListener) ServletException(javax.servlet.ServletException)

Example 3 with EventListener

use of java.util.EventListener in project jetty.project by eclipse.

the class SessionHandler method clearEventListeners.

/* ------------------------------------------------------------ */
/**
     * Removes all event listeners for session-related events.
     *
     * @see #removeEventListener(EventListener)
     */
public void clearEventListeners() {
    for (EventListener e : getBeans(EventListener.class)) removeBean(e);
    _sessionAttributeListeners.clear();
    _sessionListeners.clear();
    _sessionIdListeners.clear();
}
Also used : EventListener(java.util.EventListener)

Example 4 with EventListener

use of java.util.EventListener in project spring-boot by spring-projects.

the class ServletListenerRegistrationBeanTests method cannotRegisterUnsupportedType.

@Test
public void cannotRegisterUnsupportedType() throws Exception {
    this.thrown.expect(IllegalArgumentException.class);
    this.thrown.expectMessage("Listener is not of a supported type");
    new ServletListenerRegistrationBean<EventListener>(new EventListener() {
    });
}
Also used : EventListener(java.util.EventListener) Test(org.junit.Test)

Example 5 with EventListener

use of java.util.EventListener in project robovm by robovm.

the class OldEventListenerProxyTest method testGetListener.

public void testGetListener() {
    EventListener el = new Mock_EventListener();
    EventListenerProxy elp = new Mock_EventListenerProxy(el);
    assertSame(el, elp.getListener());
}
Also used : EventListenerProxy(java.util.EventListenerProxy) EventListener(java.util.EventListener)

Aggregations

EventListener (java.util.EventListener)70 Test (org.junit.Test)11 ListenerInfo (io.undertow.servlet.api.ListenerInfo)5 ServletRequestListener (javax.servlet.ServletRequestListener)4 HashMap (java.util.HashMap)3 ServletContextListener (javax.servlet.ServletContextListener)3 HttpSessionListener (javax.servlet.http.HttpSessionListener)3 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3 EventListenerList (org.eclipse.scout.rt.platform.util.EventListenerList)3 Bundle (org.osgi.framework.Bundle)3 BundleContext (org.osgi.framework.BundleContext)3 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 EventObject (java.util.EventObject)2 List (java.util.List)2 NamingException (javax.naming.NamingException)2 ServletRequestEvent (javax.servlet.ServletRequestEvent)2 HttpSessionIdListener (javax.servlet.http.HttpSessionIdListener)2 Connector (org.eclipse.jetty.server.Connector)2