OfficeDev / ews-java-api

A java client library to access Exchange web services. The API works against Office 365 Exchange Online as well as on premises Exchange.
MIT License
870 stars 558 forks source link

Autodiscover EWS url #325

Open nshowkath opened 9 years ago

nshowkath commented 9 years ago

Hi ,

1) To discover the EWS URL for O365 we have to use Autodiscover option
Is below url is same for any organization or if every organization has different o365 url if they have online exchange https://outlook.office365.com/EWS/Exchange.asmx

When we should we use Autodiscover option?

We can determine url using below post operation or service.autodiscoverUrl(emailAddress); 2)
POST /autodiscover/autodiscover.xml https://mail.testdomain.com/Autodiscover/Autodiscover.xml https://msdn.microsoft.com/en-us/library/office/ee332364(v=exchg.140).aspx <?xml version="1.0"?> <Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">

user@contoso.com http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a

</Autodiscover If everything is OK, then we'll get back a response Or

service.autodiscoverUrl(emailAddress);

When should we use which option , our application is deployed on cloud service.autodiscoverUrl(emailAddress) did not work , so we performed post operation to get url.

Could you share scenarios and recommendations – When should we have to use Autodiscover application , Exchange On-premise Scenarios and for the applications deployed in cloud

avromf commented 9 years ago

Hi,

I work for an organization that uses Office365 and some of our clients do as well. For all of us, the URL is https://outlook.office365.com/EWS/Exchange.asmx

The way I view the AutoDiscover feature is one of convenience. i.e. it can be used to auto configure so users don't have to themselves. However, EWS will work perfectly without this feature turned on.

In the application which I have integrated EWS with, I allow users to either manually enter the URL in our preferences or set it via the AutoDiscover feature. Then, all connections to EWS (i.e. the service object) are set using this URL. It is a lot slower to have AutoDiscover to do a lookup every single time. Also, this URL will rarely change.

valenpo commented 9 years ago

I trying to auth with Office365 via OAuth2 using ADAL4J library. I'm success get auth token for "https://outlook.office365.com", so next step is using EWS.

ExchangeService service = new ExchangeService();

                    service.setCredentials(new OAuth2Credentials(authRes.getAccessToken()));
                    service.setTraceEnabled(true);
                    service.traceMessage(TraceFlags.EwsRequest, "office365");
                    service.setImpersonatedUserId(new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "jamie@archiva360.com"));
                    service.setUrl(new URI("https://outlook.office365.com/ews/exchange.asmx"));

class OAuth2Credentials extends ExchangeCredentials {

    private String accessToken;

    public OAuth2Credentials(String accessToken) {
        Preconditions.checkNotNull(accessToken);
        this.accessToken = accessToken;
    }

    @Override
    public void prepareWebRequest(HttpWebRequest client)
            throws URISyntaxException {
        super.prepareWebRequest(client);
        if (client.getHeaders() != null) client.getHeaders().put("Authorization", "Bearer " + accessToken);
    }
}

and get error

microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. Exchange Web Services are not currently available for this request because none of the Client Access Servers in the destination site could process the request.
    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:372)
    at microsoft.exchange.webservices.data.core.ExchangeService.findFolders(ExchangeService.java:421)
    at microsoft.exchange.webservices.data.core.ExchangeService.findFolders(ExchangeService.java:456)
    at com.stimulus.archiva.connect.exchange.rest.OAuth2.main(OAuth2.java:88)

What is correct URL to get access Office365 ? Any clue?

When using auto-discover against direct url

ExchangeService service = new ExchangeService();

                    service.setCredentials(new OAuth2Credentials(authRes.getAccessToken()));
                    service.setTraceEnabled(true);
                    service.traceMessage(TraceFlags.EwsRequest, "office365");
                    service.setImpersonatedUserId(new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "jamie@archiva360.com"));
service.autodiscoverUrl("jamie@archiva360.com");

I got other problem with infinitive connection:

