Class ExchangeServiceBase
- java.lang.Object
-
- microsoft.exchange.webservices.data.core.ExchangeServiceBase
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
AutodiscoverService,ExchangeService
public abstract class ExchangeServiceBase extends Object implements Closeable
Represents an abstract binding to an Exchange Service.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanexternalHttpClientprotected booleanexternalHttpPoolingClientprotected org.apache.http.impl.client.CloseableHttpClienthttpClientprotected org.apache.http.client.protocol.HttpClientContexthttpContextprotected org.apache.http.impl.client.CloseableHttpClienthttpPoolingClient
-
Constructor Summary
Constructors Modifier Constructor Description protectedExchangeServiceBase()Initializes a new instance.protectedExchangeServiceBase(ExchangeVersion requestedServerVersion)protectedExchangeServiceBase(ExchangeVersion requestedServerVersion, org.apache.http.impl.client.CloseableHttpClient httpClient, org.apache.http.impl.client.CloseableHttpClient httpPoolingClient)protectedExchangeServiceBase(ExchangeServiceBase service, ExchangeVersion requestedServerVersion)protectedExchangeServiceBase(org.apache.http.impl.client.CloseableHttpClient httpClient, org.apache.http.impl.client.CloseableHttpClient httpPoolingClient)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static booleancheckURIPath(String location)voidclose()StringconvertDateTimeToUniversalDateTimeString(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 configuredConnectionSocketFactoryinstances.voiddoOnSerializeCustomSoapHeaders(XMLStreamWriter writer)Calls the custom SOAP header serialisation event handlers, if defined.booleangetAcceptGzipEncoding()Gets a value indicating whether GZip compression encoding should be accepted.ExchangeCredentialsgetCredentials()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.intgetMaximumPoolingConnections()List<ICustomXmlSerialization>getOnSerializeCustomSoapHeaders()Gets the on serialize custom soap headers.ExchangeVersiongetRequestedServerVersion()Gets the requested server version.ExchangeServerInfogetServerInfo()Gets information associated with the server that processed the last request.static byte[]getSessionKey()Gets the session key.intgetTimeout()Gets the timeout used when sending HTTP request and when receiving HTTP response, in milliseconds.EnumSet<TraceFlags>getTraceFlags()Gets the trace flags.ITraceListenergetTraceListener()Gets the trace listener.booleangetUseDefaultCredentials()Gets a value indicating whether the credential of the user currently logged into Windows should be used to authenticate with the Exchange Web Services.StringgetUserAgent()Gets the user agent.WebProxygetWebProxy()Gets the web proxy that should be used when sending request to EWS.protected voidinitializeHttpClient()protected voidinitializeHttpPoolingClient()protected voidinternalProcessHttpErrorResponse(HttpWebRequest httpWebResponse, Exception webException, TraceFlags responseHeadersTraceFlag, TraceFlags responseTraceFlag)This method doesn't handle 500 ISE errors.booleanisPreAuthenticate()Gets a value that indicates whether HTTP pre-authentication should be performed.booleanisTraceEnabled()Gets a value indicating whether tracing is enabled.booleanisTraceEnabledFor(TraceFlags traceFlags)Determines whether tracing is enabled for specified trace flag(s).booleanisUseGlobalCookieStore()protected voidprepareCredentials(HttpWebRequest request)protected HttpWebRequestprepareHttpPoolingWebRequestForUrl(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 HttpWebRequestprepareHttpWebRequestForUrl(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 voidprocessHttpErrorResponse(HttpWebRequest httpWebResponse, Exception webException)voidprocessHttpResponseHeaders(TraceFlags traceType, HttpWebRequest request)Traces the HTTP response headers.voidsetAcceptGzipEncoding(boolean acceptGzipEncoding)Gets a value indicating whether GZip compression encoding should be accepted.voidsetCredentials(ExchangeCredentials credentials)Sets the credential used to authenticate with the Exchange Web Services.protected voidsetCustomUserAgent(String userAgent)Sets the user agent to a custom valuevoidsetMaximumPoolingConnections(int maximumPoolingConnections)Sets the maximum number of connections for the pooling connection manager which is used for subscriptions.voidsetOnSerializeCustomSoapHeaders(List<ICustomXmlSerialization> onSerializeCustomSoapHeaders)Sets the on serialize custom soap headers.voidsetPreAuthenticate(boolean preAuthenticate)Sets a value that indicates whether HTTP pre-authentication should be performed.voidsetServerInfo(ExchangeServerInfo serverInfo)Sets information associated with the server that processed the last request.voidsetServiceRequestTracer(ServiceRequestTraceListener serviceRequestTraceListener)voidsetTimeout(int timeout)Sets the timeout used when sending HTTP request and when receiving HTTP respones, in milliseconds.voidsetTraceEnabled(boolean traceEnabled)Sets a value indicating whether tracing is enabled.voidsetTraceFlags(EnumSet<TraceFlags> traceFlags)Sets the trace flags.voidsetTraceListener(ITraceListener traceListener)Sets the trace listener.voidsetUseDefaultCredentials(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.voidsetUseGlobalCookieStore(boolean useGlobalCookieStore)voidsetUserAgent(String userAgent)Sets the user agent.voidsetWebProxy(WebProxy value)Sets the web proxy that should be used when sending request to EWS.voidtraceHttpRequestHeaders(TraceFlags traceType, HttpWebRequest request)Traces the HTTP request headers.voidtraceMessage(TraceFlags traceType, String logEntry)Logs the specified string to the TraceListener if tracing is enabled.<T> voidtraceServiceRequestError(ServiceRequestBase<T> serviceRequest, HttpWebRequest request, Exception e)<T> voidtraceServiceRequestStart(ServiceRequestBase<T> serviceRequest, HttpWebRequest request)<T> voidtraceServiceRequestSuccess(ServiceRequestBase<T> serviceRequest, HttpWebRequest request)voidtraceXml(TraceFlags traceType, ByteArrayOutputStream stream)Logs the specified XML to the TraceListener if tracing is enabled.voidvalidate()Validates this instance.
-
-
-
Field Detail
-
httpClient
protected org.apache.http.impl.client.CloseableHttpClient httpClient
-
externalHttpClient
protected boolean externalHttpClient
-
httpContext
protected org.apache.http.client.protocol.HttpClientContext httpContext
-
httpPoolingClient
protected org.apache.http.impl.client.CloseableHttpClient httpPoolingClient
-
externalHttpPoolingClient
protected boolean externalHttpPoolingClient
-
-
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(org.apache.http.impl.client.CloseableHttpClient httpClient, org.apache.http.impl.client.CloseableHttpClient httpPoolingClient)
-
ExchangeServiceBase
protected ExchangeServiceBase(ExchangeVersion requestedServerVersion)
-
ExchangeServiceBase
protected ExchangeServiceBase(ExchangeVersion requestedServerVersion, org.apache.http.impl.client.CloseableHttpClient httpClient, org.apache.http.impl.client.CloseableHttpClient httpPoolingClient)
-
ExchangeServiceBase
protected ExchangeServiceBase(ExchangeServiceBase service, ExchangeVersion requestedServerVersion)
-
-
Method Detail
-
initializeHttpClient
protected void initializeHttpClient()
-
initializeHttpPoolingClient
protected void initializeHttpPoolingClient()
-
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 configuredConnectionSocketFactoryinstances. Override this method to change how to work with different schemas.- Returns:
- registry object
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
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 exceptionURISyntaxException- 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 exceptionURISyntaxException- the uRI syntax exception
-
prepareCredentials
protected void prepareCredentials(HttpWebRequest request) 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 responsewebException- web exceptionresponseHeadersTraceFlag- trace flag for response headersresponseTraceFlag- 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 responsewebException- 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 entrylogEntry- the entry to log- Throws:
XMLStreamException- the XML stream exceptionIOException- 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 exceptionURISyntaxException- URI syntax errorIOException- signals that an I/O exception has occurredXMLStreamException- 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.
-
setServiceRequestTracer
public void setServiceRequestTracer(ServiceRequestTraceListener serviceRequestTraceListener)
-
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
-
isUseGlobalCookieStore
public boolean isUseGlobalCookieStore()
-
setUseGlobalCookieStore
public void setUseGlobalCookieStore(boolean useGlobalCookieStore)
-
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 entryrequest- The request- Throws:
EWSHttpException- EWS http exceptionIOException- signals that an I/O exception has occurredXMLStreamException- 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
-
getMaximumPoolingConnections
public int getMaximumPoolingConnections()
-
traceServiceRequestStart
public <T> void traceServiceRequestStart(ServiceRequestBase<T> serviceRequest, HttpWebRequest request)
-
traceServiceRequestError
public <T> void traceServiceRequestError(ServiceRequestBase<T> serviceRequest, HttpWebRequest request, Exception e)
-
traceServiceRequestSuccess
public <T> void traceServiceRequestSuccess(ServiceRequestBase<T> serviceRequest, HttpWebRequest request)
-
-