microsoft.exchange.webservices.data.core
Class ExchangeServiceBase

java.lang.Object
  extended by microsoft.exchange.webservices.data.core.ExchangeServiceBase
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
AutodiscoverService, ExchangeService

public abstract class ExchangeServiceBase
extends Object
implements Closeable

Represents an abstract binding to an Exchange Service.


Field Summary
protected  org.apache.http.impl.client.CloseableHttpClient httpClient
           
protected  org.apache.http.client.protocol.HttpClientContext httpContext
           
protected  org.apache.http.impl.client.CloseableHttpClient httpPoolingClient
           
 
Constructor Summary
protected ExchangeServiceBase()
          Initializes a new instance.
protected ExchangeServiceBase(ExchangeServiceBase service, ExchangeVersion requestedServerVersion)
           
protected ExchangeServiceBase(ExchangeVersion requestedServerVersion)
           
 
Method Summary
static boolean checkURIPath(String location)
           
 void close()
           
 String convertDateTimeToUniversalDateTimeString(Date dt)
          Converts the date time to universal date time string.
protected  org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> createConnectionSocketFactoryRegistry()
          Create registry with configured ConnectionSocketFactory instances.
 void doOnSerializeCustomSoapHeaders(XMLStreamWriter writer)
          Calls the custom SOAP header serialisation event handlers, if defined.
 boolean getAcceptGzipEncoding()
          Gets a value indicating whether GZip compression encoding should be accepted.
 ExchangeCredentials getCredentials()
          Gets the credential used to authenticate with the Exchange Web Services.
 Map<String,String> getHttpHeaders()
          Gets a collection of HTTP headers that will be sent with each request to EWS.
 Map<String,String> getHttpResponseHeaders()
          Gets a collection of HTTP headers from the last response.
 List<ICustomXmlSerialization> getOnSerializeCustomSoapHeaders()
          Gets the on serialize custom soap headers.
 ExchangeVersion getRequestedServerVersion()
          Gets the requested server version.
 ExchangeServerInfo getServerInfo()
          Gets information associated with the server that processed the last request.
static byte[] getSessionKey()
          Gets the session key.
 int getTimeout()
          Gets the timeout used when sending HTTP request and when receiving HTTP response, in milliseconds.
 EnumSet<TraceFlags> getTraceFlags()
          Gets the trace flags.
 ITraceListener getTraceListener()
          Gets the trace listener.
 boolean getUseDefaultCredentials()
          Gets a value indicating whether the credential of the user currently logged into Windows should be used to authenticate with the Exchange Web Services.
 String getUserAgent()
          Gets the user agent.
 WebProxy getWebProxy()
          Gets the web proxy that should be used when sending request to EWS.
protected  void internalProcessHttpErrorResponse(HttpWebRequest httpWebResponse, Exception webException, TraceFlags responseHeadersTraceFlag, TraceFlags responseTraceFlag)
          This method doesn't handle 500 ISE errors.
 boolean isPreAuthenticate()
          Gets a value that indicates whether HTTP pre-authentication should be performed.
 boolean isTraceEnabled()
          Gets a value indicating whether tracing is enabled.
 boolean isTraceEnabledFor(TraceFlags traceFlags)
          Determines whether tracing is enabled for specified trace flag(s).
protected  void prepareCredentials(HttpWebRequest request)
           
protected  HttpWebRequest prepareHttpPoolingWebRequestForUrl(URI url, boolean acceptGzipEncoding, boolean allowAutoRedirect)
          Creates an HttpWebRequest instance from a pooling connection manager and initialises it with the appropriate parameters, based on the configuration of this service object.
protected  HttpWebRequest prepareHttpWebRequestForUrl(URI url, boolean acceptGzipEncoding, boolean allowAutoRedirect)
          Creates an HttpWebRequest instance and initialises it with the appropriate parameters, based on the configuration of this service object.
protected abstract  void processHttpErrorResponse(HttpWebRequest httpWebResponse, Exception webException)
           
 void processHttpResponseHeaders(TraceFlags traceType, HttpWebRequest request)
          Traces the HTTP response headers.
 void setAcceptGzipEncoding(boolean acceptGzipEncoding)
          Gets a value indicating whether GZip compression encoding should be accepted.
 void setCredentials(ExchangeCredentials credentials)
          Sets the credential used to authenticate with the Exchange Web Services.