19:19:21.103 [pool-1-thread-1] DEBUG c.m.aad.adal4j.AuthenticationContext - [Correlation ID: 217b22b5-f251-408b-a5da-19ad639be8cf] Using Client Http Headers: x-client-SKU=java;x-client-VER=1.0.0;x-client-OS=Mac OS X;x-client-CPU=x86_64;return-client-request-id=true;client-request-id=217b22b5-f251-408b-a5da-19ad639be8cf;
19:19:21.106 [pool-1-thread-1] INFO  c.m.a.adal4j.AuthenticationAuthority - [Correlation ID: 217b22b5-f251-408b-a5da-19ad639be8cf] Instance discovery was successful
19:19:21.853 [pool-1-thread-1] DEBUG c.m.aad.adal4j.AuthenticationContext - [Correlation ID: 217b22b5-f251-408b-a5da-19ad639be8cf] Access Token with hash 'lQOnxt3PB5s-5PZrsanGGJlQx0IfMwDrwDVo0qrKKNQ' returned
Success: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSIsImtpZCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQiOiJodHRwczovL291dGxvb2sub2ZmaWNlMzY1LmNvbSIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0L2QwNjk4YTkxLTIzYmEtNDQ5NS1hYmRiLTU4NjQ3OTNjNDhkYy8iLCJpYXQiOjE0MzI5MTI0NjEsIm5iZiI6MTQzMjkxMjQ2MSwiZXhwIjoxNDMyOTE2MzYxLCJ2ZXIiOiIxLjAiLCJ0aWQiOiJkMDY5OGE5MS0yM2JhLTQ0OTUtYWJkYi01ODY0NzkzYzQ4ZGMiLCJyb2xlcyI6WyJmdWxsX2FjY2Vzc19hc19hcHAiLCJNYWlsLlJlYWRXcml0ZSIsIkNhbGVuZGFycy5SZWFkIiwiQ29udGFjdHMuUmVhZFdyaXRlIiwiTWFpbC5SZWFkIiwiQ2FsZW5kYXJzLlJlYWRXcml0ZSIsIk1haWwuU2VuZCIsIkNvbnRhY3RzLlJlYWQiXSwib2lkIjoiZTRjZTc2MzQtYjEyYi00ODdmLWEwZjYtYzMxOWI4Mjc2NWZjIiwic3ViIjoiZTRjZTc2MzQtYjEyYi00ODdmLWEwZjYtYzMxOWI4Mjc2NWZjIiwiaWRwIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvZDA2OThhOTEtMjNiYS00NDk1LWFiZGItNTg2NDc5M2M0OGRjLyIsImFwcGlkIjoiZTIzNDI1ZTktYjJhMi00OTQwLThiZTktMjFjZDc0NjcxNTEzIiwiYXBwaWRhY3IiOiIyIn0.C0QMSmujxZF7QTbrBWflzjtTIcFbgzC7XtI1HDkf3VTMK5T6kLs_ut0sCxeBjHd6wzKADqwQw7MaaC86ougKsd9_FAA7ihiTYTh1Im6ufGQxxbHiOe9dnc7NsjjrSxE_SPJx-bE2deNwdJ9wg1nqxGF4QjNMGAdw-SMcq838eOac3OMHZoH7l6wFmvLhnj-bpoaMfx2YE7ZCbEyf-0JvpVdegIQIr0Yw1rDSyXx-6yo_3agKt42xUcxEGCo32GMB2WwD3nrDmgg8u1C5bNVp9GlDCkjFCjpa7QDMrdBtIBTL2MJJ1vi71o4ODO-_2qIiNbOIFlQMftQOPxGSjZ_0YQ
19:19:22.101 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
19:19:22.110 [main] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
19:19:22.112 [main] DEBUG o.a.h.i.c.BasicHttpClientConnectionManager - Get connection for route {s}->https://archiva360.com:443
19:19:22.124 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Opening connection {s}->https://archiva360.com:443
19:19:22.403 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to archiva360.com/184.168.221.57:443
19:19:22.403 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to archiva360.com/184.168.221.57:443 with timeout 0
19:19:22.604 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Enabled protocols: [TLSv1]
19:19:22.604 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, 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_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, 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, SSL_RSA_WITH_RC4_128_MD5, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
19:19:22.604 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Starting handshake
19:19:23.013 [main] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: Shutdown connection
19:19:23.013 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Connection discarded
19:19:23.013 [main] DEBUG o.a.h.i.c.BasicHttpClientConnectionManager - Releasing connection [Not bound]
19:19:23.014 [main] INFO  o.a.http.impl.execchain.RetryExec - I/O exception (java.net.SocketException) caught when processing request to {s}->https://archiva360.com:443: Connection reset
19:19:23.021 [main] DEBUG o.a.http.impl.execchain.RetryExec - Connection reset
java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:196) ~[na:1.7.0_67]
    at java.net.SocketInputStream.read(SocketInputStream.java:122) ~[na:1.7.0_67]
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:442) ~[na:1.7.0_67]
    at sun.security.ssl.InputRecord.read(InputRecord.java:480) ~[na:1.7.0_67]
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927) ~[na:1.7.0_67]
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312) ~[na:1.7.0_67]
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339) ~[na:1.7.0_67]
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323) ~[na:1.7.0_67]
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394) ~[httpclient-4.4.1.jar:4.4.1]
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353) ~[httpclient-4.4.1.jar:4.4.1]
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134) ~[httpclient-4.4.1.jar:4.4.1]
    at org.apache.http.impl.conn.BasicHttpClientConnectionManager.connect(BasicHttpClientConnectionManager.java:338) ~[httpclient-4.4.1.jar:4.4.1]
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) ~[httpclient-4.4.1.jar:4.4.1]
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[httpclient-4.4.1.jar:4.4.1]
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) ~[httpclient-4.4.1.jar:4.4.1]
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) ~[httpclient-4.4.1.jar:4.4.1]
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) [httpclient-4.4.1.jar:4.4.1]
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) [httpclient-4.4.1.jar:4.4.1]
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) [httpclient-4.4.1.jar:4.4.1]
    at microsoft.exchange.webservices.data.core.request.HttpClientWebRequest.executeRequest(HttpClientWebRequest.java:292) [ews-java-api-2.0-SNAPSHOT.jar:na]
    at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.tryGetEnabledEndpointsForHost(AutodiscoverService.java:1531) [ews-java-api-2.0-SNAPSHOT.jar:na]
    at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.tryGetAutodiscoverEndpointUrl(AutodiscoverService.java:1349) [ews-java-api-2.0-SNAPSHOT.jar:na]
    at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.getSettings(AutodiscoverService.java:1136) [ews-java-api-2.0-SNAPSHOT.jar:na]
    at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.getUserSettings(AutodiscoverService.java:1044) [ews-java-api-2.0-SNAPSHOT.jar:na]
    at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.internalGetSoapUserSettings(AutodiscoverService.java:988) [ews-java-api-2.0-SNAPSHOT.jar:na]
    at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.getUserSettings(AutodiscoverService.java:1849) [ews-java-api-2.0-SNAPSHOT.jar:na]
    at microsoft.exchange.webservices.data.core.ExchangeService.getAutodiscoverUrl(ExchangeService.java:3611) [ews-java-api-2.0-SNAPSHOT.jar:na]
    at microsoft.exchange.webservices.data.core.ExchangeService.autodiscoverUrl(ExchangeService.java:3539) [ews-java-api-2.0-SNAPSHOT.jar:na]
    at microsoft.exchange.webservices.data.core.ExchangeService.autodiscoverUrl(ExchangeService.java:3520) [ews-java-api-2.0-SNAPSHOT.jar:na]
    at com.stimulus.archiva.connect.exchange.rest.OAuth2.main(OAuth2.java:86) [classes/:na]
