// Path: src/main/java/com/microsoft/exchange/impl/ExchangeOnlineThrottlingPolicy.java
// public class ExchangeOnlineThrottlingPolicy {
// 
// 	/**
// 	 * Indicates that there are more concurrent requests against the server than are allowed by a user's policy.
// 	 */
// 	public static final String ERROR_EXCEEDED_CONNECTION_COUNT = "ErrorExceededConnectionCount";
// 	/**
// 	 * Indicates that a user's throttling policy maximum subscription count has been exceeded.
// 	 */
// 	public static final String ERROR_EXCEEDED_SUBSCRIPTION_COUNT = "ErrorExceededSubscriptionCount";
// 	/**
// 	 * Indicates that a search operation call has exceeded the total number of items that can be returned.
// 	 */
// 	public static final String ERROR_EXCEEDED_FIND_COUNT_LIMIT = "ErrorExceededFindCountLimit";
// 	/**
// 	 * Occurs when the server is busy.
// 	 */
// 	public static final String ERROR_SERVER_BUSY = "ErrorServerBusy";
// 	/**
// 	 * The maximum number of entries returned for FindItem requests.
// 	 */
// 	public static final int FIND_ITEM_MAX_ENTRIES_RETURNED = 1000;
// 	/**
// 	 * The maximum number of concurrent connections for a service account using impersonation.
// 	 */
// 	public static final int MAX_CONCURRENT_CONNECTIONS_IMPERSONATION = 10;
// }


import org.apache.http.impl.auth.DigestScheme;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.pool.ConnPoolControl;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.springframework.ws.transport.http.HttpComponentsMessageSender;
import com.microsoft.exchange.impl.ExchangeOnlineThrottlingPolicy;
import java.net.URI;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthScope;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.auth.BasicScheme;
		this.preemptiveAuthScope = preemptiveAuthScope;
	}
	/**
	 * @return the credentialsProviderFactory
	 */
	public CredentialsProviderFactory getCredentialsProviderFactory() {
		return credentialsProviderFactory;
	}
	/**
	 * @param credentialsProviderFactory the credentialsProviderFactory to set
	 */
	public void setCredentialsProviderFactory(
			CredentialsProviderFactory credentialsProviderFactory) {
		this.credentialsProviderFactory = credentialsProviderFactory;
	}
	/* (non-Javadoc)
	 * @see org.springframework.ws.transport.http.HttpComponentsMessageSender#afterPropertiesSet()
	 */
	@Override
	public void afterPropertiesSet() throws Exception {
		super.afterPropertiesSet();
		if(isPreemptiveAuthEnabled()) {
			this.preemptiveAuthScheme = identifyScheme(getPreemptiveAuthScope().getScheme());
		}
		boolean overrideSuccess = false;
		if(defaultMaxPerRouteOverride != null) {
			overrideSuccess = this.overrideDefaultMaxPerRoute(defaultMaxPerRouteOverride);
		}
		
		if(overrideSuccess && defaultMaxPerRouteOverride > ExchangeOnlineThrottlingPolicy.MAX_CONCURRENT_CONNECTIONS_IMPERSONATION) {
// Path: src/main/java/com/microsoft/exchange/impl/ExchangeOnlineThrottlingPolicy.java
// public class ExchangeOnlineThrottlingPolicy {
// 
// 	/**
// 	 * Indicates that there are more concurrent requests against the server than are allowed by a user's policy.
// 	 */
// 	public static final String ERROR_EXCEEDED_CONNECTION_COUNT = "ErrorExceededConnectionCount";
// 	/**
// 	 * Indicates that a user's throttling policy maximum subscription count has been exceeded.
// 	 */
// 	public static final String ERROR_EXCEEDED_SUBSCRIPTION_COUNT = "ErrorExceededSubscriptionCount";
// 	/**
// 	 * Indicates that a search operation call has exceeded the total number of items that can be returned.
// 	 */
// 	public static final String ERROR_EXCEEDED_FIND_COUNT_LIMIT = "ErrorExceededFindCountLimit";
// 	/**
// 	 * Occurs when the server is busy.
// 	 */
// 	public static final String ERROR_SERVER_BUSY = "ErrorServerBusy";
// 	/**
// 	 * The maximum number of entries returned for FindItem requests.
// 	 */
// 	public static final int FIND_ITEM_MAX_ENTRIES_RETURNED = 1000;
// 	/**
// 	 * The maximum number of concurrent connections for a service account using impersonation.
// 	 */
// 	public static final int MAX_CONCURRENT_CONNECTIONS_IMPERSONATION = 10;
// }


// Path: src/main/java/com/microsoft/exchange/impl/http/CustomHttpComponentsMessageSender.java
import org.apache.http.impl.auth.DigestScheme;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.pool.ConnPoolControl;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.springframework.ws.transport.http.HttpComponentsMessageSender;
import com.microsoft.exchange.impl.ExchangeOnlineThrottlingPolicy;
import java.net.URI;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthScope;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.auth.BasicScheme;

		this.preemptiveAuthScope = preemptiveAuthScope;
	}
	/**
	 * @return the credentialsProviderFactory
	 */
	public CredentialsProviderFactory getCredentialsProviderFactory() {
		return credentialsProviderFactory;
	}
	/**
	 * @param credentialsProviderFactory the credentialsProviderFactory to set
	 */
	public void setCredentialsProviderFactory(
			CredentialsProviderFactory credentialsProviderFactory) {
		this.credentialsProviderFactory = credentialsProviderFactory;
	}
	/* (non-Javadoc)
	 * @see org.springframework.ws.transport.http.HttpComponentsMessageSender#afterPropertiesSet()
	 */
	@Override
	public void afterPropertiesSet() throws Exception {
		super.afterPropertiesSet();
		if(isPreemptiveAuthEnabled()) {
			this.preemptiveAuthScheme = identifyScheme(getPreemptiveAuthScope().getScheme());
		}
		boolean overrideSuccess = false;
		if(defaultMaxPerRouteOverride != null) {
			overrideSuccess = this.overrideDefaultMaxPerRoute(defaultMaxPerRouteOverride);
		}
		
		if(overrideSuccess && defaultMaxPerRouteOverride > ExchangeOnlineThrottlingPolicy.MAX_CONCURRENT_CONNECTIONS_IMPERSONATION) {
			logger.info("defaultMaxPerRoute is being set to " + defaultMaxPerRouteOverride + " which is in excess of ExchangeOnline's default throttling policy. You may experience regular failed requests when the limit for concurrent connections (" + ExchangeOnlineThrottlingPolicy.MAX_CONCURRENT_CONNECTIONS_IMPERSONATION + " for impersonation) is exceeded ");