我正在使用以下代码连接以交换 Web 服务。
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
String username = "mydomain\\username";
String password = "mypassword";
String exchangeServer = "myserver";
String domain = "mydomain";
boolean performAutodiscovery = false;
ExchangeCredentials credentials = new WebCredentials(username, password, domain);
service.setCredentials(credentials);
try {
service.setUrl(new URI("https://" + exchangeServer + "/EWS/Exchange.asmx"));
} catch(Exception e) {
}
我还将用户名格式更改为使用 username@domain.com。当我使用Microsoft Remote Connectivity Analyzer进行测试时,连接对给定用户工作得很好。
我也尝试过不同版本的交换。
相同的代码适用于其他客户。
下面是日志输出。
[2015-12-28 10:04:30,616]DEBUG[main](RequestAddCookies.java:122)-CookieSpec selected:default
[2015-12-28 10:04:30,632]DEBUG[main](RequestAuthCache.java:76)-Auth cache not set in the context
[2015-12-28 10:04:30,633]DEBUG[main](PoolingHttpClientConnectionManager.java:249)-Connection request:[route:{s}->https://url:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
[2015-12-28 10:04:30,652]DEBUG[main](PoolingHttpClientConnectionManager.java:282)-Connection leased:[id:0][route:{s}->https://url:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
[2015-12-28 10:04:30,654]DEBUG[main](MainClientExec.java:234)-Opening connection{s}->https://url:443
[2015-12-28 10:04:30,658]DEBUG[main](DefaultHttpClientConnectionOperator.java:131)-Connecting to url/ip:443
[2015-12-28 10:04:30,658]DEBUG[main](SSLConnectionSocketFactory.java:335)-Connecting socket to url/ip:443with timeout 100000
[2015-12-28 10:04:30,935]DEBUG[main](SSLConnectionSocketFactory.java:388)-Enabled protocols:[TLSv1]
[2015-12-28 10:04:30,935]DEBUG[main](SSLConnectionSocketFactory.java:389)-Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDH_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA,TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA,TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA,TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA,TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,TLS_ECDHE_RSA_WITH_RC4_128_SHA,SSL_RSA_WITH_RC4_128_SHA,TLS_ECDH_ECDSA_WITH_RC4_128_SHA,TLS_ECDH_RSA_WITH_RC4_128_SHA,SSL_RSA_WITH_RC4_128_MD5,TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
[2015-12-28 10:04:30,936]DEBUG[main](SSLConnectionSocketFactory.java:393)-Starting handshake
[2015-12-28 10:04:31,173]DEBUG[main](SSLConnectionSocketFactory.java:423)-Secure session established
[2015-12-28 10:04:31,173]DEBUG[main](SSLConnectionSocketFactory.java:424)-negotiated protocol:TLSv1
[2015-12-28 10:04:31,173]DEBUG[main](SSLConnectionSocketFactory.java:425)-negotiated cipher suite:TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
[2015-12-28 10:04:31,174]DEBUG[main](SSLConnectionSocketFactory.java:433)-peer principal:CN=url,OU=Domain Control Validated
[2015-12-28 10:04:31,174]DEBUG[main](SSLConnectionSocketFactory.java:442)-peer alternative names:[url,www.url,micsentry10.domain.com,micsentry2.domain.com,micsentry7.domain.com,micsentry3.domain.com,url,micsentry6.domain.com,micsentry5.domain.com,micsentry4.domain.com,micsentry8.domain.com,micsentry9.domain.com]
[2015-12-28 10:04:31,174]DEBUG[main](SSLConnectionSocketFactory.java:446)-issuer principal:CN=Go Daddy Secure Certificate Authority-G2,OU=http://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US
[2015-12-28 10:04:31,196]DEBUG[main](DefaultHttpClientConnectionOperator.java:138)-Connection established ip1:62859<->ip:443
[2015-12-28 10:04:31,196]DEBUG[main](LoggingManagedHttpClientConnection.java:90)-http-outgoing-0:set socket timeout to 100000
[2015-12-28 10:04:31,196]DEBUG[main](MainClientExec.java:255)-Executing request POST/EWS/Exchange.asmx HTTP/1.1
[2015-12-28 10:04:31,197]DEBUG[main](MainClientExec.java:260)-Target auth state:UNCHALLENGED
[2015-12-28 10:04:31,197]DEBUG[main](MainClientExec.java:266)-Proxy auth state:UNCHALLENGED
[2015-12-28 10:04:31,199]DEBUG[main](LoggingManagedHttpClientConnection.java:135)-http-outgoing-0>>POST/EWS/Exchange.asmx HTTP/1.1
[2015-12-28 10:04:31,200]DEBUG[main](LoggingManagedHttpClientConnection.java:138)-http-outgoing-0>>Content-type:text/xml;charset=utf-8
[2015-12-28 10:04:31,200]DEBUG[main](LoggingManagedHttpClientConnection.java:138)-http-outgoing-0>>User-Agent:ExchangeServicesClient/0.0.0.0
[2015-12-28 10:04:31,200]DEBUG[main](LoggingManagedHttpClientConnection.java:138)-http-outgoing-0>>Accept:text/xml
[2015-12-28 10:04:31,200]DEBUG[main](LoggingManagedHttpClientConnection.java:138)-http-outgoing-0>>Keep-Alive:300
[2015-12-28 10:04:31,200]DEBUG[main](LoggingManagedHttpClientConnection.java:138)-http-outgoing-0>>Connection:Keep-Alive
[2015-12-28 10:04:31,200]DEBUG[main](LoggingManagedHttpClientConnection.java:138)-http-outgoing-0>>Accept-Encoding:gzip,deflate
[2015-12-28 10:04:31,200]DEBUG[main](LoggingManagedHttpClientConnection.java:138)-http-outgoing-0>>Content-Length:772
[2015-12-28 10:04:31,201]DEBUG[main](LoggingManagedHttpClientConnection.java:138)-http-outgoing-0>>Host:url
[2015-12-28 10:04:31,201]DEBUG[main](Wire.java:72)-http-outgoing-0>>"POST /EWS/Exchange.asmx HTTP/1.1[\r][\n]"
[2015-12-28 10:04:31,201]DEBUG[main](Wire.java:72)-http-outgoing-0>>"Content-type: text/xml; charset=utf-8[\r][\n]"
[2015-12-28 10:04:31,201]DEBUG[main](Wire.java:72)-http-outgoing-0>>"User-Agent: ExchangeServicesClient/0.0.0.0[\r][\n]"
[2015-12-28 10:04:31,202]DEBUG[main](Wire.java:72)-http-outgoing-0>>"Accept: text/xml[\r][\n]"
[2015-12-28 10:04:31,202]DEBUG[main](Wire.java:72)-http-outgoing-0>>"Keep-Alive: 300[\r][\n]"
[2015-12-28 10:04:31,202]DEBUG[main](Wire.java:72)-http-outgoing-0>>"Connection: Keep-Alive[\r][\n]"
[2015-12-28 10:04:31,202]DEBUG[main](Wire.java:72)-http-outgoing-0>>"Accept-Encoding: gzip,deflate[\r][\n]"
[2015-12-28 10:04:31,202]DEBUG[main](Wire.java:72)-http-outgoing-0>>"Content-Length: 772[\r][\n]"
[2015-12-28 10:04:31,203]DEBUG[main](Wire.java:72)-http-outgoing-0>>"Host: url[\r][\n]"
[2015-12-28 10:04:31,203]DEBUG[main](Wire.java:72)-http-outgoing-0>>"[\r][\n]"
[2015-12-28 10:04:31,203]DEBUG[main](Wire.java:86)-http-outgoing-0>>"<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><soap:Header><t:RequestServerVersion Version="Exchange2013_SP1"></t:RequestServerVersion></soap:Header><soap:Body><m:FindFolder Traversal="Shallow"><m:FolderShape><t:BaseShape>AllProperties</t:BaseShape></m:FolderShape><m:IndexedPageFolderView MaxEntriesReturned="10" Offset="0" BasePoint="Beginning"></m:IndexedPageFolderView><m:ParentFolderIds><t:DistinguishedFolderId Id="inbox"></t:DistinguishedFolderId></m:ParentFolderIds></m:FindFolder></soap:Body></soap:Envelope>"
[2015-12-28 10:04:31,229]DEBUG[main](Wire.java:86)-http-outgoing-0<<"end of stream"
[2015-12-28 10:04:31,230]DEBUG[main](LoggingManagedHttpClientConnection.java:81)-http-outgoing-0:Close connection
[2015-12-28 10:04:31,230]DEBUG[main](LoggingManagedHttpClientConnection.java:98)-http-outgoing-0:Shutdown connection
[2015-12-28 10:04:31,230]DEBUG[main](ConnectionHolder.java:128)-Connection discarded
[2015-12-28 10:04:31,231]DEBUG[main](PoolingHttpClientConnectionManager.java:320)-Connection released:[id:0][route:{s}->https://url:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
[2015-12-28 10:04:31,232]DEBUG[main](ConnectionHolder.java:144)-Cancelling request execution
Exception in thread"main"microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException:The request failed.The request failed.url:443failed to respond
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:158)
at microsoft.exchange.webservices.data.core.ExchangeService.internalFindFolders(ExchangeService.java:256)
at microsoft.exchange.webservices.data.core.ExchangeService.findFolders(ExchangeService.java:304)
at microsoft.exchange.webservices.data.core.ExchangeService.findFolders(ExchangeService.java:340)
at com.clarius.cards.core.indexer_dep.indexer.exchange.ewsclient.EwsSession.main(EwsSession.java:398)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by:microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException:The request failed.url:443failed to respond
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:730)
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:639)
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:62)
...10more
Caused by:org.apache.http.NoHttpResponseException:url:443failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at microsoft.exchange.webservices.data.core.request.HttpClientWebRequest.executeRequest(HttpClientWebRequest.java:294)
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:720)
...12more