Search in sources :

Example 1 with ListenerInfo

use of io.undertow.servlet.api.ListenerInfo in project wildfly by wildfly.

the class UndertowContext method addSessionListener.

@Override
public void addSessionListener(HttpSessionListener listener) {
    ManagedListener ml = new ManagedListener(new ListenerInfo(HttpSessionListener.class, new ImmediateInstanceFactory<>(listener)), true);
    try {
        ml.start();
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    this.deployment.getApplicationListeners().addListener(ml);
}
Also used : ServletException(javax.servlet.ServletException) ListenerInfo(io.undertow.servlet.api.ListenerInfo) HttpSessionListener(javax.servlet.http.HttpSessionListener) ManagedListener(io.undertow.servlet.core.ManagedListener) ImmediateInstanceFactory(io.undertow.servlet.util.ImmediateInstanceFactory)

Example 2 with ListenerInfo

use of io.undertow.servlet.api.ListenerInfo in project nutzboot by nutzam.

the class UndertowStarter method addEventListener.

public void addEventListener(WebEventListenerFace webEventListener) {
    if (webEventListener.getEventListener() == null) {
        return;
    }
    EventListener et = webEventListener.getEventListener();
    log.debugf("add listener %s", et.getClass());
    ImmediateInstanceFactory<EventListener> factory = new ImmediateInstanceFactory<EventListener>(et);
    ListenerInfo listener = new ListenerInfo(et.getClass(), factory);
    deployment.addListener(listener);
}
Also used : ListenerInfo(io.undertow.servlet.api.ListenerInfo) EventListener(java.util.EventListener) ImmediateInstanceFactory(io.undertow.servlet.util.ImmediateInstanceFactory)

Example 3 with ListenerInfo

use of io.undertow.servlet.api.ListenerInfo in project indy by Commonjava.

the class DeploymentInfoUtils method merge.

public static void merge(final DeploymentInfo into, final DeploymentInfo from) {
    final Map<String, AuthenticationMechanismFactory> authMechs = from.getAuthenticationMechanisms();
    if (authMechs != null) {
        for (final Map.Entry<String, AuthenticationMechanismFactory> entry : authMechs.entrySet()) {
            logger.debug("Found authentication mechanism: {}", entry.getKey());
            into.addAuthenticationMechanism(entry.getKey(), entry.getValue());
        }
    }
    if (from.getAuthorizationManager() != null) {
        logger.debug("Found authorization manager: {}", from.getAuthorizationManager());
        into.setAuthorizationManager(from.getAuthorizationManager());
    }
    if (from.getConfidentialPortManager() != null) {
        logger.debug("Found confidential port manager: {}", from.getConfidentialPortManager());
        into.setConfidentialPortManager(from.getConfidentialPortManager());
    }
    final List<ErrorPage> errorPages = from.getErrorPages();
    if (errorPages != null) {
        logger.debug("Found error pages: {}", errorPages);
        into.addErrorPages(errorPages);
    }
    if (from.getExceptionHandler() != null) {
        logger.debug("Found exception handler: {}", from.getExceptionHandler());
        into.setExceptionHandler(from.getExceptionHandler());
    }
    final List<FilterMappingInfo> filterMappings = from.getFilterMappings();
    if (filterMappings != null) {
        for (final FilterMappingInfo fmi : filterMappings) {
            switch(fmi.getMappingType()) {
                case SERVLET:
                    {
                        logger.debug("Found servlet-name filter mapping: {} -> {}({})", fmi.getFilterName(), fmi.getMapping(), fmi.getDispatcher());
                        into.addFilterServletNameMapping(fmi.getFilterName(), fmi.getMapping(), fmi.getDispatcher());
                        break;
                    }
                default:
                    {
                        logger.debug("Found URL filter mapping: {} -> {}({})", fmi.getFilterName(), fmi.getMapping(), fmi.getDispatcher());
                        into.addFilterUrlMapping(fmi.getFilterName(), fmi.getMapping(), fmi.getDispatcher());
                    }
            }
        }
    }
    final Map<String, FilterInfo> filterInfos = from.getFilters();
    if (filterInfos != null) {
        logger.debug("Found filters: {}", filterInfos.keySet());
        into.addFilters(filterInfos.values());
    }
    if (from.getIdentityManager() != null) {
        logger.debug("Found identity manager: {}", from.getIdentityManager());
        into.setIdentityManager(from.getIdentityManager());
    }
    final Map<String, String> initParameters = from.getInitParameters();
    if (initParameters != null) {
        for (final Map.Entry<String, String> entry : initParameters.entrySet()) {
            logger.debug("Init-Param: {} = {} from: {}", entry.getKey(), entry.getValue(), from);
            into.addInitParameter(entry.getKey(), entry.getValue());
        }
    }
    final List<LifecycleInterceptor> lifecycleInterceptors = from.getLifecycleInterceptors();
    if (lifecycleInterceptors != null) {
        for (final LifecycleInterceptor lifecycleInterceptor : lifecycleInterceptors) {
            logger.debug("Found lifecycle interceptor: {}", lifecycleInterceptor);
            into.addLifecycleInterceptor(lifecycleInterceptor);
        }
    }
    final List<ListenerInfo> listeners = from.getListeners();
    if (listeners != null) {
        logger.debug("Found listeners: {}", listeners.stream().map(li -> li.getListenerClass().getName()).collect(Collectors.toList()));
        into.addListeners(listeners);
    }
    if (from.getMetricsCollector() != null) {
        logger.debug("Found metrics collector: {}", from.getMetricsCollector());
        into.setMetricsCollector(from.getMetricsCollector());
    }
    final List<MimeMapping> mimeMappings = from.getMimeMappings();
    if (mimeMappings != null) {
        logger.debug("Found mime mappings: {}", mimeMappings.stream().map(mm -> mm.getMimeType() + " -> " + mm.getExtension()).collect(Collectors.toList()));
        into.addMimeMappings(mimeMappings);
    }
    final List<NotificationReceiver> notificationReceivers = from.getNotificationReceivers();
    if (notificationReceivers != null) {
        logger.debug("Found notification receivers: {}", notificationReceivers);
        into.addNotificationReceivers(notificationReceivers);
    }
    final Map<String, Set<String>> principalVersusRolesMap = from.getPrincipalVersusRolesMap();
    if (principalVersusRolesMap != null) {
        for (final Map.Entry<String, Set<String>> entry : principalVersusRolesMap.entrySet()) {
            logger.debug("Found principle-roles mapping: {} -> {}", entry.getKey(), entry.getValue());
            into.addPrincipalVsRoleMappings(entry.getKey(), entry.getValue());
        }
    }
    final List<SecurityConstraint> securityConstraints = from.getSecurityConstraints();
    if (securityConstraints != null) {
        if (logger.isDebugEnabled()) {
            for (final SecurityConstraint sc : securityConstraints) {
                logger.debug("Security Constraint: {} from: {}", sc, from);
            }
        }
        into.addSecurityConstraints(securityConstraints);
    }
    final LoginConfig loginConfig = from.getLoginConfig();
    if (loginConfig != null) {
        logger.debug("Login Config with realm: {} and mechanism: {} from: {}", loginConfig.getRealmName(), loginConfig.getAuthMethods(), from);
        if (into.getLoginConfig() != null) {
            throw new IllegalStateException("Two or more deployment providers are attempting to provide login configurations! Enable debug logging to see more.");
        }
        into.setLoginConfig(loginConfig);
    }
    if (from.getSecurityContextFactory() != null) {
        logger.debug("Found security context factory: {}", from.getSecurityContextFactory());
        into.setSecurityContextFactory(from.getSecurityContextFactory());
    }
    final Set<String> securityRoles = from.getSecurityRoles();
    if (securityRoles != null) {
        logger.debug("Found security roles: {}", securityRoles);
        into.addSecurityRoles(securityRoles);
    }
    final List<ServletContainerInitializerInfo> servletContainerInitializers = from.getServletContainerInitializers();
    if (servletContainerInitializers != null) {
        logger.debug("Found servlet container initializers: {}", servletContainerInitializers.stream().map(sci -> sci.getServletContainerInitializerClass().getName()).collect(Collectors.toList()));
        into.addServletContainerInitalizers(servletContainerInitializers);
    }
    final Map<String, Object> servletContextAttributes = from.getServletContextAttributes();
    if (servletContextAttributes != null) {
        for (final Map.Entry<String, Object> entry : servletContextAttributes.entrySet()) {
            logger.debug("Found servlet context attribute: {} -> {}", entry.getKey(), entry.getValue());
            into.addServletContextAttribute(entry.getKey(), entry.getValue());
        }
    }
    final List<ServletExtension> servletExtensions = from.getServletExtensions();
    if (servletExtensions != null) {
        for (final ServletExtension servletExtension : servletExtensions) {
            logger.debug("Found servlet extension: {}", servletExtension);
            into.addServletExtension(servletExtension);
        }
    }
    final Map<String, ServletInfo> servletInfos = from.getServlets();
    if (servletInfos != null) {
        logger.debug("Found servlets: {}", servletInfos.values().stream().map(si -> si.getName() + " => " + si.getMappings()).collect(Collectors.toList()));
        into.addServlets(servletInfos.values());
    }
    final List<SessionListener> sessionListeners = from.getSessionListeners();
    if (sessionListeners != null) {
        for (final SessionListener sessionListener : sessionListeners) {
            logger.debug("Found session listener: {}", sessionListener);
            into.addSessionListener(sessionListener);
        }
    }
    if (from.getSessionManagerFactory() != null) {
        logger.debug("Found session manager factory: {}", from.getSessionManagerFactory());
        into.setSessionManagerFactory(from.getSessionManagerFactory());
    }
    if (from.getSessionPersistenceManager() != null) {
        logger.debug("Found session persistence manager: {}", from.getSessionPersistenceManager());
        into.setSessionPersistenceManager(from.getSessionPersistenceManager());
    }
    if (from.getTempDir() != null) {
        logger.debug("Found temp dir: {}", from.getTempDir());
        into.setTempDir(from.getTempDir());
    }
    final List<String> welcomePages = from.getWelcomePages();
    if (welcomePages != null) {
        logger.debug("Found welcome pages: {}", welcomePages);
        into.addWelcomePages(welcomePages);
    }
    final List<HandlerWrapper> initWrappers = from.getInitialHandlerChainWrappers();
    if (initWrappers != null) {
        for (final HandlerWrapper wrapper : initWrappers) {
            logger.debug("Found initial handler chain wrapper: {}", wrapper);
            into.addInitialHandlerChainWrapper(wrapper);
        }
    }
    final List<HandlerWrapper> outerWrappers = from.getOuterHandlerChainWrappers();
    if (outerWrappers != null) {
        for (final HandlerWrapper wrapper : outerWrappers) {
            logger.debug("Found outer handler chain wrapper: {}", wrapper);
            into.addOuterHandlerChainWrapper(wrapper);
        }
    }
    final List<HandlerWrapper> innerWrappers = from.getInnerHandlerChainWrappers();
    if (innerWrappers != null) {
        for (final HandlerWrapper wrapper : innerWrappers) {
            logger.debug("Found inner handler chain wrapper: {}", wrapper);
            into.addInnerHandlerChainWrapper(wrapper);
        }
    }
}
Also used : ErrorPage(io.undertow.servlet.api.ErrorPage) FilterMappingInfo(io.undertow.servlet.api.FilterMappingInfo) Set(java.util.Set) HandlerWrapper(io.undertow.server.HandlerWrapper) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) LifecycleInterceptor(io.undertow.servlet.api.LifecycleInterceptor) ServletInfo(io.undertow.servlet.api.ServletInfo) LoginConfig(io.undertow.servlet.api.LoginConfig) FilterInfo(io.undertow.servlet.api.FilterInfo) MimeMapping(io.undertow.servlet.api.MimeMapping) ServletContainerInitializerInfo(io.undertow.servlet.api.ServletContainerInitializerInfo) ListenerInfo(io.undertow.servlet.api.ListenerInfo) NotificationReceiver(io.undertow.security.api.NotificationReceiver) SessionListener(io.undertow.server.session.SessionListener) AuthenticationMechanismFactory(io.undertow.security.api.AuthenticationMechanismFactory) Map(java.util.Map) ServletExtension(io.undertow.servlet.ServletExtension)

