Example usage for org.springframework.integration.mail AbstractMailReceiver setBeanName

List of usage examples for org.springframework.integration.mail AbstractMailReceiver setBeanName

Introduction

In this page you can find the example usage for org.springframework.integration.mail AbstractMailReceiver setBeanName.

Prototype

@Override
    public final void setBeanName(String beanName) 

Source Link

Usage

From source file:eu.openanalytics.rsb.component.EmailDepositHandler.java

@PostConstruct
public void setupChannelAdapters() throws URISyntaxException {
    final List<DepositEmailConfiguration> depositEmailConfigurations = getConfiguration()
            .getDepositEmailAccounts();//  w  w  w .  j  ava2 s  .  co m

    if ((depositEmailConfigurations == null) || (depositEmailConfigurations.isEmpty())) {
        return;
    }

    for (final DepositEmailConfiguration depositEmailConfiguration : depositEmailConfigurations) {
        final PeriodicTrigger trigger = new PeriodicTrigger(depositEmailConfiguration.getPollingPeriod(),
                TimeUnit.MILLISECONDS);
        trigger.setInitialDelay(5000L);

        AbstractMailReceiver mailReceiver = null;

        final URI emailAccountURI = depositEmailConfiguration.getAccountURI();
        if (StringUtils.equals(emailAccountURI.getScheme(), "pop3")) {
            mailReceiver = new Pop3MailReceiver(emailAccountURI.toString());
        } else if (StringUtils.equals(emailAccountURI.getScheme(), "imap")) {
            mailReceiver = new ImapMailReceiver(emailAccountURI.toString());
            ((ImapMailReceiver) mailReceiver).setShouldMarkMessagesAsRead(true);
        } else {
            throw new IllegalArgumentException("Invalid email account URI: " + emailAccountURI);
        }

        mailReceiver.setBeanFactory(beanFactory);
        mailReceiver.setBeanName("rsb-email-ms-" + emailAccountURI.getHost() + emailAccountURI.hashCode());
        mailReceiver.setShouldDeleteMessages(true);
        mailReceiver.setMaxFetchSize(1);
        mailReceiver.afterPropertiesSet();
        final MailReceivingMessageSource fileMessageSource = new MailReceivingMessageSource(mailReceiver);
        final HeaderSettingMessageSourceWrapper<javax.mail.Message> messageSource = new HeaderSettingMessageSourceWrapper<javax.mail.Message>(
                fileMessageSource, EMAIL_CONFIG_HEADER_NAME, depositEmailConfiguration);

        final SourcePollingChannelAdapter channelAdapter = new SourcePollingChannelAdapter();
        channelAdapter.setBeanFactory(beanFactory);
        channelAdapter.setBeanName("rsb-email-ca-" + emailAccountURI.getHost() + emailAccountURI.hashCode());
        channelAdapter.setOutputChannel(emailDepositChannel);
        channelAdapter.setSource(messageSource);
        channelAdapter.setTrigger(trigger);
        channelAdapter.afterPropertiesSet();
        channelAdapter.start();

        getLogger().info("Started channel adapter: " + channelAdapter);

        channelAdapters.add(channelAdapter);
    }
}