protected  void setCustomUserAgent(String userAgent)
          Sets the user agent to a custom value
 void setMaximumPoolingConnections(int maximumPoolingConnections)
          Sets the maximum number of connections for the pooling connection manager which is used for subscriptions.
 void setOnSerializeCustomSoapHeaders(List<ICustomXmlSerialization> onSerializeCustomSoapHeaders)
          Sets the on serialize custom soap headers.
 void setPreAuthenticate(boolean preAuthenticate)
          Sets a value that indicates whether HTTP pre-authentication should be performed.
 void setServerInfo(ExchangeServerInfo serverInfo)
          Sets information associated with the server that processed the last request.
 void setTimeout(int timeout)
          Sets the timeout used when sending HTTP request and when receiving HTTP respones, in milliseconds.
 void setTraceEnabled(boolean traceEnabled)
          Sets a value indicating whether tracing is enabled.
 void setTraceFlags(EnumSet<TraceFlags> traceFlags)
          Sets the trace flags.
 void setTraceListener(ITraceListener traceListener)
          Sets the trace listener.
 void setUseDefaultCredentials(boolean value)
          Sets a value indicating whether the credential of the user currently logged into Windows should be used to authenticate with the Exchange Web Services.
 void setUserAgent(String userAgent)
          Sets the user agent.
 void setWebProxy(WebProxy value)
          Sets the web proxy that should be used when sending request to EWS.
 void traceHttpRequestHeaders(TraceFlags traceType, HttpWebRequest request)
          Traces the HTTP request headers.
 void traceMessage(TraceFlags traceType, String logEntry)
          Logs the specified string to the TraceListener if tracing is enabled.
 void traceXml(TraceFlags traceType, ByteArrayOutputStream stream)
          Logs the specified XML to the TraceListener if tracing is enabled.
 void validate()
          Validates this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

httpClient

protected org.apache.http.impl.client.CloseableHttpClient httpClient

httpContext

protected org.apache.http.client.protocol.HttpClientContext httpContext

httpPoolingClient

protected org.apache.http.impl.client.CloseableHttpClient httpPoolingClient
Constructor Detail

ExchangeServiceBase

protected ExchangeServiceBase()
Initializes a new instance. This constructor performs the initialization of the HTTP connection manager, so it should be called by every other constructor.


ExchangeServiceBase

protected ExchangeServiceBase(ExchangeVersion requestedServerVersion)

ExchangeServiceBase

protected ExchangeServiceBase(ExchangeServiceBase service,
                              ExchangeVersion requestedServerVersion)
Method Detail

setMaximumPoolingConnections

public void setMaximumPoolingConnections(int maximumPoolingConnections)
Sets the maximum number of connections for the pooling connection manager which is used for subscriptions.

Default is 10.

Parameters:
maximumPoolingConnections - Maximum number of pooling connections

createConnectionSocketFactoryRegistry

protected org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> createConnectionSocketFactoryRegistry()
Create registry with configured ConnectionSocketFactory instances. Override this method to change how to work with different schemas.

Returns:
registry object

close

public void close()
Specified by:
close in interface Closeable

doOnSerializeCustomSoapHeaders

public void doOnSerializeCustomSoapHeaders(XMLStreamWriter writer)
Calls the custom SOAP header serialisation event handlers, if defined.

Parameters:
writer - The XmlWriter to which to write the custom SOAP headers.

prepareHttpWebRequestForUrl

protected HttpWebRequest prepareHttpWebRequestForUrl(URI url,
                                                     boolean acceptGzipEncoding,
                                                     boolean allowAutoRedirect)
                                              throws ServiceLocalException,
                                                     URISyntaxException
Creates an HttpWebRequest instance and initialises it with the appropriate parameters, based on the configuration of this service object.

Parameters:
url - The URL that the HttpWebRequest should target.
acceptGzipEncoding - If true, ask server for GZip compressed content.
allowAutoRedirect - If true, redirection response will be automatically followed.
Returns:
An initialised instance of HttpWebRequest.
Throws:
ServiceLocalException - the service local exception
URISyntaxException - the uRI syntax exception

prepareHttpPoolingWebRequestForUrl

protected HttpWebRequest prepareHttpPoolingWebRequestForUrl(URI url,
                                                            boolean acceptGzipEncoding,
                                                            boolean allowAutoRedirect)
                                                     throws ServiceLocalException,
                                                            URISyntaxException
Creates an HttpWebRequest instance from a pooling connection manager and initialises it with the appropriate parameters, based on the configuration of this service object.

This is used for subscriptions.