19:19:23.021 [main] INFO  o.a.http.impl.execchain.RetryExec - Retrying request to {s}->https://archiva360.com:443
19:19:23.021 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
19:19:23.021 [main] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
19:19:23.021 [main] DEBUG o.a.h.i.c.BasicHttpClientConnectionManager - Get connection for route {s}->https://archiva360.com:443
19:19:23.021 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Opening connection {s}->https://archiva360.com:443
19:19:23.021 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to archiva360.com/184.168.221.57:443
19:19:23.022 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to archiva360.com/184.168.221.57:443 with timeout 0
19:19:23.324 [main] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-1: Shutdown connection
19:19:23.324 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Connection discarded
19:19:23.324 [main] DEBUG o.a.h.i.c.BasicHttpClientConnectionManager - Releasing connection [Not bound]
19:19:23.324 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Cancelling request execution
19:19:23.328 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
19:19:23.328 [main] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
19:19:23.328 [main] DEBUG o.a.h.i.c.BasicHttpClientConnectionManager - Get connection for route {s}->https://autodiscover.archiva360.com:443
19:19:23.328 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Opening connection {s}->https://autodiscover.archiva360.com:443
19:19:23.677 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to autodiscover.archiva360.com/132.245.224.200:443
19:19:23.677 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to autodiscover.archiva360.com/132.245.224.200:443 with timeout 0
19:19:23.741 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connect to autodiscover.archiva360.com/132.245.224.200:443 timed out. Connection will be retried using another IP address
19:19:23.742 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to autodiscover.archiva360.com/132.245.176.72:443
19:19:23.742 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to autodiscover.archiva360.com/132.245.176.72:443 with timeout 0
19:19:23.801 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connect to autodiscover.archiva360.com/132.245.176.72:443 timed out. Connection will be retried using another IP address
19:19:23.802 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to autodiscover.archiva360.com/132.245.48.24:443
19:19:23.802 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to autodiscover.archiva360.com/132.245.48.24:443 with timeout 0
19:19:23.860 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connect to autodiscover.archiva360.com/132.245.48.24:443 timed out. Connection will be retried using another IP address
19:19:23.861 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to autodiscover.archiva360.com/132.245.36.104:443
19:19:23.861 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to autodiscover.archiva360.com/132.245.36.104:443 with timeout 0
19:19:23.923 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connect to autodiscover.archiva360.com/132.245.36.104:443 timed out. Connection will be retried using another IP address
19:19:23.924 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to autodiscover.archiva360.com/132.245.193.136:443
19:19:23.924 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to autodiscover.archiva360.com/132.245.193.136:443 with timeout 0
19:19:23.982 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connect to autodiscover.archiva360.com/132.245.193.136:443 timed out. Connection will be retried using another IP address
19:19:23.983 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to autodiscover.archiva360.com/191.234.224.8:443
19:19:23.983 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to autodiscover.archiva360.com/191.234.224.8:443 with timeout 0
19:19:24.033 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connect to autodiscover.archiva360.com/191.234.224.8:443 timed out. Connection will be retried using another IP address
19:19:24.033 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to autodiscover.archiva360.com/191.234.224.184:443
19:19:24.033 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to autodiscover.archiva360.com/191.234.224.184:443 with timeout 0
19:19:24.085 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connect to autodiscover.archiva360.com/191.234.224.184:443 timed out. Connection will be retried using another IP address
19:19:24.085 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to autodiscover.archiva360.com/132.245.61.232:443
19:19:24.085 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to autodiscover.archiva360.com/132.245.61.232:443 with timeout 0
19:19:24.154 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connect to autodiscover.archiva360.com/132.245.61.232:443 timed out. Connection will be retried using another IP address
19:19:24.155 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to autodiscover.archiva360.com/132.245.229.184:443
19:19:24.155 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to autodiscover.archiva360.com/132.245.229.184:443 with timeout 0
19:19:24.200 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connect to autodiscover.archiva360.com/132.245.229.184:443 timed out. Connection will be retried using another IP address
19:19:24.201 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to autodiscover.archiva360.com/2a01:111:f400:8400:0:0:0:8:443
19:19:24.201 [main] DEBUG m.e.w.d.c.EwsSSLProtocolSocketFactory - Connecting socket to autodiscover.archiva360.com/2a01:111:f400:8400:0:0:0:8:443 with timeout 0
avromf commented 9 years ago

