Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

java - Exchange Hybrid- External EWS URL throws Connection timed out errors

We have currently setup Exchange Hybrid environment using Hybrid Configuration Wizard on our test servers. We were thinking of using EWS external URL(with EWS Java libraries) to access all the mails from on-premises as well as Exchange Online mailboxes in the Hybrid setup.

Code Snippet:

System.setProperty("https.proxyHost", "<host>");
System.setProperty("https.proxyPort", "443");
...
exchangeService.setUrl(new URI("https://<public_domain>/ews/exchange.asmx")); 
exchangeService.setCredentials(new WebCredentials("ex user", "password"));
...

Below is the stack trace:

microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. The request failed. Connect to <public domain>:443 [<public domain>/<public domain IP>] failed: Connection timed out: connect
    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:377)
    at microsoft.exchange.webservices.data.core.ExchangeService.findFolders(ExchangeService.java:425)
    at microsoft.exchange.webservices.data.core.ExchangeService.findFolders(ExchangeService.java:461)
    at com.sample.externalews.UsingClientCreds.displayMailboxFolders(UsingClientCreds.java:143)
    at com.sample.externalews.UsingClientCreds.usingCredentials(UsingClientCreds.java:161)
    at com.sample.externalews.UsingClientCreds.main(UsingClientCreds.java:237)
Caused by: microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. Connect to <public domain>:443 [<public domain>/<public domain IP>] failed: Connection timed out: connect
    at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:729)
    at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:639)
    at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:62)
    ... 7 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to <public domain>:443 [<public domain>/<public domain IP>] failed: Connection timed out: connect
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
    at org.apache.http.impl.conn.BasicHttpClientConnectionManager.connect(BasicHttpClientConnectionManager.java:313)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at microsoft.exchange.webservices.data.core.request.HttpClientWebRequest.executeRequest(HttpClientWebRequest.java:292)
    at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:720)
    ... 9 more
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:96)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:380)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:236)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:218)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
    at java.net.Socket.connect(Socket.java:682)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:368)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    ... 19 more
microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. The request failed. Connect to <public domain>:443 [<public domain>/<public domain IP>] failed: Connection timed out: connect
    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.bindToFolder(ExchangeService.java:504)
    at microsoft.exchange.webservices.data.core.ExchangeService.bindToFolder(ExchangeService.java:523)
    at microsoft.exchange.webservices.data.core.service.folder.Folder.bind(Folder.java:98)
    at microsoft.exchange.webservices.data.core.service.folder.Folder.bind(Folder.java:147)
    at com.sample.externalews.UsingClientCreds.displayMails(UsingClientCreds.java:171)
    at com.sample.externalews.UsingClientCreds.usingCredentials(UsingClientCreds.java:163)
    at com.sample.externalews.UsingClientCreds.main(UsingClientCreds.java:237)
Caused by: microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. Connect to <public domain>:443 [<public domain>/<public domain IP>] failed: Connection timed out: connect
    at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:729)
    at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:639)
    at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:62)
    ... 8 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to <public domain>:443 [<public domain>/<public domain IP>] failed: Connection timed out: connect
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
    at org.apache.http.impl.conn.BasicHttpClientConnectionManager.connect(BasicHttpClientConnectionManager.java:313)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at microsoft.exchange.webservices.data.core.request.HttpClientWebRequest.executeRequest(HttpClientWebRequest.java:292)
    at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:720)
    ... 10 more
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:96)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:380)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:236)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:218)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
    at java.net.Socket.connect(Socket.java:682)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:368)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    ... 20 more

When we use Exchange EWS endpoint https://outlook.office365.com/EWS/Exchange.asmx, we are able to access the mails from Exchange Online user only and it throws "Mailbox does not exist" error for Exchange On-premise user, which I assume is expected.

Please let us know if this is feasible i.e. if we can use external EWS endpoint to access both Exchange On-premises and Exchange Online mailboxes. If not, is there any other way in which this can be achieved?

question from:https://stackoverflow.com/questions/65839672/exchange-hybrid-external-ews-url-throws-connection-timed-out-errors

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No for OnPrem Exchange users (in Hybrid) you must use the OnPrem EWS Endpoint, you can use Autodiscoverv2 endpoint (which isn't) authenticated to discover the correct endpoint you should be using. eg

https://outlook.office365.com/autodiscover/[email protected]&Protocol=ews

If you setup hybrid Modern authentication then you can get an Authentication token from Azure that you will be then able to use against the OnPrem Server.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...