Parameters:
url - The URL that the HttpWebRequest should target.
acceptGzipEncoding - If true, ask server for GZip compressed content.
allowAutoRedirect - If true, redirection response will be automatically followed.
Returns:
An initialised instance of HttpWebRequest.
Throws:
ServiceLocalException - the service local exception
URISyntaxException - the uRI syntax exception

prepareCredentials

protected void prepareCredentials(HttpWebRequest request)
                           throws ServiceLocalException,
                                  URISyntaxException
Throws:
ServiceLocalException
URISyntaxException

internalProcessHttpErrorResponse

protected void internalProcessHttpErrorResponse(HttpWebRequest httpWebResponse,
                                                Exception webException,
                                                TraceFlags responseHeadersTraceFlag,
                                                TraceFlags responseTraceFlag)
                                         throws Exception
This method doesn't handle 500 ISE errors. This is handled by the caller since 500 ISE typically indicates that a SOAP fault has occurred and the handling of a SOAP fault is currently service specific.

Parameters:
httpWebResponse - HTTP web response
webException - web exception
responseHeadersTraceFlag - trace flag for response headers
responseTraceFlag - trace flag for respone
Throws:
Exception - on error

checkURIPath

public static boolean checkURIPath(String location)
Parameters:
location - file path
Returns:
false if location is null,true if this abstract pathname is absolute

processHttpErrorResponse

protected abstract void processHttpErrorResponse(HttpWebRequest httpWebResponse,
                                                 Exception webException)
                                          throws Exception
Parameters:
httpWebResponse - HTTP web response
webException - web exception
Throws:
Exception - on error

isTraceEnabledFor

public boolean isTraceEnabledFor(TraceFlags traceFlags)
Determines whether tracing is enabled for specified trace flag(s).

Parameters:
traceFlags - The trace flags.
Returns:
True if tracing is enabled for specified trace flag(s).

traceMessage

public void traceMessage(TraceFlags traceType,
                         String logEntry)
                  throws XMLStreamException,
                         IOException
Logs the specified string to the TraceListener if tracing is enabled.

Parameters:
traceType - kind of trace entry
logEntry - the entry to log
Throws:
XMLStreamException - the XML stream exception
IOException - signals that an I/O exception has occurred

traceXml

public void traceXml(TraceFlags traceType,
                     ByteArrayOutputStream stream)
Logs the specified XML to the TraceListener if tracing is enabled.

Parameters:
traceType - Kind of trace entry.
stream - The stream containing XML.

traceHttpRequestHeaders

public void traceHttpRequestHeaders(TraceFlags traceType,
                                    HttpWebRequest request)
                             throws URISyntaxException,
                                    EWSHttpException,
                                    XMLStreamException,
                                    IOException
Traces the HTTP request headers.

Parameters:
traceType - Kind of trace entry.
request - The request
Throws:
EWSHttpException - EWS http exception
URISyntaxException - URI syntax error
IOException - signals that an I/O exception has occurred
XMLStreamException - the XML stream exception

convertDateTimeToUniversalDateTimeString

public String convertDateTimeToUniversalDateTimeString(Date dt)
Converts the date time to universal date time string.

Parameters:
dt - the date
Returns:
String representation of DateTime in yyyy-MM-ddTHH:mm:ssZ format.

setCustomUserAgent

protected void setCustomUserAgent(String userAgent)
Sets the user agent to a custom value

Parameters:
userAgent - User agent string to set on the service

validate

public void validate()
              throws ServiceLocalException
Validates this instance.

Throws:
ServiceLocalException - the service local exception

isTraceEnabled

public boolean isTraceEnabled()
Gets a value indicating whether tracing is enabled.

Returns:
True is tracing is enabled

setTraceEnabled

public void setTraceEnabled(boolean traceEnabled)
Sets a value indicating whether tracing is enabled.

Parameters:
traceEnabled - true to enable tracing

getTraceFlags

public EnumSet<TraceFlags> getTraceFlags()
Gets the trace flags.

Returns:
Set of trace flags.

setTraceFlags

public void setTraceFlags(EnumSet<TraceFlags> traceFlags)
Sets the trace flags.

Parameters:
traceFlags - A set of trace flags

getTraceListener

public ITraceListener getTraceListener()
Gets the trace listener.

Returns:
The trace listener.

setTraceListener

public void setTraceListener(ITraceListener traceListener)
Sets the trace listener.

Parameters:
traceListener - the trace listener.

getCredentials

public ExchangeCredentials getCredentials()
Gets the credential used to authenticate with the Exchange Web Services.

Returns:
credential

setCredentials

public void setCredentials(ExchangeCredentials credentials)
Sets the credential used to authenticate with the Exchange Web Services. Setting the Credentials property automatically sets the UseDefaultCredentials to false.

