无法建立与Exchange Web服务的连接 – Java API

前端之家收集整理的这篇文章主要介绍了无法建立与Exchange Web服务的连接 – Java API前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在测试Microsoft Exchange Web服务Java API(版本1.2)以从服务器读取邮件.这是我的代码
  1. String url = "https://my-server/EWS/exchange.asmx";
  2. ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
  3. service.setTraceEnabled(true);
  4. service.setCredentials(new WebCredentials("user","password"));
  5. service.setUrl(url.toURI());
  6.  
  7. MailBox mailBox = new MailBox("foo@bar.com");
  8. FolderId folder = new FolderId(WellKnownFolderName.InBox,mailBox);
  9. ItemView view = new ItemView(10);
  10. view.getOrderBy().add(ItemSchema.DateTimeReceived,SortDirection.Descending);
  11. FindItemsResults<Item> items = service.findItems(folder,view);

不幸的是,此代码抛出以下错误

  1. Exception in thread "main" microsoft.exchange.webservices.data.EWSHttpException: Connection not established
  2. at microsoft.exchange.webservices.data.HttpClientWebRequest.throwIfConnIsNull(Unknown Source)
  3. at microsoft.exchange.webservices.data.HttpClientWebRequest.getResponseCode(Unknown Source)
  4. at microsoft.exchange.webservices.data.EwsUtilities.formatHttpResponseHeaders(Unknown Source)
  5. at microsoft.exchange.webservices.data.ExchangeServiceBase.traceHttpResponseHeaders(Unknown Source)
  6. at microsoft.exchange.webservices.data.ExchangeServiceBase.processHttpResponseHeaders(Unknown Source)
  7. at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)
  8. at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
  9. at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
  10. at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
  11. at foo.bar.TestMail.main(TestMail.java:52)

我无法理解当前代码错误.你有任何线索,或至少一些测试尝试?

请注意,我的Java代码可以访问Web服务(https // my-server / exchange.asmx).

不确定它是否可以提供帮助,但我发现在日志显示的跟踪中:

  1. <Trace Tag="EwsResponse" Tid="1" Time="2013-01-28 10:47:03Z">
  2. <html><head><title>Error</title></head><body>The function requested is not supported
  3. </body></html>
  4. </Trace>

编辑

我做了另一个测试.这一次,我使用默认凭据 – 所以我自己的电子邮件帐户 – 使用service.setUseDefaultCredentials(true);而不是设置WebCredentials对象.连接仍然没有建立,但我得到另一个错误(我只采取了跟踪日志的有趣部分):

  1. <h1>You are not authorized to view this page</h1>
  2. 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.
  3. (...)
  4. <h2>HTTP Error 401.2 - Unauthorized: Access is denied due to server configuration.<br>Internet Information Services (IIS)</h2>

当然,我无法在Exchange服务器端访问或更改任何内容.有没有办法使身份验证成功?

解决方法

问题是由于使用的身份验证方案.默认情况下,EWS使用NTLM,但我的Exchange服务器未配置为接受此类身份验证.我必须使用LDAP身份验证.

猜你在找的HTML相关文章