Example 4 with ListenerInfo

use of io.undertow.servlet.api.ListenerInfo in project undertow by undertow-io.

the class RequestListenerAsyncRequestTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo m = new ServletInfo("messageServlet", MessageServlet.class).addInitParam(MessageServlet.MESSAGE, HELLO_WORLD).setAsyncSupported(true).addMapping("/message");
    ServletInfo a = new ServletInfo("asyncServlet", AsyncServlet.class).addInitParam(MessageServlet.MESSAGE, HELLO_WORLD).setAsyncSupported(true).addMapping("/async");
    ServletInfo comp = new ServletInfo("completeAsyncServlet", CompleteAsyncServlet.class).addInitParam(MessageServlet.MESSAGE, HELLO_WORLD).setAsyncSupported(true).addMapping("/asynccomplete");
    ServletInfo a2 = new ServletInfo("asyncServlet2", AnotherAsyncServlet.class).setAsyncSupported(true).addMapping("/async2");
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlets(m, a, a2, comp).addListener(new ListenerInfo(TestListener.class));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ListenerInfo(io.undertow.servlet.api.ListenerInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) TestListener(io.undertow.servlet.test.util.TestListener) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) MessageServlet(io.undertow.servlet.test.util.MessageServlet) BeforeClass(org.junit.BeforeClass)