Parameters:
credentials - Exchange credential.

getUseDefaultCredentials

public boolean getUseDefaultCredentials()
Gets a value indicating whether the credential of the user currently logged into Windows should be used to authenticate with the Exchange Web Services.

Returns:
true if credential of the user currently logged in are used

setUseDefaultCredentials

public void setUseDefaultCredentials(boolean value)
Sets a value indicating whether the credential of the user currently logged into Windows should be used to authenticate with the Exchange Web Services. Setting UseDefaultCredentials to true automatically sets the Credentials property to null.

Parameters:
value - the new use default credential

getTimeout

public int getTimeout()
Gets the timeout used when sending HTTP request and when receiving HTTP response, in milliseconds.

Returns:
timeout in milliseconds

setTimeout

public void setTimeout(int timeout)
Sets the timeout used when sending HTTP request and when receiving HTTP respones, in milliseconds. Defaults to 100000.

Parameters:
timeout - timeout in milliseconds

isPreAuthenticate

public boolean isPreAuthenticate()
Gets a value that indicates whether HTTP pre-authentication should be performed.

Returns:
true indicates pre-authentication is set

setPreAuthenticate

public void setPreAuthenticate(boolean preAuthenticate)
Sets a value that indicates whether HTTP pre-authentication should be performed.

Parameters:
preAuthenticate - true to enable pre-authentication

getAcceptGzipEncoding

public boolean getAcceptGzipEncoding()
Gets a value indicating whether GZip compression encoding should be accepted. This value will tell the server that the client is able to handle GZip compression encoding. The server will only send Gzip compressed content if it has been configured to do so.

Returns:
true if compression is used

setAcceptGzipEncoding

public void setAcceptGzipEncoding(boolean acceptGzipEncoding)
Gets a value indicating whether GZip compression encoding should be accepted. This value will tell the server that the client is able to handle GZip compression encoding. The server will only send Gzip compressed content if it has been configured to do so.

Parameters:
acceptGzipEncoding - true to enable compression

getRequestedServerVersion

public ExchangeVersion getRequestedServerVersion()
Gets the requested server version.

Returns:
The requested server version.

getUserAgent

public String getUserAgent()
Gets the user agent.

Returns:
The user agent.

setUserAgent

public void setUserAgent(String userAgent)
Sets the user agent.

Parameters:
userAgent - The user agent

getServerInfo

public ExchangeServerInfo getServerInfo()
Gets information associated with the server that processed the last request. Will be null if no request have been processed.

Returns:
the server info

setServerInfo

public void setServerInfo(ExchangeServerInfo serverInfo)
Sets information associated with the server that processed the last request.

Parameters:
serverInfo - Server Information

getWebProxy

public WebProxy getWebProxy()
Gets the web proxy that should be used when sending request to EWS.

Returns:
Proxy the Proxy Information

setWebProxy

public void setWebProxy(WebProxy value)
Sets the web proxy that should be used when sending request to EWS. Set this property to null to use the default web proxy.

Parameters:
value - the Proxy Information

getHttpHeaders

public Map<String,String> getHttpHeaders()
Gets a collection of HTTP headers that will be sent with each request to EWS.

Returns:
httpHeaders

getOnSerializeCustomSoapHeaders

public List<ICustomXmlSerialization> getOnSerializeCustomSoapHeaders()
Gets the on serialize custom soap headers.

Returns:
the on serialize custom soap headers

setOnSerializeCustomSoapHeaders

public void setOnSerializeCustomSoapHeaders(List<ICustomXmlSerialization> onSerializeCustomSoapHeaders)
Sets the on serialize custom soap headers.

Parameters:
onSerializeCustomSoapHeaders - the new on serialize custom soap headers

processHttpResponseHeaders

public void processHttpResponseHeaders(TraceFlags traceType,
                                       HttpWebRequest request)
                                throws XMLStreamException,
                                       IOException,
                                       EWSHttpException
Traces the HTTP response headers.

Parameters:
traceType - kind of trace entry
request - The request
Throws:
EWSHttpException - EWS http exception
IOException - signals that an I/O exception has occurred
XMLStreamException - the XML stream exception

getHttpResponseHeaders

public Map<String,String> getHttpResponseHeaders()
Gets a collection of HTTP headers from the last response.

Returns:
HTTP response headers

getSessionKey

public static byte[] getSessionKey()
Gets the session key.

Returns:
session key


Copyright © 2012–2015 Microsoft. All rights reserved.