I think I've exhausted my options on this one. I have searched over the internet for days and couldn't find anyone with a similar problem.
I'm using the EWS Java API 1.2.1 to connect to an Exchange server and open my inbox folder to look for emails. Here is my code:
import java.net.URI;
import microsoft.exchange.webservices.data.*;
public class Connection {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials("myUser", "myPass");
service.setCredentials(credentials);
service.setUrl(new URI("https://example.com/ews/exchange.asmx"));
service.setTraceEnabled(true);
Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox);
System.out.println("messages: " + inbox.getTotalCount());
}
}
When I run it, I get the following error:
Exception in thread "main" microsoft.exchange.webservices.data.ServiceLocalException: https://example.com/ews/exchange.asmx : Connection error
at microsoft.exchange.webservices.data.ExchangeServiceBase.prepareHttpWebRequestForUrl(Unknown Source)
at microsoft.exchange.webservices.data.ExchangeService.prepareHttpWebRequest(Unknown Source)
at microsoft.exchange.webservices.data.ServiceRequestBase.buildEwsHttpWebRequest(Unknown Source)
at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(Unknown Source)
at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
at microsoft.exchange.webservices.data.ExchangeService.bindToFolder(Unknown Source)
at microsoft.exchange.webservices.data.ExchangeService.bindToFolder(Unknown Source)
at microsoft.exchange.webservices.data.Folder.bind(Unknown Source)
at microsoft.exchange.webservices.data.Folder.bind(Unknown Source)
at Connection.main(Connection.java:22)
I thought it could be something blocking my connection attempt but it does work with the above URL and User credentials when I use the JWebServices API.
BTW, I can also access the WSDL from my browser.
Any clues?
Thanks in advance!
This could be because of the wrong JARs referenced to this Class.
What are the JARs you are using. And which version of EWS API is used here.??
I faced this same Problem while using EWS API 1.2, after referring the following JARs, it got resolved.
EWSJavaAPI_1.2original.jar, EWSJavaAPIWithJars_1.2.1.jar, httpclient-4.2.5.jar, httpcore-4.2.4.jar, jcifs-1.3.17.jar, commons-codec-1.7.jar, commons-logging-1.1.1.jar
EWSJavaAPI_1.2original.jar - This is having the microsoft related Classes EWSJavaAPIWithJars_1.2.1.jar - This one is having its Connection related Classes.
Try adding these JARs.
Regards,
Ramesh G.