use of microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion 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;
}
Aggregations