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).evaluateAttributeExpressions().getValue(); String password = context.getProperty(PASSWORD).evaluateAttributeExpressions().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; }
/** * Validate enum version value. * * @param enumValue the enum value * @param requestVersion the request version * @throws ServiceVersionException the service version exception */ public static void validateEnumVersionValue(Enum<?> enumValue, ExchangeVersion requestVersion) throws ServiceVersionException { final Map<Class<?>, Map<String, ExchangeVersion>> member = ENUM_VERSION_DICTIONARIES.getMember(); final Map<String, ExchangeVersion> enumVersionDict = member.get(enumValue.getClass()); final ExchangeVersion enumVersion = enumVersionDict.get(enumValue.toString()); if (enumVersion != null) { final int i = requestVersion.compareTo(enumVersion); if (i < 0) { throw new ServiceVersionException( String.format( "Enumeration value %s in enumeration type %s is only valid for Exchange version %s or later.", enumValue.toString(), enumValue.getClass().getName(), enumVersion ) ); } } }
/** * Validates property version against the request version. * * @param service The Exchange service. * @param minimumServerVersion The minimum server version * @param propertyName The property name * @throws ServiceVersionException The service version exception */ public static void validatePropertyVersion( ExchangeService service, ExchangeVersion minimumServerVersion, String propertyName) throws ServiceVersionException { if (service.getRequestedServerVersion().ordinal() < minimumServerVersion.ordinal()) { throw new ServiceVersionException( String.format("The property %s is valid only for Exchange %s or later versions.", propertyName, minimumServerVersion)); } }
/** * Validates service object version against the request version. * * @param serviceObject The service object. * @param requestVersion The request version. * @throws ServiceVersionException Raised if this service object type requires a later version * of Exchange. */ public static void validateServiceObjectVersion( ServiceObject serviceObject, ExchangeVersion requestVersion) throws ServiceVersionException { ExchangeVersion minimumRequiredServerVersion = serviceObject .getMinimumRequiredServerVersion(); if (requestVersion.ordinal() < minimumRequiredServerVersion.ordinal()) { String msg = String.format( "The object type %s is only valid for Exchange Server version %s or later versions.", serviceObject.getClass().getName(), minimumRequiredServerVersion.toString()); throw new ServiceVersionException(msg); } }
PropertyDefinition propertyDefinition = (PropertyDefinition) propDefBase; if (propertyDefinition.getVersion().ordinal() > request .getService().getRequestedServerVersion().ordinal()) { throw new ServiceVersionException(String.format( "The property %s is valid only for Exchange %s or later versions.", if (request.getService().getRequestedServerVersion().compareTo(ExchangeVersion.Exchange2010) < 0) { throw new ServiceVersionException( String.format("The property %s is valid only for Exchange %s or later versions.", if (request.getService().getRequestedServerVersion().compareTo(ExchangeVersion.Exchange2010_SP1) < 0) { throw new ServiceVersionException( String.format("The property %s is valid only for Exchange %s or later versions.",
/** * Gets st ring representation of requested server version. In order to support E12 RTM servers, * ExchangeService has another flag indicating that we should use "Exchange2007" as the server version * string rather than Exchange2007_SP1. * * @return String representation of requested server version. */ private String getRequestedServiceVersionString() { if (this.service.getRequestedServerVersion() == ExchangeVersion.Exchange2007_SP1 && this.service .getExchange2007CompatibilityMode()) { return "Exchange2007"; } else { return this.service.getRequestedServerVersion().toString(); } }
/** * Validates service object version against the request version. * * @param serviceObject The service object. * @param requestVersion The request version. * @throws ServiceVersionException Raised if this service object type requires a later version * of Exchange. */ public static void validateServiceObjectVersion( ServiceObject serviceObject, ExchangeVersion requestVersion) throws ServiceVersionException { ExchangeVersion minimumRequiredServerVersion = serviceObject .getMinimumRequiredServerVersion(); if (requestVersion.ordinal() < minimumRequiredServerVersion.ordinal()) { String msg = String.format( "The object type %s is only valid for Exchange Server version %s or later versions.", serviceObject.getClass().getName(), minimumRequiredServerVersion.toString()); throw new ServiceVersionException(msg); } }
PropertyDefinition propertyDefinition = (PropertyDefinition) propDefBase; if (propertyDefinition.getVersion().ordinal() > request .getService().getRequestedServerVersion().ordinal()) { throw new ServiceVersionException(String.format( "The property %s is valid only for Exchange %s or later versions.", if (request.getService().getRequestedServerVersion().compareTo(ExchangeVersion.Exchange2010) < 0) { throw new ServiceVersionException( String.format("The property %s is valid only for Exchange %s or later versions.", if (request.getService().getRequestedServerVersion().compareTo(ExchangeVersion.Exchange2010_SP1) < 0) { throw new ServiceVersionException( String.format("The property %s is valid only for Exchange %s or later versions.",
.getRequestedServerVersion().toString());
/** * Validates class version against the request version. * * @param service the service * @param minimumServerVersion The minimum server version that supports the method. * @param className Name of the class. * @throws ServiceVersionException */ public static void validateClassVersion( ExchangeService service, ExchangeVersion minimumServerVersion, String className) throws ServiceVersionException { if (service.getRequestedServerVersion().ordinal() < minimumServerVersion.ordinal()) { throw new ServiceVersionException( String.format("Class %s is only valid for Exchange version %s or later.", className, minimumServerVersion)); } }
/** * Retrieves the specified settings for a set of users. * * @param userSmtpAddresses the user smtp addresses * @param userSettingNames The user setting names. * @return A GetUserSettingsResponseCollection object containing the * response for each individual user. * @throws Exception the exception */ public GetUserSettingsResponseCollection getUsersSettings( Iterable<String> userSmtpAddresses, UserSettingName... userSettingNames) throws Exception { if (this.getRequestedServerVersion().compareTo(MinimumRequestVersionForAutoDiscoverSoapService) < 0) { throw new ServiceVersionException( String.format("The Autodiscover service only supports %s or a later version.", MinimumRequestVersionForAutoDiscoverSoapService)); } List<String> smtpAddresses = new ArrayList<String>(); smtpAddresses.addAll((Collection<? extends String>) userSmtpAddresses); List<UserSettingName> settings = new ArrayList<UserSettingName>(); settings.addAll(Arrays.asList(userSettingNames)); return this.getUserSettings(smtpAddresses, settings); }
/** * Constructor for instantiating Exchange data source. * * @param settings the settings to use when reading from Microsoft Exchange * @throws Exception if an error occurs */ public ExchangeSourceImpl(final ExchangeSettings settings) throws Exception { LOG.info("Connecting to Exchange (" + settings.getExchangeHost() + ") as " + settings.getExchangeUsername() + "..."); final ExchangeCredentials credentials = new WebCredentials(settings.getExchangeUsername(), settings.getExchangePassword(), settings.getExchangeDomain()); service = new ExchangeService(ExchangeVersion.valueOf(settings.getExchangeVersion())); service.setCredentials(credentials); if (settings.needsExchangeProxy()) { final WebProxy webProxy = new WebProxy(settings.getExchangeProxyHost(), settings.getExchangeProxyPort()); service.setWebProxy(webProxy); } service.setUrl(new URI("https://" + settings.getExchangeHost() + "/EWS/Exchange.asmx")); service.setTraceEnabled(ENABLE_DEBUGGING); LOG.info("Connected to Exchange."); }
/** * Gets st ring representation of requested server version. In order to support E12 RTM servers, * ExchangeService has another flag indicating that we should use "Exchange2007" as the server version * string rather than Exchange2007_SP1. * * @return String representation of requested server version. */ private String getRequestedServiceVersionString() { if (this.service.getRequestedServerVersion() == ExchangeVersion.Exchange2007_SP1 && this.service .getExchange2007CompatibilityMode()) { return "Exchange2007"; } else { return this.service.getRequestedServerVersion().toString(); } }
/** * Validate method version. * * @param service the service * @param minimumServerVersion the minimum server version * @param methodName the method name * @throws ServiceVersionException the service version exception */ public static void validateMethodVersion(ExchangeService service, ExchangeVersion minimumServerVersion, String methodName) throws ServiceVersionException { if (service.getRequestedServerVersion().ordinal() < minimumServerVersion.ordinal()) { throw new ServiceVersionException(String.format( "Method %s is only valid for Exchange Server version %s or later.", methodName, minimumServerVersion)); } }
/** * Determines whether the specified flag is set. * * @param flag The flag. * @param version Requested version. * @return true/false if the specified flag is set,otherwise false. */ @Override public boolean hasFlag(PropertyDefinitionFlags flag, ExchangeVersion version) { if (version != null && this.getVersion() .compareTo(ExchangeVersion.Exchange2010_SP2) >= 0) { if (AttachmentsPropertyDefinition.Exchange2010SP2PropertyDefinitionFlags .contains(flag)) { return true; } else { return false; } } return super.hasFlag(flag, version); }
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).evaluateAttributeExpressions().getValue(); String password = context.getProperty(PASSWORD).evaluateAttributeExpressions().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; }
.getRequestedServerVersion().toString());
/** * Throw exception if request is not supported in requested server version. * * @throws ServiceVersionException the service version exception */ protected void throwIfNotSupportedByRequestedServerVersion() throws ServiceVersionException { if (this.service.getRequestedServerVersion().ordinal() < this.getMinimumRequiredServerVersion() .ordinal()) { throw new ServiceVersionException(String.format( "The service request %s is only valid for Exchange version %s or later.", this.getXmlElementName(), this.getMinimumRequiredServerVersion())); } }
/** * Retrieves the specified settings for single SMTP address. * <p>This method will run the entire Autodiscover "discovery" * algorithm and will follow address and URL redirections.</p> * @param userSmtpAddress The SMTP addresses of the user. * @param userSettingNames The user setting names. * @return A UserResponse object containing the requested settings for the * specified user. * @throws Exception on error */ public GetUserSettingsResponse getUserSettings(String userSmtpAddress, UserSettingName... userSettingNames) throws Exception { List<UserSettingName> requestedSettings = new ArrayList<UserSettingName>(); requestedSettings.addAll(Arrays.asList(userSettingNames)); if (userSmtpAddress == null || userSmtpAddress.isEmpty()) { throw new ServiceValidationException("A valid SMTP address must be specified."); } if (requestedSettings.size() == 0) { throw new ServiceValidationException("At least one setting must be requested."); } if (this.getRequestedServerVersion().compareTo(MinimumRequestVersionForAutoDiscoverSoapService) < 0) { return this.internalGetLegacyUserSettings(userSmtpAddress, requestedSettings); } else { return this.internalGetSoapUserSettings(userSmtpAddress, requestedSettings); } }
/** * Initializes a new instance of <see cref="UserConfiguration"/> class. * * @param service The service to which the user configuration is bound. * @param requestedProperties The property requested for this user configuration. * @throws Exception the exception */ public UserConfiguration(ExchangeService service, EnumSet<UserConfigurationProperties> requestedProperties) throws Exception { EwsUtilities.validateParam(service, "service"); if (service.getRequestedServerVersion().ordinal() < UserConfiguration.ObjectVersion.ordinal()) { throw new ServiceVersionException(String.format( "The object type %s is only valid for Exchange Server version %s or later versions.", this .getClass().getName(), UserConfiguration.ObjectVersion)); } this.service = service; this.isNew = true; this.initializeProperties(requestedProperties); }