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
868 stars 560 forks source link

NullPointerException thrown in some Exchange environments #82

Open robnikkel opened 10 years ago

robnikkel commented 10 years ago

We are getting a NullPointerException in our usage of the Java EWS API in some client environments. We are currently using version 1.1.5 but have tried 1.2 as well. I was hoping someone could shed some light for us on how to further investigate the underlying issue.

Our product is a web application written in CFML (on top of Java) which is leveraging this Java API. I can step through our code and it looks like a connection to the EWS is being made, however when we make a call on a mailbox to "FindAttachments" it throws this exception.

Testing these environments via the MS tool https://testconnectivity.microsoft.com/ passes.

Is there a Java Client readily available that I can test server connection credentials with and test API method calls? I'm hoping to get to the source line in the API that is causing the issue to understand what is triggering it. It feels like it must be something environmental as we have a number of customers using the current implementation without issues and connecting to Office 365 or local Exchange servers. Any help would be greatly appreciated.

robnikkel commented 10 years ago

How do I attach a code sample here? It seems to strip it our in the markup when I paste it in

vboctor commented 10 years ago

@robnikkel consider publishing a github gist and referencing it from here. If you search for "github gist" you will find more information.

evpaassen commented 10 years ago

@robnikkel Take a look at this page: https://help.github.com/articles/github-flavored-markdown/

robnikkel commented 10 years ago
<cfset oService.exchangeVersion = application.Compat.JavaCreate("microsoft.exchange.webservices.data.ExchangeVersion", ewsPath)>
<cfset oService.service = application.Compat.JavaCreate("microsoft.exchange.webservices.data.ExchangeService", ewsPath).init( oReturn.exchangeVersion.Exchange2007_SP1 )>

<cfset credentials = application.Compat.JavaCreate("microsoft.exchange.webservices.data.WebCredentials", ewsPath).init(arguments.sUserName, sPasswordDecrypted)>
<cfset oService.service.setCredentials(credentials)>

<cfset serviceUri = CreateObject("java", "java.net.URI").init(arguments.sWebServiceURL)>
<cfset oService.service.setUrl(serviceUri)>

<cfset WellKnownFolderName = application.Compat.JavaCreate("microsoft.exchange.webservices.data.WellKnownFolderName", oService.ewsPath)>
<cfset mailbox = application.Compat.JavaCreate("microsoft.exchange.webservices.data.Mailbox", oService.ewsPath).init("#arguments.sUserName#")>
<cfset calendar = application.Compat.JavaCreate("microsoft.exchange.webservices.data.FolderId", oService.ewsPath).init(WellKnownFolderName.Calendar, mailbox)>
<cfset formatter = CreateObject("java", "java.text.SimpleDateFormat").init("yyy-MM-dd")>
<cfset startDate = formatter.parse("#Year(now())#-#Month(now())#-#Day(now())#")>
<cfset endDate = formatter.parse("#Year(now())#-#Month(now())#-#Day(now())#")>
<cfset calendarview = application.Compat.JavaCreate("microsoft.exchange.webservices.data.CalendarView", oService.ewsPath).init(startDate, endDate, 1)>
<cfset results = oService.service.FindAppointments(calendar, calendarview)>
robnikkel commented 10 years ago

Looking in the "src" code folder I can find two places where a NullPointerException is thrown: 1) AsyncExecuter.submit() 2) UserConfigurationDictionary.validateObject() Not sure if there are any clues here but looks like the UserConfiguration seems more likely the culprit.

robnikkel commented 10 years ago

Does this API not support Exchange 2013? I'm wondering if we simply need to replace this API usage with one that does? Eg. JWebServices.

This topic online makes me think 2013 is not supported:

http://stackoverflow.com/questions/21612829/can-i-use-the-microsoft-exchange-2013-api-from-java

serious6 commented 10 years ago

@robnikkel did you investigate the NullPointerException just by looking at the code where these exceptions are explicitly thrown or did you get the information by locking at the stacktrace? As mentioned in #58 the use of exchange 2013 should be no problem.

robnikkel commented 10 years ago

We are implementing this API within ColdFusion CFML and we don't get a full stack trace, simply a NullPointerException. No line number, no further clues. I'm wondering if it's not Exchange 2013 support, maybe it's environments with a proxy. How could we confirm that? Any help or clues to troubleshoot this would be hugely appreciated. If we can't solve this, we're going to have to look at replacing this API, especially considering it does not seem to actively supported by Microsoft anymore

vboctor commented 10 years ago

@robnikkel did you try creating a hello world java client that connects to your Exchange mailbox to test environment issues from? This is likely to give you more details than Cold Fusion and help you get more context.

robnikkel commented 10 years ago

Victor, I haven't done much Java programming in a while. Do you have one I can grab? Would save me some time figuring it out. We use an Eclipse dev environment so I'm assuming it should be relatively easy to create one but Java is not my expertise.