javax.servlet.annotation.WebListener Java Examples

The following examples show how to use javax.servlet.annotation.WebListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationScanInitializer.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Is this a web annotation.
 *
 * @param annotation the annotation.
 * @return true if it is, false otherwise.
 */
private boolean isWebAnnotation(Annotation annotation) {
    return annotation instanceof WebServlet
            || annotation instanceof WebListener
            || annotation instanceof WebInitParam
            || annotation instanceof WebFilter
            || annotation instanceof ServletSecurity
            || annotation instanceof MultipartConfig;
}
 
Example #2
Source File: ServerCmdlet.java    From HongsCORE with MIT License 5 votes vote down vote up
@Override
public void init(ServletContextHandler context) {
    String pkgx  = CoreConfig.getInstance("defines"   )
                             .getProperty("apply.serv");
    if  (  pkgx != null ) {
        String[]   pkgs = pkgx.split(";");
        for(String pkgn : pkgs) {
            pkgn = pkgn.trim  ( );
            if  (  pkgn.length( ) == 0  ) {
                continue;
            }

            Set<String> clss = getClss(pkgn);
            for(String  clsn : clss) {
                Class   clso = getClso(clsn);

                WebFilter   wf = (WebFilter  ) clso.getAnnotation(WebFilter.class  );
                if (null != wf) {
                    addFilter  (context, clso, wf);
                }

                WebServlet  wb = (WebServlet ) clso.getAnnotation(WebServlet.class );
                if (null != wb) {
                    addServlet (context, clso, wb);
                }

                WebListener wl = (WebListener) clso.getAnnotation(WebListener.class);
                if (null != wl) {
                    addListener(context, clso, wl);
                }
            }
        }
    }
}
 
Example #3
Source File: WebServletPlugin.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Collection<ClasspathScanRequest> classpathScanRequests() {
    return classpathScanRequestBuilder()
            .annotationType(WebFilter.class)
            .annotationType(WebServlet.class)
            .annotationType(WebListener.class)
            .build();
}
 
Example #4
Source File: WebServletPlugin.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public InitState initialize(InitContext initContext) {
    if (servletContext != null) {
        listenerDefinitions.addAll(
                detectListeners(initContext.scannedClassesByAnnotationClass().get(WebListener.class)));
        filterDefinitions.addAll(detectFilters(initContext.scannedClassesByAnnotationClass().get(WebFilter.class)));
        servletDefinitions.addAll(
                detectServlets(initContext.scannedClassesByAnnotationClass().get(WebServlet.class)));
    }

    return InitState.INITIALIZED;
}
 
Example #5
Source File: WebAnnotationInitializer.java    From piranha with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Class<? extends EventListener> getTargetListener(AnnotationInfo<WebListener> annotationInfo) {
    return (Class<? extends EventListener>) annotationInfo.getTargetType();
}
 
Example #6
Source File: MeecrowaveContextConfig.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
@Override
protected void webConfig() {
    if (context.getServletContext().getAttribute("meecrowave.configuration") == null) { // redeploy
        context.getServletContext().setAttribute("meecrowave.configuration",
                Meecrowave.Builder.class.isInstance(configuration) ? configuration : new Meecrowave.Builder(configuration));
        context.addServletContainerInitializer(intializer, emptySet());
    }

    if (!configuration.isTomcatScanning()) {
        super.webConfig();
        return;
    }

    // eagerly start CDI to scan only once and not twice (tomcat+CDI)
    final ClassLoader loader = context.getLoader().getClassLoader(); // should already be started at that point
    final Thread thread = Thread.currentThread();
    final ClassLoader old = thread.getContextClassLoader();
    thread.setContextClassLoader(loader);
    try {
        final OWBTomcatWebScannerService scannerService = OWBTomcatWebScannerService.class.cast(WebBeansContext.getInstance().getScannerService());
        scannerService.setFilter(ofNullable(context.getJarScanner()).map(JarScanner::getJarScanFilter).orElse(null), context.getServletContext());
        scannerService.setDocBase(context.getDocBase());
        scannerService.setShared(configuration.getSharedLibraries());
        if (configuration.getWatcherBouncing() > 0) { // note that caching should be disabled with this config in most of the times
            watcher = new ReloadOnChangeController(context, configuration.getWatcherBouncing());
            scannerService.setFileVisitor(f -> watcher.register(f));
        }
        scannerService.scan();
        finder = scannerService.getFinder();
        finder.link();
        final CdiArchive archive = CdiArchive.class.cast(finder.getArchive());
        Stream.of(WebServlet.class, WebFilter.class, WebListener.class)
                .forEach(marker -> finder.findAnnotatedClasses(marker).stream()
                        .filter(c -> !Modifier.isAbstract(c.getModifiers()) && Modifier.isPublic(c.getModifiers()))
                        .forEach(webComponent -> webClasses.computeIfAbsent(
                                archive.classesByUrl().entrySet().stream()
                                        .filter(e -> e.getValue().getClassNames().contains(webComponent.getName()))
                                        .findFirst().get().getKey(), k -> new HashSet<>())
                                .add(webComponent)));
    } finally {
        thread.setContextClassLoader(old);
    }
    try {
        super.webConfig();
    } finally {
        webClasses.clear();
        finder = null;
    }
}
 
Example #7
Source File: WebListenerInstaller.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
@Override
public boolean matches(final Class<?> type) {
    return FeatureUtils.is(type, EventListener.class)
            && FeatureUtils.hasAnnotation(type, WebListener.class)
            && hasMatch(type, SUPPORTED);
}
 
Example #8
Source File: WebServerExtension.java    From hammock with Apache License 2.0 4 votes vote down vote up
public void findListeners(@Observes @WithAnnotations({WebListener.class})
                          ProcessAnnotatedType<? extends ServletContextListener> pat) {
    listeners.add(pat.getAnnotatedType().getJavaClass());
}