@valenpo , you are using the correct EWS url for Office365. Its https://outlook.office365.com/EWS/Exchange.asmx Beyond that, I'm not sure what the problem is.

yatinc1206 commented 7 years ago

Hi I am using ews-java-api to connect outlook 2010 our exchange server service url is https://hostname/EWS/Exchange.asmx I am trying to connect public folder root using following line of code

public static void main(String[] args) {
    String serviceUrl = "";
    try {
        //Load Property
        Properties prop = new Properties();
        prop.load(new FileInputStream("config.properties"));

        //Get exchange service object       
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

        String mailId = prop.getProperty("mailId");
        String passWd = prop.getProperty("mailPwd");
        passWd = CryptBase64.decrypt(passWd);
        serviceUrl = prop.getProperty("serviceUrl");

        //System.out.println("mailId = "+mailId+"\t pwd = "+passWd+"\t serviceUrl = "+serviceUrl);

        //Set credentials
        ExchangeCredentials credentials = new WebCredentials( mailId, passWd);

        //Pass credentials to service
        service.setCredentials(credentials);

        //Set service Url
        service.setUrl(new URI(serviceUrl.trim()));
        //service.autodiscoverUrl(mailId);

        service.setTraceEnabled(true);

        FolderView view = new FolderView(1000);

        //Read Your own folder Items
        FolderId folderId = new FolderId(WellKnownFolderName.PublicFoldersRoot);

        ItemView itemview = new ItemView(1000);
        FindItemsResults<Item> findResults = service.findItems(folderId, itemview);

        for(Item f : findResults){
            System.out.println("Name : "+f.getSubject());
        }
    }catch(Exception e){
        e.printStackTrace();
    }
}

