Example usage for org.springframework.context ApplicationEvent getClass

List of usage examples for org.springframework.context ApplicationEvent getClass

Introduction

In this page you can find the example usage for org.springframework.context ApplicationEvent getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.mule.module.spring.events.TestApplicationEventBean.java

public void onApplicationEvent(ApplicationEvent event) {
    logger.debug("Received Spring event: " + event.getClass().getName());

    if (eventCallback != null) {
        try {/* w w w . ja  v  a2 s .co m*/
            eventCallback.eventReceived(null, event);
        } catch (Exception e1) {
            throw new RuntimeException("Callback failed: " + e1.getMessage(), e1);
        }
    }
}

From source file:org.opennms.web.springframework.security.SecurityAuthenticationEventOnmsEventBuilder.java

/** {@inheritDoc} */
@Override//  w  ww  . jav a 2 s . co m
public void onApplicationEvent(ApplicationEvent event) {
    LOG.debug("Received ApplicationEvent {}", event.getClass());
    if (event instanceof AuthenticationSuccessEvent) {
        AuthenticationSuccessEvent authEvent = (AuthenticationSuccessEvent) event;

        EventBuilder builder = createEvent(SUCCESS_UEI, authEvent);
        // Sync the timestamp
        builder.setTime(new Date(event.getTimestamp()));
        if (!"true".equalsIgnoreCase(System.getProperty("org.opennms.security.disableLoginSuccessEvent"))) {
            sendEvent(builder.getEvent());
        }
    }

    if (event instanceof AbstractAuthenticationFailureEvent) {
        AbstractAuthenticationFailureEvent authEvent = (AbstractAuthenticationFailureEvent) event;

        LOG.debug("AbstractAuthenticationFailureEvent was received, exception message - {}",
                authEvent.getException().getMessage());
        EventBuilder builder = createEvent(FAILURE_UEI, authEvent);
        // Sync the timestamp
        builder.setTime(new Date(event.getTimestamp()));
        builder.addParam("exceptionName", authEvent.getException().getClass().getSimpleName());
        builder.addParam("exceptionMessage", authEvent.getException().getMessage());
        sendEvent(builder.getEvent());
    }

    if (event instanceof AuthorizedEvent) {
        AuthorizedEvent authEvent = (AuthorizedEvent) event;
        LOG.debug("AuthorizedEvent received - \n  Details - {}\n  Principal - {}",
                authEvent.getAuthentication().getDetails(), authEvent.getAuthentication().getPrincipal());
    }
    if (event instanceof AuthorizationFailureEvent) {
        AuthorizationFailureEvent authEvent = (AuthorizationFailureEvent) event;
        LOG.debug("AuthorizationFailureEvent received  -\n   Details - {}\n  Principal - {}",
                authEvent.getAuthentication().getDetails(), authEvent.getAuthentication().getPrincipal());
    }
    if (event instanceof InteractiveAuthenticationSuccessEvent) {
        InteractiveAuthenticationSuccessEvent authEvent = (InteractiveAuthenticationSuccessEvent) event;
        LOG.debug("InteractiveAuthenticationSuccessEvent received - \n  Details - {}\n  Principal - {}",
                authEvent.getAuthentication().getDetails(), authEvent.getAuthentication().getPrincipal());

    }
    if (event instanceof ServletRequestHandledEvent) {
        ServletRequestHandledEvent authEvent = (ServletRequestHandledEvent) event;
        LOG.debug("ServletRequestHandledEvent received - {}\n  Servlet - {}\n  URL - {}",
                authEvent.getDescription(), authEvent.getServletName(), authEvent.getRequestUrl());
        LOG.info("{} requested from {} by user {}", authEvent.getRequestUrl(), authEvent.getClientAddress(),
                authEvent.getUserName());
    }

}

From source file:org.pentaho.platform.engine.security.event.PentahoAuthenticationSuccessListener.java

