1

I'm using EWS Java API to connect Exchange server and retrieve information about mail, calendar appointment and task.

It's working well with a lot of user, except for one account. I got the following error :

microsoft.exchange.webservices.data.EWSHttpException: Connection not established
at microsoft.exchange.webservices.data.HttpClientWebRequest.throwIfConnIsNull(HttpClientWebRequest.java:394)
at microsoft.exchange.webservices.data.HttpClientWebRequest.getResponseHeaders(HttpClientWebRequest.java:280)
at microsoft.exchange.webservices.data.ExchangeServiceBase.processHttpResponseHeaders(ExchangeServiceBase.java:1045)
at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:58)
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:144)
at microsoft.exchange.webservices.data.ExchangeService.bindToFolder(ExchangeService.java:350)
at microsoft.exchange.webservices.data.ExchangeService.bindToFolder(ExchangeService.java:374)

Here the code to establish the connection :

ExchangeService service = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials(<user>, <password>);

service.setCredentials(credentials);
service.setUrl(new URI(url));

I suspect a specific account configuration for explaining this error but I'm unable to determine which parameter.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
user3767882
  • 11
  • 1
  • 2
  • http://stackoverflow.com/questions/1739921/are-there-any-api-to-integrate-microsoft-exchange-server-with-java-application-f/7517021#7517021 –  Jul 14 '14 at 07:28

3 Answers3

1

That exception is almost certainly due to a bug. I've seen it many, many times. The problem lies in the SimpleServiceRequest class. If there's an error when reading the response, it will close the response in a finally block in readResponse(). It will go back up to internalExecute(), where the catch block will try to process the headers...and it tries to read the response that has been closed. The closing won't null out the response, but it does null out some data in the response, which EWS tries to read as to display errors. Then you get another exception because the connection is null due to the response being closed earlier.

The solution is to either fix the bug yourself or enable tracing and look at the response to see what kind of error you're dealing with. Also, for good measure, make sure the Strings class is reading in the Strings.properties file or it'll throw a different exception when it can't find certain error messages.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
user1017413
  • 2,023
  • 4
  • 26
  • 41
  • Would you mind sharing your approach for fixing the bug? Should the response be nulled so it doesn't get processed in internalExecute() or should the response never be closed in readResponse() so it is available in internalExecute() and will be finally closed there? Having not so much knowledge about the internal workings of the EWS Java API I'd appreciate if someone could share a safe fix for that without any side effects to other logic. – tvirtualw Aug 06 '14 at 00:31
  • Please tell us how to fix this issue, I am able to get rooms but when I am trying to get service.userAvailability it is showing connection not established...previously I was able to get the data but now its connection not established showing – Manoj Behera Jul 27 '15 at 07:46
  • I would advise checking the github page as EWS Java was open sourced last year, thank goodness. I believe this bug (among others) has been fixed. – user1017413 Jul 27 '15 at 18:28
0

After working with the debugger and Fiddler, one way I've seen this error coming in is from an HTTP 302 error (the server says the link has been moved permanently to an https: location instead of the almost identical http: location).

I'm going to guess that the Java EWS API is not using the Secure Sockets Layer correctly (and is attempting to send to an HTTP url instead of an HTTPS url).

EDIT If you get past the 302 error, then you may very well have a problem with handling the SSL certificate properly later on. If you debug the API, you may be able to see one of those

"PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"

errors in on the stack in ServiceRequestBase.java. That means that a Truststore, somewhere cannot find a certificate, or it's not looking in the right place.

UPDATE Check which NTLM flags are getting set in the EwsJCIFSNTLMScheme class. I've seen connections fail because these flags were getting set wrong.

Use something like Fiddler to automatically (and successfully) authenticate into your EWS instance, check and see what NTLM flags are getting set (by decoding the Authorization: Negotiate headers with Fiddler in the "Inspectors", "Auth" tab - it's a 32-bit hex number), and send those hex-valued flags into the Type1 and Type3 message constructors.

Maximus
  • 1
  • 1
0

I have the same error in china.I think it's ews-java-api bug .so I check the github.com,I see the author Victor Boctor update the scrip.so I think maybe it can fix this bug.so try to compile the source code,and sure ,it fix this bug. ~_~ thanks for Victor Boctor

jun
  • 1