but it is raising an exception as

microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: There are no public folder servers available. at microsoft.exchange.webservices.data.core.response.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:278) at microsoft.exchange.webservices.data.core.response.ServiceResponse.throwIfNecessary(ServiceResponse.java:267) at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:165) at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:985) at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:1049) at com.wellmanage.fi.ReadFromPublicFolder.main(ReadFromPublicFolder.java:57)

what could be the reason? can any one help me out from this? struggling a lot with this thing. I am able to read email from Inbox or other messaging folders and even from user created folders too.

avromf commented 7 years ago

@yatinc1206 The exception tells you what went wrong.

Not all Exchange Server configurations have public folders set up. If it is not set up, then if you try to access the public folder root, it will give you that error.

yatinc1206 commented 7 years ago

@avromf As you said not all exchnage server has public folder set up then what missing here if I am able to view public folders from outlook and I can send mail to that shared public folder also. When I approached messaging team with above concern they are saying exchange has nothing to do with that issue. So could you please tell which configurations need to be checked or set up to be made? So that I can convey the same to them.

Thanks

davster commented 7 years ago

The error you are getting from EWS suggests that you may be using the X-AnchorMailbox header incorrectly (or not using it). That is basically a routing hint to the front end servers. You are landing on a server in the wrong site. Also, likely not related, but worth mentioning anyways, make sure you are getting the right scopes in your OAuth token:

https://msdn.microsoft.com/en-us/library/office/dn903761(v=exchg.150).aspx

avromf commented 7 years ago

@yatinc1206 My company's Exchange Server does not provide us with public folders. I just tested EWS now against our server by trying to access the root public folder and I got the exact same error. From what I understand, shared folders are not the same as public folders. Maybe in your case it is actually a shared folder.

yatinc1206 commented 7 years ago

@davster : what does mean by X-AnchorMailbox? And I didn't get what you have commented.

@avromf : Actually I am working on client remote desktop there we are implementing this. what is difference between public folder and shared folder? what about the view which am I getting in my mailbox under public folders. There I can see few number of folders. And what workaround you will suggest to get it executed.

davster commented 7 years ago

@yatinc1206 - your post above mentioned you receive:

The request failed. Exchange Web Services are not currently available for this request because none of the Client Access Servers in the destination site could process the request.

I am suggesting that you add an HTTP header to your request like this: X-AnchorMailbox: jamie@archiva360.com

This is a routing hint for Exchange to get you to the right backend to start with instead of routing you incorrectly (long story) and causing a proxy which is where the above error is coming from.

yatinc1206 commented 7 years ago

@davster : sorry but still not getting what you are trying to say. And how it relate in my source code. Where I will have to use whatever you are saying?

avromf commented 7 years ago

@yatinc1206 See this: https://www.codetwo.com/admins-blog/office-365-shared-mailbox-vs-public-folders-whats-the-difference/ Or Microsoft's page: https://technet.microsoft.com/en-us/library/jj983794(v=exchg.150).aspx

I do not know of any workaround you can implement. (Maybe consult with the IT people who are in charge of your Exchange Server so you will have a better idea of what you are dealing with.)

avromf commented 7 years ago

@davster I believe the post above that you are referring to was by @valenpo a while back. I do not think it has anything to do with @yatinc1206 's issue.