public void onApplicationEvent(final ApplicationEvent event) {
    if (event instanceof AuthenticationSuccessEvent) {
        logger.debug("received " + event.getClass().getSimpleName()); //$NON-NLS-1$
        logger.debug("synchronizing current IPentahoSession with SecurityContext"); //$NON-NLS-1$
        try {/*from   w w  w.  j a v  a 2 s .  c o  m*/
            Authentication authentication = ((AbstractAuthenticationEvent) event).getAuthentication();
            IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
            Assert.notNull(pentahoSession, "PentahoSessionHolder doesn't have a session");
            pentahoSession.setAuthenticated(authentication.getName());
            pentahoSession.setAttribute(IPentahoSession.SESSION_ROLES, authentication.getAuthorities());
            // audit session creation
            AuditHelper.audit(pentahoSession.getId(), pentahoSession.getName(), pentahoSession.getActionName(),
                    pentahoSession.getObjectName(), "", MessageTypes.SESSION_START, "", "", 0, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        } catch (Exception e) {
            logger.error(e.getLocalizedMessage(), e);
        }
    }
}

From source file:org.springframework.context.event.SimpleApplicationEventMulticaster.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void doInvokeListener(ApplicationListener listener, ApplicationEvent event) {
    try {//from ww  w .  j a  v a 2s .  com
        listener.onApplicationEvent(event);
    } catch (ClassCastException ex) {
        String msg = ex.getMessage();
        if (msg == null || matchesClassCastMessage(msg, event.getClass().getName())) {
            // Possibly a lambda-defined listener which we could not resolve the generic event type for
            // -> let's suppress the exception and just log a debug message.
            Log logger = LogFactory.getLog(getClass());
            if (logger.isDebugEnabled()) {
                logger.debug("Non-matching event type for listener: " + listener, ex);
            }
        } else {
            throw ex;
        }
    }
}

From source file:org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.java

public void onApplicationEvent(ApplicationEvent event) {
    for (ApplicationListener<ApplicationEvent> listener : listeners) {
        try {//from   w  w w .  ja  v a 2s .c  om
            listener.onApplicationEvent(event);
        } catch (ClassCastException e) {
            if (logger.isWarnEnabled() && event != null) {
                logger.warn("ApplicationEvent of type [" + event.getClass()
                        + "] not accepted by ApplicationListener [" + listener + "]");
            }
        }
    }
}

From source file:org.springframework.statemachine.processor.StateMachineAnnotationPostProcessor.java

@Override
public void onApplicationEvent(ApplicationEvent event) {
    for (ApplicationListener<ApplicationEvent> listener : listeners) {
        try {/*from  w ww  .  j av a  2  s.  co m*/
            listener.onApplicationEvent(event);
        } catch (ClassCastException e) {
            if (log.isWarnEnabled() && event != null) {
                log.warn("ApplicationEvent of type [" + event.getClass()
                        + "] not accepted by ApplicationListener [" + listener + "]");
            }
        }
    }
}

From source file:org.webical.plugin.file.PluginCleanupApplicationListener.java

/**
 * Cleans up the plugin work directory on context stop
 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
 *///from www.  j  a  v a  2 s. co  m
public void onApplicationEvent(ApplicationEvent event) {
    try {
        if (event instanceof ContextClosedEvent
                && ApplicationSettingsFactory.getInstance().getApplicationSettings().isPluginCleanupEnabled()) {
            File pluginWorkDir = new File(
                    ApplicationSettingsFactory.getInstance().getApplicationSettings().getPluginWorkPath());

            if (pluginWorkDir.exists() && pluginWorkDir.isDirectory()) {
                log.info("Cleaning up the plugin work directory: " + pluginWorkDir.getAbsolutePath());
                FileUtils.cleanupDirectory(pluginWorkDir);
            } else {
                log.info("Could not cleanup plugin work directory: " + pluginWorkDir.getAbsolutePath()
                        + " because it doesn't exist or is not a directory");
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Received ApplicationEvent of class: " + event.getClass());
            }
        }
    } catch (ApplicationSettingsException e) {
        throw new WebicalWebAplicationException(e);
    }
}