Search in sources :

Example 6 with ManagedListener

use of io.undertow.servlet.core.ManagedListener in project undertow by undertow-io.

the class ServletContextImpl method addListener.

@Override
public void addListener(final Class<? extends EventListener> listenerClass) {
    ensureNotInitialized();
    ensureNotProgramaticListener();
    if (ApplicationListeners.listenerState() != NO_LISTENER && ServletContextListener.class.isAssignableFrom(listenerClass)) {
        throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener();
    }
    final DeploymentInfo deploymentInfo = getDeploymentInfo();
    InstanceFactory<? extends EventListener> factory = null;
    try {
        factory = deploymentInfo.getClassIntrospecter().createInstanceFactory(listenerClass);
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    final ListenerInfo listener = new ListenerInfo(listenerClass, factory);
    deploymentInfo.addListener(listener);
    deployment.getApplicationListeners().addListener(new ManagedListener(listener, true));
}
Also used : ListenerInfo(io.undertow.servlet.api.ListenerInfo) ServletContextListener(javax.servlet.ServletContextListener) ManagedListener(io.undertow.servlet.core.ManagedListener) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ServletException(javax.servlet.ServletException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

ListenerInfo (io.undertow.servlet.api.ListenerInfo)6 ManagedListener (io.undertow.servlet.core.ManagedListener)6 ServletException (javax.servlet.ServletException)5 ImmediateInstanceFactory (io.undertow.servlet.util.ImmediateInstanceFactory)4 ServletContextListener (javax.servlet.ServletContextListener)2 ServletRequestListener (javax.servlet.ServletRequestListener)2 HttpSessionListener (javax.servlet.http.HttpSessionListener)2 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 EventListener (java.util.EventListener)1 ServletRequestEvent (javax.servlet.ServletRequestEvent)1 HttpSessionEvent (javax.servlet.http.HttpSessionEvent)1