Example 5 with ListenerInfo

use of io.undertow.servlet.api.ListenerInfo in project undertow by undertow-io.

the class ServletContextListenerTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServletContainerInitializer(new ServletContainerInitializerInfo(TestSci.class, Collections.<Class<?>>emptySet())).addServlet(new ServletInfo("servlet", MessageServlet.class).addMapping("/aa")).addListener(new ListenerInfo(ServletContextTestListener.class));
    manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ServletContainerInitializerInfo(io.undertow.servlet.api.ServletContainerInitializerInfo) ListenerInfo(io.undertow.servlet.api.ListenerInfo) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) BeforeClass(org.junit.BeforeClass) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) MessageServlet(io.undertow.servlet.test.util.MessageServlet) BeforeClass(org.junit.BeforeClass)

Aggregations

ListenerInfo (io.undertow.servlet.api.ListenerInfo)23 ServletInfo (io.undertow.servlet.api.ServletInfo)14 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)12 PathHandler (io.undertow.server.handlers.PathHandler)10 ServletContainer (io.undertow.servlet.api.ServletContainer)10 BeforeClass (org.junit.BeforeClass)9 DeploymentManager (io.undertow.servlet.api.DeploymentManager)8 ServletException (javax.servlet.ServletException)8 ManagedListener (io.undertow.servlet.core.ManagedListener)6 ImmediateInstanceFactory (io.undertow.servlet.util.ImmediateInstanceFactory)6 EventListener (java.util.EventListener)5 FilterInfo (io.undertow.servlet.api.FilterInfo)4 HandlerWrapper (io.undertow.server.HandlerWrapper)3 ErrorPage (io.undertow.servlet.api.ErrorPage)3 LoginConfig (io.undertow.servlet.api.LoginConfig)3 MimeMapping (io.undertow.servlet.api.MimeMapping)3 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)3 ServletContainerInitializerInfo (io.undertow.servlet.api.ServletContainerInitializerInfo)3 MessageServlet (io.undertow.servlet.test.util.MessageServlet)3 ServletContextListener (javax.servlet.ServletContextListener)3