exchangeservice java,无法建立与Exchange Web服务的连接 - Java API

I am testing the Microsoft Exchange Web Service Java API (version 1.2) to read mails from a server. Here is my code:

String url = "https://my-server/EWS/exchange.asmx";

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

service.setTraceEnabled(true);

service.setCredentials(new WebCredentials("user", "password"));

service.setUrl(url.toURI());

Mailbox mailbox = new Mailbox("foo@bar.com");

FolderId folder = new FolderId(WellKnownFolderName.Inbox, mailbox);

ItemView view = new ItemView(10);

view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Descending);

FindItemsResults items = service.findItems(folder, view);

Unfortunately, this code throws the following error:

Exception in thread "main" microsoft.exchange.webservices.data.EWSHttpException: Connection not established

at microsoft.exchange.webservices.data.HttpClientWebRequest.throwIfConnIsNull(Unknown Source)

at microsoft.exchange.webservices.data.HttpClientWebRequest.getResponseCode(Unknown Source)

at microsoft.exchange.webservices.data.EwsUtilities.formatHttpResponseHeaders(Unknown Source)

at microsoft.exchange.webservices.data.ExchangeServiceBase.traceHttpResponseHeaders(Unknown Source)

at microsoft.exchange.webservices.data.ExchangeServiceBase.processHttpResponseHeaders(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.findItems(Unknown Source)

at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)

at foo.bar.TestMail.main(TestMail.java:52)

I'm not able to understand what is wrong with the current code. Do you have any clue, or at least some tests to try?

Note that the web-service (https//my-server/exchange.asmx) is accessible to my Java code.

Not sure if it can help, but I've found that in the traces displayed by the logs:

ErrorThe function requested is not supported

EDIT

I've made another test. This time, I use the defaults credentials - so my own email account - using service.setUseDefaultCredentials(true); instead of setting the WebCredentials object. The connection is still not established, but I get another error (I've took only the interesting part of the trace log):

You are not authorized to view this page

You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept.

(...)

HTTP Error 401.2 - Unauthorized: Access is denied due to server configuration.
Internet Information Services (IIS)

Of course, I can't access nor change anything on the Exchange server side. Is there a way to make the authentication successful?

解决方案

The problem is due to the authentication scheme used. By default, EWS uses NTLM, but my Exchange server is not configured to accept this kind of authentication. I have to use LDAP authentication.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值