endpoints = EnumSet
+ .noneOf(AutodiscoverEndpoints.class);
+ endpoints.add(AutodiscoverEndpoints.Legacy);
+
+ final String soapEnabled = request.getResponseHeaderField(AutodiscoverSoapEnabledHeaderName);
+ if (soapEnabled != null && !soapEnabled.isEmpty()) {
+ endpoints.add(AutodiscoverEndpoints.Soap);
+ }
+ final String wsSecEnabled = request.getResponseHeaderField(AutodiscoverWsSecurityEnabledHeaderName);
+ if (wsSecEnabled != null && !wsSecEnabled.isEmpty()) {
+ endpoints.add(AutodiscoverEndpoints.WsSecurity);
+ }
+
+ /* if (! (request.getResponseHeaders().get(
+ AutodiscoverWsSecuritySymmetricKeyEnabledHeaderName) !=null || request
+ .getResponseHeaders().get(
+ AutodiscoverWsSecuritySymmetricKeyEnabledHeaderName).isEmpty()))
+ {
+ endpoints .add( AutodiscoverEndpoints.WSSecuritySymmetricKey);
+ }
+ if (!(request.getResponseHeaders().get(
+ AutodiscoverWsSecurityX509CertEnabledHeaderName)!=null ||
+ request.getResponseHeaders().get(
+ AutodiscoverWsSecurityX509CertEnabledHeaderName).isEmpty()))
+
+ {
+ endpoints .add(AutodiscoverEndpoints.WSSecurityX509Cert);
+ }*/
+
+ return endpoints;
+ }
+
+ /**
+ * Traces the response.
+ *
+ * @param request the request
+ * @param memoryStream the memory stream
+ * @throws XMLStreamException the XML stream exception
+ * @throws IOException signals that an I/O exception has occurred.
+ * @throws EWSHttpException the EWS http exception
+ */
+ public void traceResponse(ExchangeHttpClient.Request request, ByteArrayOutputStream memoryStream) throws XMLStreamException,
+ IOException, EWSHttpException {
+ this.processHttpResponseHeaders(
+ TraceFlags.AutodiscoverResponseHttpHeaders, request);
+ String contentType = request.getResponseContentType();
+ if (!(contentType == null || contentType.isEmpty())) {
+ contentType = contentType.toLowerCase();
+ if (contentType.toLowerCase().startsWith("text/") ||
+ contentType.toLowerCase().
+ startsWith("application/soap")) {
+ this.traceXml(TraceFlags.AutodiscoverResponse, memoryStream);
+ } else {
+ this.traceMessage(TraceFlags.AutodiscoverResponse,
+ "Non-textual response");
+ }
+ }
+ }
+
+ /**
+ * Creates an HttpWebRequest instance and initializes it with the
+ * appropriate parameters, based on the configuration of this service
+ * object.
+ *
+ * @param url The URL that the HttpWebRequest should target
+ * @return HttpWebRequest The HttpWebRequest
+ * @throws ServiceLocalException the service local exception
+ * @throws java.net.URISyntaxException the uRI syntax exception
+ */
+ public ExchangeHttpClient.Request prepareHttpWebRequestForUrl(URI url) throws ServiceLocalException, URISyntaxException {
+ return this.prepareHttpWebRequestForUrl(url, false,
+ // acceptGzipEncoding
+ false); // allowAutoRedirect
+ }
+
+ /**
+ * Calls the redirection URL validation callback. If the redirection URL
+ * validation callback is null, use the default callback which does not
+ * allow following any redirections.
+ *
+ * @param redirectionUrl The redirection URL.
+ * @return True if redirection should be followed.
+ * @throws AutodiscoverLocalException the autodiscover local exception
+ */
+ private boolean callRedirectionUrlValidationCallback(String redirectionUrl)
+ throws AutodiscoverLocalException {
+ IAutodiscoverRedirectionUrl callback =
+ (this.redirectionUrlValidationCallback == null) ? this
+ : this.redirectionUrlValidationCallback;
+ return callback
+ .autodiscoverRedirectionUrlValidationCallback(redirectionUrl);
+ }
+
+ /**
+ * Processes an HTTP error response.
+ *
+ * @param httpWebResponse The HTTP web response.
+ * @throws Exception the exception
+ */
+ @Override
+ public void processHttpErrorResponse(ExchangeHttpClient.Request httpWebResponse, Exception webException) throws Exception {
+ this.internalProcessHttpErrorResponse(
+ httpWebResponse,
+ webException,
+ TraceFlags.AutodiscoverResponseHttpHeaders,
+ TraceFlags.AutodiscoverResponse);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see microsoft.exchange.webservices.AutodiscoverRedirectionUrlInterface#
+ * autodiscoverRedirectionUrlValidationCallback(java.lang.String)
+ */
+ public boolean autodiscoverRedirectionUrlValidationCallback(
+ String redirectionUrl) throws AutodiscoverLocalException {
+ return defaultAutodiscoverRedirectionUrlValidationCallback(
+ redirectionUrl);
+ }
+
+ /**
+ * Initializes a new instance of the "AutodiscoverService" class.
+ *
+ * @throws ArgumentException on validation error
+ */
+ public AutodiscoverService(final ExchangeHttpClient client) throws ArgumentException {
+ this(client, ExchangeVersion.Exchange2010);
+ }
+
+ /**
+ * Initializes a new instance of the "AutodiscoverService" class.
+ *
+ * @param requestedServerVersion The requested server version
+ * @throws ArgumentException on validation error
+ */
+ public AutodiscoverService(final ExchangeHttpClient client, ExchangeVersion requestedServerVersion) throws ArgumentException {
+ this(client, null, null, requestedServerVersion);
+ }
+
+ /**
+ * Initializes a new instance of the "AutodiscoverService" class.
+ *
+ * @param domain The domain that will be used to determine the URL of the service
+ * @throws ArgumentException on validation error
+ */
+ public AutodiscoverService(final ExchangeHttpClient client, String domain) throws ArgumentException {
+ this(client, null, domain);
+ }
+
+ /**
+ * Initializes a new instance of the "AutodiscoverService" class.
+ *
+ * @param domain The domain that will be used to determine the URL of the service
+ * @param requestedServerVersion The requested server version
+ * @throws ArgumentException on validation error
+ */
+ public AutodiscoverService(final ExchangeHttpClient client,
+ String domain,
+ ExchangeVersion requestedServerVersion) throws ArgumentException {
+ this(client, null, domain, requestedServerVersion);
+ }
+
+ /**
+ * Initializes a new instance of the "AutodiscoverService" class.
+ *
+ * @param url The URL of the service
+ * @throws ArgumentException on validation error
+ */
+ public AutodiscoverService(final ExchangeHttpClient client, URI url) throws ArgumentException {
+ this(client, url, url.getHost());
+ }
+
+ /**
+ * Initializes a new instance of the "AutodiscoverService" class.
+ *
+ * @param url The URL of the service
+ * @param requestedServerVersion The requested server version
+ * @throws ArgumentException on validation error
+ */
+ public AutodiscoverService(final ExchangeHttpClient client, URI url,
+ ExchangeVersion requestedServerVersion) throws ArgumentException {
+ this(client, url, url.getHost(), requestedServerVersion);
+ }
+
+ /**
+ * Initializes a new instance of the "AutodiscoverService" class.
+ *
+ * @param url The URL of the service
+ * @param domain The domain that will be used to determine the URL of the service
+ * @throws ArgumentException on validation error
+ */
+ public AutodiscoverService(final ExchangeHttpClient client, URI url, String domain) throws ArgumentException {
+ super(client);
+ EwsUtilities.validateDomainNameAllowNull(domain, "domain");
+ this.url = url;
+ this.domain = domain;
+ this.dnsClient = new AutodiscoverDnsClient(this);
+ }
+
+ /**
+ * Initializes a new instance of the "AutodiscoverService" class.
+ *
+ * @param url The URL of the service.
+ * @param domain The domain that will be used to determine the URL of the
+ * service.
+ * @param requestedServerVersion The requested server version.
+ * @throws ArgumentException on validation error
+ */
+ public AutodiscoverService(final ExchangeHttpClient client, URI url, String domain, ExchangeVersion requestedServerVersion) throws ArgumentException {
+ super(requestedServerVersion, client);
+ EwsUtilities.validateDomainNameAllowNull(domain, "domain");
+
+ this.url = url;
+ this.domain = domain;
+ this.dnsClient = new AutodiscoverDnsClient(this);
+ }
+
+ /**
+ * Initializes a new instance of the AutodiscoverService class.
+ *
+ * @param service The other service.
+ * @param requestedServerVersion The requested server version.
+ */
+ public AutodiscoverService(ExchangeServiceBase service,
+ ExchangeVersion requestedServerVersion) {
+ super(service, requestedServerVersion);
+ this.dnsClient = new AutodiscoverDnsClient(this);
+ }
+
+ /**
+ * Initializes a new instance of the "AutodiscoverService" class.
+ *
+ * @param service The service.
+ */
+ public AutodiscoverService(ExchangeServiceBase service) {
+ super(service, service.getRequestedServerVersion());
+ }
+
+ /**
+ * Retrieves the specified settings for single SMTP address.
+ * This method will run the entire Autodiscover "discovery"
+ * algorithm and will follow address and URL redirections.
+ *
+ * @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 requestedSettings = new ArrayList();
+ requestedSettings.addAll(Arrays.asList(userSettingNames));
+
+ if (userSmtpAddress == null || userSmtpAddress.isEmpty()) {
+ throw new ExchangeValidationException("A valid SMTP address must be specified.");
+ }
+
+ if (requestedSettings.size() == 0) {
+ throw new ExchangeValidationException("At least one setting must be requested.");
+ }
+
+ if (this.getRequestedServerVersion().compareTo(MinimumRequestVersionForAutoDiscoverSoapService) < 0) {
+ return this.internalGetLegacyUserSettings(userSmtpAddress,
+ requestedSettings);
+ } else {
+ return this.internalGetSoapUserSettings(userSmtpAddress,
+ requestedSettings);
+ }
+
+ }
+
+ /**
+ * 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 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 smtpAddresses = new ArrayList();
+ smtpAddresses.addAll((Collection extends String>) userSmtpAddresses);
+ List settings = new ArrayList();
+ settings.addAll(Arrays.asList(userSettingNames));
+ return this.getUserSettings(smtpAddresses, settings);
+ }
+
+ /**
+ * Retrieves the specified settings for a domain.
+ *
+ * @param domain The domain.
+ * @param requestedVersion Requested version of the Exchange service.
+ * @param domainSettingNames The domain setting names.
+ * @return A DomainResponse object containing the requested settings for the
+ * specified domain.
+ * @throws Exception the exception
+ */
+ public GetDomainSettingsResponse getDomainSettings(String domain,
+ ExchangeVersion requestedVersion,
+ DomainSettingName... domainSettingNames) throws Exception {
+ List domains = new ArrayList(1);
+ domains.add(domain);
+
+ List settings = new ArrayList();
+ settings.addAll(Arrays.asList(domainSettingNames));
+
+ return this.getDomainSettings(domains, settings, requestedVersion).
+ getTResponseAtIndex(0);
+ }
+
+ /**
+ * Retrieves the specified settings for a set of domains.
+ *
+ * @param domains the domains
+ * @param requestedVersion Requested version of the Exchange service.
+ * @param domainSettingNames The domain setting names.
+ * @return A GetDomainSettingsResponseCollection object containing the
+ * response for each individual domain.
+ * @throws Exception the exception
+ */
+ public GetDomainSettingsResponseCollection getDomainSettings(
+ Iterable domains, ExchangeVersion requestedVersion,
+ DomainSettingName... domainSettingNames)
+ throws Exception {
+ List settings = new ArrayList();
+ settings.addAll(Arrays.asList(domainSettingNames));
+
+ List domainslst = new ArrayList();
+ domainslst.addAll((Collection extends String>) domains);
+
+ return this.getDomainSettings(domainslst, settings, requestedVersion);
+ }
+
+ /**
+ * Gets the domain this service is bound to. When this property is
+ * set, the domain name is used to automatically determine the Autodiscover service URL.
+ *
+ * @return the domain
+ */
+ public String getDomain() {
+ return this.domain;
+ }
+
+ /**
+ * Sets the domain this service is bound to. When this property is
+ * set, the domain
+ * name is used to automatically determine the Autodiscover service URL.
+ *
+ * @param value the new domain
+ * @throws ArgumentException on validation error
+ */
+ public void setDomain(String value) throws ArgumentException {
+ EwsUtilities.validateDomainNameAllowNull(value, "Domain");
+
+ // If Domain property is set to non-null value, Url property is nulled.
+ if (value != null) {
+ this.url = null;
+ }
+ this.domain = value;
+ }
+
+ /**
+ * Gets the url this service is bound to.
+ *
+ * @return the url
+ */
+ public URI getUrl() {
+ return this.url;
+ }
+
+ /**
+ * Sets the url this service is bound to.
+ *
+ * @param value the new url
+ */
+ public void setUrl(URI value) {
+ // If Url property is set to non-null value, Domain property is set to
+ // host portion of Url.
+ if (value != null) {
+ this.domain = value.getHost();
+ }
+ this.url = value;
+ }
+
+ public Boolean isExternal() {
+ return this.isExternal;
+ }
+
+ protected void setIsExternal(Boolean value) {
+ this.isExternal = value;
+ }
+
+
+ /**
+ * Gets the redirection url validation callback.
+ *
+ * @return the redirection url validation callback
+ */
+ public IAutodiscoverRedirectionUrl
+ getRedirectionUrlValidationCallback() {
+ return this.redirectionUrlValidationCallback;
+ }
+
+ /**
+ * Sets the redirection url validation callback.
+ *
+ * @param value the new redirection url validation callback
+ */
+ public void setRedirectionUrlValidationCallback(
+ IAutodiscoverRedirectionUrl value) {
+ this.redirectionUrlValidationCallback = value;
+ }
+
+ /**
+ * Gets the dns server address.
+ *
+ * @return the dns server address
+ */
+ protected String getDnsServerAddress() {
+ return this.dnsServerAddress;
+ }
+
+ /**
+ * Sets the dns server address.
+ *
+ * @param value the new dns server address
+ */
+ protected void setDnsServerAddress(String value) {
+ this.dnsServerAddress = value;
+ }
+
+ /**
+ * Gets a value indicating whether the AutodiscoverService should
+ * perform SCP (ServiceConnectionPoint) record lookup when determining
+ * the Autodiscover service URL.
+ *
+ * @return the enable scp lookup
+ */
+ public boolean getEnableScpLookup() {
+ return this.enableScpLookup;
+ }
+
+ /**
+ * Sets the enable scp lookup.
+ *
+ * @param value the new enable scp lookup
+ */
+ public void setEnableScpLookup(boolean value) {
+ this.enableScpLookup = value;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * microsoft.exchange.webservices.FuncDelegateInterface#func(java.util.List,
+ * java.util.List, java.net.URI)
+ */
+ @Override
+ public Object func(List arg1, List arg2, ExchangeVersion arg3, URI arg4)
+ throws Exception {
+ if (arg2.get(0).getClass().equals(DomainSettingName.class)) {
+ return internalGetDomainSettings(arg1, arg2, arg3, arg4);
+ } else if (arg2.get(0).getClass().equals(UserSettingName.class)) {
+ return internalGetUserSettings(arg1, arg2, arg3, arg4);
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/ews-api/src/main/java/com/eischet/ews/api/autodiscover/IAutodiscoverRedirectionUrl.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/IAutodiscoverRedirectionUrl.java
new file mode 100644
index 000000000..a76b0edd3
--- /dev/null
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/IAutodiscoverRedirectionUrl.java
@@ -0,0 +1,43 @@
+/*
+ * The MIT License
+ * Copyright (c) 2012 Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.eischet.ews.api.autodiscover;
+
+import com.eischet.ews.api.autodiscover.exception.AutodiscoverLocalException;
+
+/**
+ * Defines a delegate that is used by the AutodiscoverService to ask whether a
+ * redirectionUrl can be used.
+ */
+public interface IAutodiscoverRedirectionUrl {
+
+ /**
+ * Autodiscover redirection url validation callback.
+ *
+ * @param redirectionUrl the redirection url
+ * @return true, if successful
+ * @throws AutodiscoverLocalException the autodiscover local exception
+ */
+ boolean autodiscoverRedirectionUrlValidationCallback(
+ String redirectionUrl) throws AutodiscoverLocalException;
+}
diff --git a/src/main/java/microsoft/exchange/webservices/data/autodiscover/IFunc.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/IFunc.java
similarity index 89%
rename from src/main/java/microsoft/exchange/webservices/data/autodiscover/IFunc.java
rename to ews-api/src/main/java/com/eischet/ews/api/autodiscover/IFunc.java
index 3dc6429a6..a001c207e 100644
--- a/src/main/java/microsoft/exchange/webservices/data/autodiscover/IFunc.java
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/IFunc.java
@@ -21,7 +21,7 @@
* THE SOFTWARE.
*/
-package microsoft.exchange.webservices.data.autodiscover;
+package com.eischet.ews.api.autodiscover;
/**
* The Interface Func.
@@ -31,11 +31,11 @@
*/
public interface IFunc {
- /**
- * Func.
- *
- * @param arg the arg
- * @return the t result
- */
- TResult func(T arg);
+ /**
+ * Func.
+ *
+ * @param arg the arg
+ * @return the t result
+ */
+ TResult func(T arg);
}
diff --git a/src/main/java/microsoft/exchange/webservices/data/autodiscover/IFuncDelegate.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/IFuncDelegate.java
similarity index 81%
rename from src/main/java/microsoft/exchange/webservices/data/autodiscover/IFuncDelegate.java
rename to ews-api/src/main/java/com/eischet/ews/api/autodiscover/IFuncDelegate.java
index 386e3e4aa..326fe1243 100644
--- a/src/main/java/microsoft/exchange/webservices/data/autodiscover/IFuncDelegate.java
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/IFuncDelegate.java
@@ -21,9 +21,9 @@
* THE SOFTWARE.
*/
-package microsoft.exchange.webservices.data.autodiscover;
+package com.eischet.ews.api.autodiscover;
-import microsoft.exchange.webservices.data.core.exception.misc.FormatException;
+import com.eischet.ews.api.core.exception.misc.FormatException;
/**
* The Interface FuncDelegate.
@@ -32,11 +32,11 @@
*/
public interface IFuncDelegate {
- /**
- * Func.
- *
- * @return the t result
- * @throws FormatException the format exception
- */
- TResult func() throws FormatException;
+ /**
+ * Func.
+ *
+ * @return the t result
+ * @throws FormatException the format exception
+ */
+ TResult func() throws FormatException;
}
diff --git a/src/main/java/microsoft/exchange/webservices/data/autodiscover/IFunctionDelegate.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/IFunctionDelegate.java
similarity index 77%
rename from src/main/java/microsoft/exchange/webservices/data/autodiscover/IFunctionDelegate.java
rename to ews-api/src/main/java/com/eischet/ews/api/autodiscover/IFunctionDelegate.java
index 0588754d0..220f701c5 100644
--- a/src/main/java/microsoft/exchange/webservices/data/autodiscover/IFunctionDelegate.java
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/IFunctionDelegate.java
@@ -21,9 +21,9 @@
* THE SOFTWARE.
*/
-package microsoft.exchange.webservices.data.autodiscover;
+package com.eischet.ews.api.autodiscover;
-import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
+import com.eischet.ews.api.core.enumeration.misc.ExchangeVersion;
import java.net.URI;
import java.util.List;
@@ -37,16 +37,16 @@
*/
public interface IFunctionDelegate, T2 extends List>, TResult> {
- /**
- * Func.
- *
- * @param arg1 the arg1
- * @param arg2 the arg2
- * @param arg3 the arg3
- * @param arg4 the arg4
- * @return the t result
- * @throws Exception the exception
- */
- TResult func(T1 arg1, T2 arg2, ExchangeVersion arg3, URI arg4) throws Exception;
+ /**
+ * Func.
+ *
+ * @param arg1 the arg1
+ * @param arg2 the arg2
+ * @param arg3 the arg3
+ * @param arg4 the arg4
+ * @return the t result
+ * @throws Exception the exception
+ */
+ TResult func(T1 arg1, T2 arg2, ExchangeVersion arg3, URI arg4) throws Exception;
}
diff --git a/ews-api/src/main/java/com/eischet/ews/api/autodiscover/ProtocolConnection.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/ProtocolConnection.java
new file mode 100644
index 000000000..86e5e32ca
--- /dev/null
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/ProtocolConnection.java
@@ -0,0 +1,160 @@
+/*
+ * The MIT License
+ * Copyright (c) 2012 Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.eischet.ews.api.autodiscover;
+
+import com.eischet.ews.api.core.EwsXmlReader;
+import com.eischet.ews.api.core.XmlElementNames;
+import com.eischet.ews.api.core.enumeration.misc.XmlNamespace;
+import com.eischet.ews.api.security.XmlNodeType;
+
+/**
+ * Represents the email Protocol connection settings for pop/imap/smtp
+ * protocols.
+ */
+public final class ProtocolConnection {
+
+ /**
+ * The encryption method.
+ */
+ private String encryptionMethod;
+
+ /**
+ * The hostname.
+ */
+ private String hostname;
+
+ /**
+ * The port.
+ */
+ private int port;
+
+ /**
+ * Initializes a new instance of the {@link ProtocolConnection} class.
+ */
+
+ protected ProtocolConnection() {
+ }
+
+ /**
+ * Read user setting with ProtocolConnection value.
+ *
+ * @param reader EwsServiceXmlReader
+ * @return the protocol connection
+ * @throws Exception the exception
+ */
+ protected static ProtocolConnection loadFromXml(EwsXmlReader reader)
+ throws Exception {
+ ProtocolConnection connection = new ProtocolConnection();
+
+ do {
+ reader.read();
+
+ if (reader.getNodeType().getNodeType() == XmlNodeType.START_ELEMENT) {
+ if (reader.getLocalName().equals(
+ XmlElementNames.EncryptionMethod)) {
+ connection.setEncryptionMethod(reader
+ .readElementValue(String.class));
+ } else if (reader.getLocalName().equals(
+ XmlElementNames.Hostname)) {
+ connection.setHostname(reader
+ .readElementValue(String.class));
+ } else if (reader.getLocalName().equals(XmlElementNames.Port)) {
+ connection.setPort(reader.readElementValue(int.class));
+ }
+ }
+ } while (!reader.isEndElement(XmlNamespace.Autodiscover,
+ XmlElementNames.ProtocolConnection));
+
+ return connection;
+ }
+
+ /**
+ * Initializes a new instance of the ProtocolConnection class.
+ *
+ * @param encryptionMethod The encryption method.
+ * @param hostname The hostname.
+ * @param port The port number to use for the portocol.
+ */
+ protected ProtocolConnection(String encryptionMethod, String hostname,
+ int port) {
+ this.encryptionMethod = encryptionMethod;
+ this.hostname = hostname;
+ this.port = port;
+ }
+
+ /**
+ * Gets the encryption method.
+ *
+ * @return The encryption method.
+ */
+ public String getEncryptionMethod() {
+ return this.encryptionMethod;
+ }
+
+ /**
+ * Sets the encryption method.
+ *
+ * @param value the new encryption method
+ */
+ public void setEncryptionMethod(String value) {
+ this.encryptionMethod = value;
+ }
+
+ /**
+ * Gets the hostname.
+ *
+ * @return The hostname.
+ */
+ public String getHostname() {
+ return this.hostname;
+
+ }
+
+ /**
+ * Sets the hostname.
+ *
+ * @param value the new hostname
+ */
+ public void setHostname(String value) {
+ this.hostname = value;
+ }
+
+ /**
+ * Gets the port number.
+ *
+ * @return The port number.
+ */
+ public int getPort() {
+ return this.port;
+ }
+
+ /**
+ * Sets the port.
+ *
+ * @param value the new port
+ */
+ public void setPort(int value) {
+ this.port = value;
+ }
+}
diff --git a/ews-api/src/main/java/com/eischet/ews/api/autodiscover/ProtocolConnectionCollection.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/ProtocolConnectionCollection.java
new file mode 100644
index 000000000..a0c4525af
--- /dev/null
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/ProtocolConnectionCollection.java
@@ -0,0 +1,96 @@
+/*
+ * The MIT License
+ * Copyright (c) 2012 Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.eischet.ews.api.autodiscover;
+
+import com.eischet.ews.api.core.EwsXmlReader;
+import com.eischet.ews.api.core.XmlElementNames;
+import com.eischet.ews.api.core.enumeration.misc.XmlNamespace;
+import com.eischet.ews.api.security.XmlNodeType;
+
+import java.util.ArrayList;
+
+/**
+ * Represents a user setting that is a collection of protocol connection.
+ */
+public final class ProtocolConnectionCollection {
+
+ /**
+ * The connections.
+ */
+ private ArrayList connections;
+
+ /**
+ * Initializes a new instance of the class.
+ */
+ ProtocolConnectionCollection() {
+ this.connections = new ArrayList();
+ }
+
+ /**
+ * Read user setting with ProtocolConnectionCollection value.
+ *
+ * @param reader EwsServiceXmlReader
+ * @return the protocol connection collection
+ * @throws Exception the exception
+ */
+ public static ProtocolConnectionCollection loadFromXml(final EwsXmlReader reader)
+ throws Exception {
+ final ProtocolConnectionCollection value = new ProtocolConnectionCollection();
+
+ do {
+ reader.read();
+
+ if (reader.getNodeType().getNodeType() == XmlNodeType.START_ELEMENT) {
+ if (reader.getLocalName().equals(XmlElementNames.ProtocolConnection)) {
+ final ProtocolConnection connection = ProtocolConnection.loadFromXml(reader);
+ if (connection != null) {
+ value.getConnections().add(connection);
+ }
+ }
+ }
+ } while (!reader.isEndElement(XmlNamespace.Autodiscover,
+ XmlElementNames.ProtocolConnections));
+
+ return value;
+ }
+
+ /**
+ * Gets the Connections.
+ *
+ * @return the connections
+ */
+ public ArrayList getConnections() {
+ return this.connections;
+ }
+
+ /**
+ * Sets the connections.
+ *
+ * @param value the new connections
+ */
+ void setConnections(ArrayList value) {
+ this.connections = value;
+ }
+}
diff --git a/ews-api/src/main/java/com/eischet/ews/api/autodiscover/WebClientUrl.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/WebClientUrl.java
new file mode 100644
index 000000000..a592495d4
--- /dev/null
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/WebClientUrl.java
@@ -0,0 +1,129 @@
+/*
+ * The MIT License
+ * Copyright (c) 2012 Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.eischet.ews.api.autodiscover;
+
+import com.eischet.ews.api.core.EwsXmlReader;
+import com.eischet.ews.api.core.XmlElementNames;
+import com.eischet.ews.api.core.enumeration.misc.XmlNamespace;
+import com.eischet.ews.api.security.XmlNodeType;
+
+/**
+ * Represents the URL of the Exchange web client.
+ */
+public final class WebClientUrl {
+
+ /**
+ * The authentication methods.
+ */
+ private String authenticationMethods;
+
+ /**
+ * The url.
+ */
+ private String url;
+
+ /**
+ * Initializes a new instance of the class.
+ */
+ private WebClientUrl() {
+ }
+
+ /**
+ * Initializes a new instance of the WebClientUrl class.
+ *
+ * @param authenticationMethods The authentication methods.
+ * @param url The URL.
+ */
+ public WebClientUrl(String authenticationMethods, String url) {
+ this.authenticationMethods = authenticationMethods;
+ this.url = url;
+ }
+
+
+ /**
+ * Loads WebClientUrl instance from XML.
+ *
+ * @param reader The reader.
+ * @return WebClientUrl.
+ * @throws Exception the exception
+ */
+ protected static WebClientUrl loadFromXml(EwsXmlReader reader)
+ throws Exception {
+ WebClientUrl webClientUrl = new WebClientUrl();
+
+ do {
+ reader.read();
+
+ if (reader.getNodeType().getNodeType() == XmlNodeType.START_ELEMENT) {
+ if (reader.getLocalName().equals(
+ XmlElementNames.AuthenticationMethods)) {
+ webClientUrl.setAuthenticationMethods(reader
+ .readElementValue(String.class));
+ } else if (reader.getLocalName().equals(XmlElementNames.Url)) {
+ webClientUrl.setUrl(reader.readElementValue(String.class));
+ }
+ }
+ } while (!reader.isEndElement(XmlNamespace.Autodiscover,
+ XmlElementNames.WebClientUrl));
+
+ return webClientUrl;
+ }
+
+ /**
+ * Gets the authentication methods.
+ *
+ * @return the authentication methods
+ */
+ public String getAuthenticationMethods() {
+ return this.authenticationMethods;
+ }
+
+ /**
+ * Sets the authentication methods.
+ *
+ * @param value the new authentication methods
+ */
+ protected void setAuthenticationMethods(String value) {
+ this.authenticationMethods = value;
+ }
+
+ /**
+ * Gets the URL.
+ *
+ * @return the url
+ */
+ public String getUrl() {
+ return this.url;
+ }
+
+ /**
+ * Sets the url.
+ *
+ * @param value the new url
+ */
+ protected void setUrl(String value) {
+ this.url = value;
+ }
+
+}
diff --git a/ews-api/src/main/java/com/eischet/ews/api/autodiscover/WebClientUrlCollection.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/WebClientUrlCollection.java
new file mode 100644
index 000000000..40d1f6104
--- /dev/null
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/WebClientUrlCollection.java
@@ -0,0 +1,84 @@
+/*
+ * The MIT License
+ * Copyright (c) 2012 Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.eischet.ews.api.autodiscover;
+
+import com.eischet.ews.api.core.EwsXmlReader;
+import com.eischet.ews.api.core.XmlElementNames;
+import com.eischet.ews.api.core.enumeration.misc.XmlNamespace;
+import com.eischet.ews.api.security.XmlNodeType;
+
+import java.util.ArrayList;
+
+/**
+ * Represents a user setting that is a collection of Exchange web client URLs.
+ */
+public final class WebClientUrlCollection {
+
+ /**
+ * The urls.
+ */
+ private final ArrayList urls;
+
+ /**
+ * Initializes a new instance of the {@link WebClientUrlCollection} class.
+ */
+ public WebClientUrlCollection() {
+ this.urls = new ArrayList();
+ }
+
+ /**
+ * Loads instance of WebClientUrlCollection from XML.
+ *
+ * @param reader The reader.
+ * @return the web client url collection
+ * @throws Exception the exception
+ */
+ public static WebClientUrlCollection loadFromXml(EwsXmlReader reader)
+ throws Exception {
+ WebClientUrlCollection instance = new WebClientUrlCollection();
+
+ do {
+ reader.read();
+
+ if ((reader.getNodeType().getNodeType() == XmlNodeType.START_ELEMENT) &&
+ (reader.getLocalName()
+ .equals(XmlElementNames.WebClientUrl))) {
+ instance.getUrls().add(WebClientUrl.loadFromXml(reader));
+ }
+ } while (!reader.isEndElement(XmlNamespace.Autodiscover,
+ XmlElementNames.WebClientUrls));
+
+ return instance;
+ }
+
+ /**
+ * Gets the URLs.
+ *
+ * @return the urls
+ */
+ public ArrayList getUrls() {
+ return this.urls;
+
+ }
+}
diff --git a/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/ConfigurationSettingsBase.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/ConfigurationSettingsBase.java
new file mode 100644
index 000000000..e2bb641dc
--- /dev/null
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/ConfigurationSettingsBase.java
@@ -0,0 +1,149 @@
+/*
+ * The MIT License
+ * Copyright (c) 2012 Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.eischet.ews.api.autodiscover.configuration;
+
+import com.eischet.ews.api.attribute.EditorBrowsable;
+import com.eischet.ews.api.autodiscover.enumeration.AutodiscoverResponseType;
+import com.eischet.ews.api.autodiscover.enumeration.UserSettingName;
+import com.eischet.ews.api.autodiscover.exception.error.AutodiscoverError;
+import com.eischet.ews.api.autodiscover.response.GetUserSettingsResponse;
+import com.eischet.ews.api.core.EwsXmlReader;
+import com.eischet.ews.api.core.XmlElementNames;
+import com.eischet.ews.api.core.enumeration.attribute.EditorBrowsableState;
+import com.eischet.ews.api.core.enumeration.misc.XmlNamespace;
+
+import java.net.URI;
+import java.util.List;
+
+/**
+ * Represents the base class for configuration settings.
+ */
+@EditorBrowsable(state = EditorBrowsableState.Never)
+public abstract class ConfigurationSettingsBase {
+
+ /**
+ * The error.
+ */
+ private AutodiscoverError error;
+
+ /**
+ * Initializes a new instance of the ConfigurationSettingsBase class.
+ */
+ public ConfigurationSettingsBase() {
+ }
+
+ /**
+ * Tries to read the current XML element.
+ *
+ * @param reader the reader
+ * @return True is the current element was read, false otherwise.
+ * @throws Exception the exception
+ */
+ public boolean tryReadCurrentXmlElement(EwsXmlReader reader)
+ throws Exception {
+ if (reader.getLocalName().equalsIgnoreCase(XmlElementNames.Error)) {
+ this.error = AutodiscoverError.parse(reader);
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Loads the settings from XML.
+ *
+ * @param reader the reader
+ * @throws Exception the exception
+ */
+ public void loadFromXml(EwsXmlReader reader) throws Exception {
+ reader.readStartElement(XmlNamespace.NotSpecified,
+ XmlElementNames.Autodiscover);
+ reader.readStartElement(XmlNamespace.NotSpecified,
+ XmlElementNames.Response);
+
+ do {
+ reader.read();
+
+ if (reader.isStartElement()) {
+ if (!this.tryReadCurrentXmlElement(reader)) {
+ reader.skipCurrentElement();
+ }
+ }
+ } while (!reader.isEndElement(XmlNamespace.NotSpecified,
+ XmlElementNames.Response));
+
+ reader.readEndElement(XmlNamespace.NotSpecified,
+ XmlElementNames.Autodiscover);
+ }
+
+ /**
+ * Gets the namespace that defines the settings.
+ *
+ * @return The namespace that defines the settings
+ */
+ public abstract String getNamespace();
+
+ /**
+ * Makes this instance a redirection response.
+ *
+ * @param redirectUrl the redirect url
+ */
+ public abstract void makeRedirectionResponse(URI redirectUrl);
+
+ /**
+ * Gets the type of the response.
+ *
+ * @return The type of the response.
+ */
+ public abstract AutodiscoverResponseType getResponseType();
+
+ /**
+ * Gets the redirect target.
+ *
+ * @return The redirect target.
+ */
+ public abstract String getRedirectTarget();
+
+ /**
+ * Convert ConfigurationSettings to GetUserSettings response.
+ *
+ * @param smtpAddress SMTP address.
+ * @param requestedSettings The requested settings.
+ * @return GetUserSettingsResponse.
+ */
+ public abstract GetUserSettingsResponse convertSettings(
+ String smtpAddress,
+ List requestedSettings);
+
+
+ /**
+ * Gets the error.
+ *
+ * @return The error.
+ */
+ public AutodiscoverError getError() {
+ return this.error;
+ }
+}
diff --git a/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/outlook/OutlookAccount.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/outlook/OutlookAccount.java
new file mode 100644
index 000000000..8f476dbb3
--- /dev/null
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/outlook/OutlookAccount.java
@@ -0,0 +1,208 @@
+/*
+ * The MIT License
+ * Copyright (c) 2012 Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.eischet.ews.api.autodiscover.configuration.outlook;
+
+import com.eischet.ews.api.attribute.EditorBrowsable;
+import com.eischet.ews.api.autodiscover.AlternateMailbox;
+import com.eischet.ews.api.autodiscover.AlternateMailboxCollection;
+import com.eischet.ews.api.autodiscover.enumeration.AutodiscoverResponseType;
+import com.eischet.ews.api.autodiscover.enumeration.OutlookProtocolType;
+import com.eischet.ews.api.autodiscover.enumeration.UserSettingName;
+import com.eischet.ews.api.autodiscover.response.GetUserSettingsResponse;
+import com.eischet.ews.api.core.EwsXmlReader;
+import com.eischet.ews.api.core.XmlElementNames;
+import com.eischet.ews.api.core.enumeration.attribute.EditorBrowsableState;
+import com.eischet.ews.api.core.enumeration.misc.XmlNamespace;
+import com.eischet.ews.api.security.XmlNodeType;
+
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Represents an Outlook configuration settings account.
+ */
+@EditorBrowsable(state = EditorBrowsableState.Never)
+final class OutlookAccount {
+
+ //region Private constants
+ /**
+ * The Constant Settings.
+ */
+ private final static String Settings = "settings";
+
+ /**
+ * The Constant RedirectAddr.
+ */
+ private final static String RedirectAddr = "redirectAddr";
+
+ /**
+ * The Constant RedirectUrl.
+ */
+ private final static String RedirectUrl = "redirectUrl";
+ //endRegion
+
+ private String accountType;
+ private AutodiscoverResponseType responseType;
+
+ //region Private fields
+ /**
+ * The protocols.
+ */
+ private final HashMap protocols;
+ private final AlternateMailboxCollection alternateMailboxes;
+ private String redirectTarget;
+ //endRegion
+
+ /**
+ * Initializes a new instance of the OutlookAccount class.
+ */
+ protected OutlookAccount() {
+ this.protocols = new HashMap();
+ this.alternateMailboxes = new AlternateMailboxCollection();
+ }
+
+ /**
+ * Parses the specified reader.
+ *
+ * @param reader The reader.
+ * @throws Exception the exception
+ */
+ protected void loadFromXml(EwsXmlReader reader)
+ throws Exception {
+
+ do {
+ reader.read();
+
+ if (reader.getNodeType().getNodeType() == XmlNodeType.START_ELEMENT) {
+ if (reader.getLocalName().equals(XmlElementNames.AccountType)) {
+ this.setAccountType(reader.readElementValue());
+ } else if (reader.getLocalName().equals(XmlElementNames.Action)) {
+ String xmlResponseType = reader.readElementValue();
+ if (xmlResponseType.equals(OutlookAccount.Settings)) {
+ this.setResponseType(AutodiscoverResponseType.Success);
+ } else if (xmlResponseType
+ .equals(OutlookAccount.RedirectUrl)) {
+ this.setResponseType(AutodiscoverResponseType.
+ RedirectUrl);
+ } else if (xmlResponseType
+ .equals(OutlookAccount.RedirectAddr)) {
+ this.setResponseType(
+ AutodiscoverResponseType.RedirectAddress);
+ } else {
+ this.setResponseType(AutodiscoverResponseType.Error);
+ }
+
+ } else if (reader.getLocalName().equals(
+ XmlElementNames.Protocol)) {
+ OutlookProtocol protocol = new OutlookProtocol();
+ protocol.loadFromXml(reader);
+ this.protocols.put(
+ protocol.getProtocolType(), protocol);
+ } else if (reader.getLocalName().equals(
+ XmlElementNames.RedirectAddr)) {
+ this.setRedirectTarget(reader.readElementValue());
+ } else if (reader.getLocalName().equals(
+ XmlElementNames.RedirectUrl)) {
+ this.setRedirectTarget(reader.readElementValue());
+ } else if (reader.getLocalName().equals(
+ XmlElementNames.AlternateMailboxes)) {
+ AlternateMailbox alternateMailbox = AlternateMailbox.
+ loadFromXml(reader);
+ this.alternateMailboxes.getEntries().add(alternateMailbox);
+ } else {
+ reader.skipCurrentElement();
+ }
+ }
+ } while (!reader.isEndElement(XmlNamespace.NotSpecified,
+ XmlElementNames.Account));
+ }
+
+ /**
+ * Gets the type of the account.
+ */
+ protected void convertToUserSettings(List requestedSettings,
+ GetUserSettingsResponse response) {
+ for (OutlookProtocol protocol : this.protocols.values()) {
+ protocol.convertToUserSettings(requestedSettings, response);
+ }
+
+ if (requestedSettings.contains(UserSettingName.AlternateMailboxes)) {
+ response.getSettings().put(UserSettingName.
+ AlternateMailboxes, this.alternateMailboxes);
+ }
+ }
+
+ /**
+ * Gets the type of the account.
+ *
+ * @return the account type
+ */
+ protected String getAccountType() {
+ return accountType;
+ }
+
+ /**
+ * Gets the type of the account.
+ */
+ protected void setAccountType(String value) {
+ this.accountType = value;
+ }
+
+ /**
+ * Gets the type of the response.
+ *
+ * @return the response type
+ */
+ protected AutodiscoverResponseType getResponseType() {
+ return responseType;
+ }
+
+ /**
+ * Sets the response type.
+ *
+ * @param value the new response type
+ */
+ protected void setResponseType(AutodiscoverResponseType value) {
+ this.responseType = value;
+ }
+
+ /**
+ * Gets the redirect target.
+ *
+ * @return the redirect target
+ */
+ protected String getRedirectTarget() {
+ return redirectTarget;
+
+ }
+
+ /**
+ * Sets the redirect target.
+ *
+ * @param value the new redirect target
+ */
+ protected void setRedirectTarget(String value) {
+ this.redirectTarget = value;
+ }
+}
diff --git a/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/outlook/OutlookConfigurationSettings.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/outlook/OutlookConfigurationSettings.java
new file mode 100644
index 000000000..889ecef87
--- /dev/null
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/outlook/OutlookConfigurationSettings.java
@@ -0,0 +1,249 @@
+/*
+ * The MIT License
+ * Copyright (c) 2012 Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.eischet.ews.api.autodiscover.configuration.outlook;
+
+import com.eischet.ews.api.autodiscover.configuration.ConfigurationSettingsBase;
+import com.eischet.ews.api.autodiscover.enumeration.AutodiscoverErrorCode;
+import com.eischet.ews.api.autodiscover.enumeration.AutodiscoverResponseType;
+import com.eischet.ews.api.autodiscover.enumeration.UserSettingName;
+import com.eischet.ews.api.autodiscover.exception.error.UserSettingError;
+import com.eischet.ews.api.autodiscover.response.GetUserSettingsResponse;
+import com.eischet.ews.api.core.*;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents Outlook configuration settings.
+ */
+public final class OutlookConfigurationSettings extends ConfigurationSettingsBase {
+
+ /**
+ * All user settings that are available from the Outlook provider.
+ */
+ private static final LazyMember>
+ allOutlookProviderSettings = new LazyMember>(
+ new ILazyMember>() {
+ public List createInstance() {
+
+ List results =
+ new ArrayList();
+ for (UserSettingName userSettingName : OutlookUser.getAvailableUserSettings()) {
+ results.add(userSettingName);
+ }
+ results.addAll(OutlookProtocol.getAvailableUserSettings());
+ results.add(UserSettingName.AlternateMailboxes);
+ return results;
+ }
+ });
+
+
+ /**
+ * The user.
+ */
+ private final OutlookUser user;
+
+ /**
+ * The account.
+ */
+ private OutlookAccount account;
+
+ /**
+ * Initializes a new instance of the OutlookConfigurationSettings class.
+ */
+ public OutlookConfigurationSettings() {
+ this.user = new OutlookUser();
+ this.account = new OutlookAccount();
+ }
+
+ /**
+ * Determines whether user setting is available in the
+ * OutlookConfiguration or not.
+ *
+ * @param setting The setting.
+ * @return True if user setting is available, otherwise, false.
+ */
+ protected static boolean isAvailableUserSetting(UserSettingName setting) {
+ return allOutlookProviderSettings.getMember().contains(setting);
+ }
+
+ /**
+ * Gets the namespace that defines the settings.
+ *
+ * @return The namespace that defines the settings.
+ */
+ @Override
+ public String getNamespace() {
+ return "http://schemas.microsoft.com/exchange/" +
+ "autodiscover/outlook/responseschema/2006a";
+ }
+
+ /**
+ * Makes this instance a redirection response.
+ *
+ * @param redirectUrl The redirect URL.
+ */
+ @Override
+ public void makeRedirectionResponse(URI redirectUrl) {
+ this.account = new OutlookAccount();
+ this.account.setRedirectTarget(redirectUrl.toString());
+ this.account.setResponseType(AutodiscoverResponseType.RedirectUrl);
+ }
+
+ /**
+ * Tries to read the current XML element.
+ *
+ * @param reader the reader
+ * @return true is the current element was read, false otherwise
+ * @throws Exception the exception
+ */
+ @Override
+ public boolean tryReadCurrentXmlElement(EwsXmlReader reader) throws Exception {
+ if (!super.tryReadCurrentXmlElement(reader)) {
+ if (reader.getLocalName().equals(XmlElementNames.User)) {
+ this.user.loadFromXml(reader);
+ return true;
+ } else if (reader.getLocalName().equals(XmlElementNames.Account)) {
+ this.account.loadFromXml(reader);
+ return true;
+ } else {
+ reader.skipCurrentElement();
+ return false;
+ }
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Convert OutlookConfigurationSettings to GetUserSettings response.
+ *
+ * @param smtpAddress SMTP address requested.
+ * @param requestedSettings The requested settings.
+ * @return GetUserSettingsResponse
+ */
+ @Override
+ public GetUserSettingsResponse convertSettings(String smtpAddress,
+ List requestedSettings) {
+ GetUserSettingsResponse response = new GetUserSettingsResponse();
+ response.setSmtpAddress(smtpAddress);
+
+ if (this.getError() != null) {
+ response.setErrorCode(AutodiscoverErrorCode.InternalServerError);
+ response.setErrorMessage(this.getError().getMessage());
+ } else {
+ switch (this.getResponseType()) {
+ case Success:
+ response.setErrorCode(AutodiscoverErrorCode.NoError);
+ response.setErrorMessage("");
+ this.user.convertToUserSettings(requestedSettings, response);
+ this.account.convertToUserSettings(requestedSettings, response);
+ this.reportUnsupportedSettings(requestedSettings, response);
+ break;
+ case Error:
+ response.setErrorCode(AutodiscoverErrorCode.InternalServerError);
+ response.setErrorMessage("The Autodiscover service response was invalid.");
+ break;
+ case RedirectAddress:
+ response.setErrorCode(AutodiscoverErrorCode.RedirectAddress);
+ response.setErrorMessage("");
+ response.setRedirectTarget(this.getRedirectTarget());
+ break;
+ case RedirectUrl:
+ response.setErrorCode(AutodiscoverErrorCode.RedirectUrl);
+ response.setErrorMessage("");
+ response.setRedirectTarget(this.getRedirectTarget());
+ break;
+ default:
+ EwsUtilities.ewsAssert(false, "OutlookConfigurationSettings.ConvertSettings",
+ "An unexpected error has occured. "
+ + "This code path should never be reached.");
+ break;
+ }
+ }
+ return response;
+ }
+
+ /**
+ * Reports any requested user settings that aren't
+ * supported by the Outlook provider.
+ *
+ * @param requestedSettings The requested settings.
+ * @param response The response.
+ */
+ private void reportUnsupportedSettings(List requestedSettings,
+ GetUserSettingsResponse response) {
+ // In English: find settings listed in requestedSettings that are not supported by the Legacy provider.
+
+ //TODO need to check Iterable
+ List invalidSettingQuery =
+ new ArrayList();
+ for (UserSettingName userSettingName : requestedSettings) {
+ if (!OutlookConfigurationSettings.isAvailableUserSetting(userSettingName)) {
+ invalidSettingQuery.add(userSettingName);
+ }
+ }
+ /* from setting in requestedSettings
+ where !OutlookConfigurationSettings.IsAvailableUserSetting(setting)
+ select setting;*/
+
+ // Add any unsupported settings to the UserSettingsError collection.
+ for (UserSettingName invalidSetting : invalidSettingQuery) {
+ UserSettingError settingError = new UserSettingError();
+ settingError.setErrorCode(AutodiscoverErrorCode.InvalidSetting);
+ settingError.setSettingName(invalidSetting.toString());
+ settingError.setErrorMessage(String.format(
+ "The requested setting, '%s', isn't supported by this Autodiscover endpoint.",
+ invalidSetting));
+ response.getUserSettingErrors().add(settingError);
+ }
+ }
+
+ /**
+ * Gets the type of the response.
+ *
+ * @return The type of the response.
+ */
+ @Override
+ public AutodiscoverResponseType getResponseType() {
+ if (this.account != null) {
+ return this.account.getResponseType();
+ } else {
+ return AutodiscoverResponseType.Error;
+ }
+ }
+
+ /**
+ * Gets the redirect target.
+ *
+ * @return String
+ * the redirect target.
+ */
+ @Override
+ public String getRedirectTarget() {
+ return this.account.getRedirectTarget();
+ }
+
+}
diff --git a/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/outlook/OutlookProtocol.java b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/outlook/OutlookProtocol.java
new file mode 100644
index 000000000..2c7c02037
--- /dev/null
+++ b/ews-api/src/main/java/com/eischet/ews/api/autodiscover/configuration/outlook/OutlookProtocol.java
@@ -0,0 +1,808 @@
+/*
+ * The MIT License
+ * Copyright (c) 2012 Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.eischet.ews.api.autodiscover.configuration.outlook;
+
+import com.eischet.ews.api.attribute.EditorBrowsable;
+import com.eischet.ews.api.autodiscover.IFunc;
+import com.eischet.ews.api.autodiscover.WebClientUrl;
+import com.eischet.ews.api.autodiscover.WebClientUrlCollection;
+import com.eischet.ews.api.autodiscover.enumeration.OutlookProtocolType;
+import com.eischet.ews.api.autodiscover.enumeration.UserSettingName;
+import com.eischet.ews.api.autodiscover.response.GetUserSettingsResponse;
+import com.eischet.ews.api.core.*;
+import com.eischet.ews.api.core.enumeration.attribute.EditorBrowsableState;
+import com.eischet.ews.api.core.enumeration.misc.XmlNamespace;
+import com.eischet.ews.api.security.XmlNodeType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * Represents a supported Outlook protocol in an Outlook configurations settings
+ * account.
+ */
+@EditorBrowsable(state = EditorBrowsableState.Never)
+final class OutlookProtocol {
+
+ /**
+ * The Constant EXCH.
+ */
+ private final static String EXCH = "EXCH";
+
+ /**
+ * The Constant EXPR.
+ */
+ private final static String EXPR = "EXPR";
+
+ /**
+ * The Constant WEB.
+ */
+ private final static String WEB = "WEB";
+
+ /**
+ * Converters to translate common Outlook protocol settings.
+ * Each entry maps to a lambda expression used to
+ * get the matching property from the OutlookProtocol instance.
+ */
+ private static final LazyMember