使用commons-httpclient和EWSJavaAPI获取nullPointerException

Mah*_*leh 5 web-services jtapi exchangewebservices ewsjavaapi cisco-jtapi

我正在使用EWS Java API 1.1.5 ,我试图将服务绑定到收件箱文件夹,如下所示:

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);
Run Code Online (Sandbox Code Playgroud)

我从jsp页面调用上面的代码.

但我得到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)
Run Code Online (Sandbox Code Playgroud)

我正在使用commons-httpclient 3.1.

从运行在tomcat 7上的Web项目运行代码时会发生此异常,但是从桌面应用程序运行代码时它可以正常工作.

更新:

1-例外的httpclient调试:

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()
Run Code Online (Sandbox Code Playgroud)

异常之前的2 EWS跟踪:

<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>
Run Code Online (Sandbox Code Playgroud)

并且它应该发送以下请求:

<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>
Run Code Online (Sandbox Code Playgroud)

但事实并非如此,而是抛出异常.

UPDATE2:忘了提到我正在使用Cisco jtapi 6.1库处理IP电话,谷歌搜索后发现以下问题在最新版本的jtapi中得到解决:

CSCtz31973 : Ews request printed is Null in case of StreamingSubscriptionRequest 
Run Code Online (Sandbox Code Playgroud)

我的理解是EWS请求是null(无法发送microsoft webservices请求),所以我将更新jtapi库并试一试.

请告知如何解决它.

Mah*_*leh 4

升级jaxws-rtsaaj-api的 jar 后问题已解决,如下所示:

    <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>
Run Code Online (Sandbox Code Playgroud)