microsoft.exchange.webservices.data.autodiscover.IAutodiscoverRedirectionUrl Java Examples

The following examples show how to use microsoft.exchange.webservices.data.autodiscover.IAutodiscoverRedirectionUrl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExchangeService.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Gets the autodiscover url.
 *
 * @param emailAddress                   the email address
 * @param requestedServerVersion         the Exchange version
 * @param validateRedirectionUrlCallback the validate redirection url callback
 * @return the autodiscover url
 * @throws Exception the exception
 */
private URI getAutodiscoverUrl(String emailAddress,
    ExchangeVersion requestedServerVersion,
    IAutodiscoverRedirectionUrl validateRedirectionUrlCallback)
    throws Exception {

  AutodiscoverService autodiscoverService = new AutodiscoverService(this, requestedServerVersion);
  autodiscoverService.setWebProxy(getWebProxy());
  autodiscoverService.setTimeout(getTimeout());
  
  autodiscoverService
      .setRedirectionUrlValidationCallback(validateRedirectionUrlCallback);
  autodiscoverService.setEnableScpLookup(this.getEnableScpLookup());

  GetUserSettingsResponse response = autodiscoverService.getUserSettings(
      emailAddress, UserSettingName.InternalEwsUrl,
      UserSettingName.ExternalEwsUrl);

  switch (response.getErrorCode()) {
    case NoError:
      return this.getEwsUrlFromResponse(response, autodiscoverService
          .isExternal().TRUE);

    case InvalidUser:
      throw new ServiceRemoteException(String.format("Invalid user: '%s'",
          emailAddress));

    case InvalidRequest:
      throw new ServiceRemoteException(String.format("Invalid Autodiscover request: '%s'", response
              .getErrorMessage()));

    default:
      this.traceMessage(TraceFlags.AutodiscoverConfiguration, String
          .format("No EWS Url returned for user %s, "
              + "error code is %s", emailAddress, response
              .getErrorCode()));

      throw new ServiceRemoteException(response.getErrorMessage());
  }
}