Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting nullPointerException with commons-httpclient and EWSJavaAPI

i am using EWS Java API 1.1.5 and i am trying to bind the service to inbox folder as follows:

ExchangeService service = new ExchangeService();
        ExchangeCredentials credentials = new WebCredentials(email, password);
        service.setCredentials(credentials);
        service.setUrl(new java.net.URI("https://" + host
                + "/EWS/Exchange.asmx"));
Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox);

i call the above code from jsp page.

but i am getting NullPointerException:

java.lang.NullPointerException
    at org.apache.commons.httpclient.HttpMethodBase.getStatusCode(HttpMethodBase.java:570)
    at microsoft.exchange.webservices.data.HttpClientWebRequest.getResponseCode(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 com.xeno.phonesuite.web.Mail.Mail.readInbox(Mail.java:49)
    at org.apache.jsp.mail.inbox_jsp._jspService(inbox_jsp.java:79)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

i am using commons-httpclient 3.1.

this exception occurs when running the code from a web project that runs on tomcat 7, but when running the code from desktop application it works fine.

UPDATE:

1- httpclient debugs before exception:

2012-11-07/16:37:32.425 [http-bio-8080-exec-2] DEBUG Set parameter http.auth.scheme-priority = [NTLM, Basic, Digest]
2012-11-07/16:37:32.425 [http-bio-8080-exec-2] DEBUG enter HttpState.setCredentials(AuthScope, Credentials)
2012-11-07/16:37:32.425 [http-bio-8080-exec-2] DEBUG Set parameter http.socket.timeout = 100000
2012-11-07/16:37:32.425 [http-bio-8080-exec-2] DEBUG Set parameter http.connection.timeout = 100000
2012-11-07/16:37:32.425 [http-bio-8080-exec-2] DEBUG enter PostMethod.clearRequestBody()
2012-11-07/16:37:32.425 [http-bio-8080-exec-2] DEBUG enter EntityEnclosingMethod.clearRequestBody()

2- EWS trace before exception:

<Trace Tag="EwsRequestHttpHeaders" Tid="33" Time="2012-11-07 15:14:24Z">
POST /EWS/Exchange.asmx HTTP/1.1
Content-type : text/xml; charset=utf-8
Accept-Encoding : gzip,deflate
Keep-Alive : 300
User-Agent : ExchangeServicesClient/0.0.0.0
Connection : Keep-Alive
Accept : text/xml


</Trace>

and its supposed to send then the following request:

<Trace Tag="EwsRequest" Tid="1" Time="2012-11-07 15:18:19Z">
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><soap:Header><t:RequestServerVersion Version="Exchange2010_SP1"></t:RequestServerVersion></soap:Header><soap:Body><m:FindItem Traversal="Shallow"><m:ItemShape><t:BaseShape>AllProperties</t:BaseShape></m:ItemShape><m:IndexedPageItemView MaxEntriesReturned="5" Offset="0" BasePoint="Beginning"></m:IndexedPageItemView><m:ParentFolderIds><t:DistinguishedFolderId Id="inbox"></t:DistinguishedFolderId></m:ParentFolderIds></m:FindItem></soap:Body></soap:Envelope>
</Trace>

but it doesn't, and it throws the exception instead.

UPDATE2: forgot to mention that i am using Cisco jtapi 6.1 library for dealing with IP phones, and after googling i found that the following issue is resolved in latest version of jtapi:

CSCtz31973 : Ews request printed is Null in case of StreamingSubscriptionRequest 

what i understand is that the EWS requests is null (cannot send microsoft webservices requests), so i will update the jtapi library and give it a try.

please advise how to fix it.

like image 356
Mahmoud Saleh Avatar asked Oct 07 '22 02:10

Mahmoud Saleh


1 Answers

Problem solved after upgrading the jars for jaxws-rt and saaj-api as follows:

    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.2.7</version>
    </dependency>

    <dependency>
        <groupId>javax.xml.soap</groupId>
        <artifactId>saaj-api</artifactId>
        <version>1.3.4</version>
    </dependency>
like image 155
Mahmoud Saleh Avatar answered Oct 28 '22 08:10

Mahmoud Saleh