Search in sources :

Example 1 with WebCredentials

use of microsoft.exchange.webservices.data.credential.WebCredentials in project nifi by apache.

the class ConsumeEWS method initializeIfNecessary.

protected ExchangeService initializeIfNecessary(ProcessContext context) throws ProcessException {
    ExchangeVersion ver = ExchangeVersion.valueOf(context.getProperty(EXCHANGE_VERSION).getValue());
    ExchangeService service = new ExchangeService(ver);
    final String timeoutInMillis = String.valueOf(context.getProperty(CONNECTION_TIMEOUT).evaluateAttributeExpressions().asTimePeriod(TimeUnit.MILLISECONDS));
    service.setTimeout(Integer.parseInt(timeoutInMillis));
    String userEmail = context.getProperty(USER).getValue();
    String password = context.getProperty(PASSWORD).getValue();
    ExchangeCredentials credentials = new WebCredentials(userEmail, password);
    service.setCredentials(credentials);
    Boolean useAutodiscover = context.getProperty(USE_AUTODISCOVER).asBoolean();
    if (useAutodiscover) {
        try {
            service.autodiscoverUrl(userEmail, new RedirectionUrlCallback());
        } catch (Exception e) {
            throw new ProcessException("Failure setting Autodiscover URL from email address.", e);
        }
    } else {
        String ewsURL = context.getProperty(EWS_URL).getValue();
        try {
            service.setUrl(new URI(ewsURL));
        } catch (URISyntaxException e) {
            throw new ProcessException("Failure setting EWS URL.", e);
        }
    }
    return service;
}
Also used : ExchangeService(microsoft.exchange.webservices.data.core.ExchangeService) ExchangeVersion(microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion) ProcessException(org.apache.nifi.processor.exception.ProcessException) ExchangeCredentials(microsoft.exchange.webservices.data.credential.ExchangeCredentials) URISyntaxException(java.net.URISyntaxException) WebCredentials(microsoft.exchange.webservices.data.credential.WebCredentials) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) MessagingException(javax.mail.MessagingException) EmailException(org.apache.commons.mail.EmailException) ProcessException(org.apache.nifi.processor.exception.ProcessException) IOException(java.io.IOException)

Example 2 with WebCredentials

use of microsoft.exchange.webservices.data.credential.WebCredentials in project iaf by ibissource.

the class ExchangeMailListener method configure.

public void configure() throws ConfigurationException {
    try {
        exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        CredentialFactory cf = new CredentialFactory(getAuthAlias(), getUserName(), getPassword());
        ExchangeCredentials credentials = new WebCredentials(cf.getUsername(), cf.getPassword());
        exchangeService.setCredentials(credentials);
        if (StringUtils.isNotEmpty(getMailAddress())) {
            exchangeService.autodiscoverUrl(getMailAddress());
        } else {
            exchangeService.setUrl(new URI(getUrl()));
        }
        FolderId inboxId;
        if (StringUtils.isNotEmpty(getMailAddress())) {
            Mailbox mailbox = new Mailbox(getMailAddress());
            inboxId = new FolderId(WellKnownFolderName.Inbox, mailbox);
        } else {
            inboxId = new FolderId(WellKnownFolderName.Inbox);
        }
        FindFoldersResults findFoldersResultsIn;
        FolderView folderViewIn = new FolderView(10);
        if (StringUtils.isNotEmpty(getInputFolder())) {
            SearchFilter searchFilterIn = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, getInputFolder());
            findFoldersResultsIn = exchangeService.findFolders(inboxId, searchFilterIn, folderViewIn);
            if (findFoldersResultsIn.getTotalCount() == 0) {
                throw new ConfigurationException("no (in) folder found with name [" + getInputFolder() + "]");
            } else if (findFoldersResultsIn.getTotalCount() > 1) {
                throw new ConfigurationException("multiple (in) folders found with name [" + getInputFolder() + "]");
            }
        } else {
            findFoldersResultsIn = exchangeService.findFolders(inboxId, folderViewIn);
        }
        folderIn = findFoldersResultsIn.getFolders().get(0);
        if (StringUtils.isNotEmpty(getFilter())) {
            if (!getFilter().equalsIgnoreCase("NDR")) {
                throw new ConfigurationException("illegal value for filter [" + getFilter() + "], must be 'NDR' or empty");
            }
        }
        if (StringUtils.isNotEmpty(getOutputFolder())) {
            SearchFilter searchFilterOut = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, getOutputFolder());
            FolderView folderViewOut = new FolderView(10);
            FindFoldersResults findFoldersResultsOut = exchangeService.findFolders(inboxId, searchFilterOut, folderViewOut);
            if (findFoldersResultsOut.getTotalCount() == 0) {
                throw new ConfigurationException("no (out) folder found with name [" + getOutputFolder() + "]");
            } else if (findFoldersResultsOut.getTotalCount() > 1) {
                throw new ConfigurationException("multiple (out) folders found with name [" + getOutputFolder() + "]");
            }
            folderOut = findFoldersResultsOut.getFolders().get(0);
        }
    } catch (Exception e) {
        throw new ConfigurationException(e);
    }
}
Also used : FolderView(microsoft.exchange.webservices.data.search.FolderView) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) FindFoldersResults(microsoft.exchange.webservices.data.search.FindFoldersResults) SearchFilter(microsoft.exchange.webservices.data.search.filter.SearchFilter) FolderId(microsoft.exchange.webservices.data.property.complex.FolderId) URI(java.net.URI) ServiceLocalException(microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ExchangeService(microsoft.exchange.webservices.data.core.ExchangeService) Mailbox(microsoft.exchange.webservices.data.property.complex.Mailbox) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ExchangeCredentials(microsoft.exchange.webservices.data.credential.ExchangeCredentials) WebCredentials(microsoft.exchange.webservices.data.credential.WebCredentials)

Aggregations

URI (java.net.URI)2 ExchangeService (microsoft.exchange.webservices.data.core.ExchangeService)2 ExchangeCredentials (microsoft.exchange.webservices.data.credential.ExchangeCredentials)2 WebCredentials (microsoft.exchange.webservices.data.credential.WebCredentials)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 MessagingException (javax.mail.MessagingException)1 ExchangeVersion (microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion)1 ServiceLocalException (microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException)1 FolderId (microsoft.exchange.webservices.data.property.complex.FolderId)1 Mailbox (microsoft.exchange.webservices.data.property.complex.Mailbox)1 FindFoldersResults (microsoft.exchange.webservices.data.search.FindFoldersResults)1 FolderView (microsoft.exchange.webservices.data.search.FolderView)1 SearchFilter (microsoft.exchange.webservices.data.search.filter.SearchFilter)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 ListenerException (nl.nn.adapterframework.core.ListenerException)1 CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)1 EmailException (org.apache.commons.mail.EmailException)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1