当前位置: 首页 > 工具软件 > EWS Java API > 使用案例 >

java ews_如何验证EWS Java API

贺雅健
2023-12-01

我们使用EWS

Java API在

Java应用程序上使用outlook日历.我在EWS上遇到了身份验证问题.

我尝试使用由rackspace提供的云Outlook帐户上的应用程序,一切正常,所以我知道凭据是准确的.

这是代码:

import java.net.URI;

import java.net.URISyntaxException;

import microsoft.exchange.webservices.data.*;

public class TestClass {

public static void main(String[] args) {

TestClass obj = new TestClass();

obj.testMethod();

}

public void testMethod() {

ExchangeService service = new ExchangeService(

ExchangeVersion.Exchange2007_SP1);

ExchangeCredentials credentials = new WebCredentials("username",

"password");

service.setCredentials(credentials);

try {

service.setUrl(new URI("https://domain/EWS/Exchange.asmx"));

} catch (URISyntaxException e) {

e.printStackTrace();

}

EmailMessage msg;

try {

msg = new EmailMessage(service);

msg.setSubject("hello world");

msg.setBody(MessageBody

.getMessageBodyFromText("Sent using the EWS API"));

msg.getToRecipients().add("test@test.com");

msg.send();

} catch (Exception e) {

e.printStackTrace();

}

}

}

rackspace的网址是:https://connect.emailsrvr.com/EWS/Exchange.asmx

当我为这个帐户输入用户名和密码并且它有效时,我看到控制台吐出这个:

Apr 05, 2013 1:40:28 PM org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme

INFO: NTLM authentication scheme selected

我们的客户端正在使用ExchangeVersion.Exchange2007_SP1,而Rackspace正在使用ExchangeVersion.Exchange2010但是当我使用客户端提供的凭据(用户名,密码和URL)时,我收到此错误:

Apr 05, 2013 1:49:13 PM org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme

INFO: Basic authentication scheme selected

Apr 05, 2013 1:49:13 PM org.apache.commons.httpclient.HttpMethodDirector processAuthenticationResponse

SEVERE: Invalid challenge: Basic

org.apache.commons.httpclient.auth.MalformedChallengeException: Invalid challenge: Basic

at org.apache.commons.httpclient.auth.AuthChallengeParser.extractParams(AuthChallengeParser.java:98)

at org.apache.commons.httpclient.auth.RFC2617Scheme.processChallenge(RFC2617Scheme.java:94)

at org.apache.commons.httpclient.auth.BasicScheme.processChallenge(BasicScheme.java:112)

at org.apache.commons.httpclient.auth.AuthChallengeProcessor.processChallenge(AuthChallengeProcessor.java:162)

at org.apache.commons.httpclient.HttpMethodDirector.processWWWAuthChallenge(HttpMethodDirector.java:694)

at org.apache.commons.httpclient.HttpMethodDirector.processAuthenticationResponse(HttpMethodDirector.java:668)

at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:193)

at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)

at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)

at microsoft.exchange.webservices.data.HttpClientWebRequest.executeRequest(HttpClientWebRequest.java:358)

at microsoft.exchange.webservices.data.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:930)

at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:825)

at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:46)

at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:144)

at microsoft.exchange.webservices.data.ExchangeService.internalCreateItems(ExchangeService.java:464)

at microsoft.exchange.webservices.data.ExchangeService.createItem(ExchangeService.java:535)

at microsoft.exchange.webservices.data.Item.internalCreate(Item.java:215)

at microsoft.exchange.webservices.data.EmailMessage.internalSend(EmailMessage.java:125)

at microsoft.exchange.webservices.data.EmailMessage.send(EmailMessage.java:253)

at com.aurora.trials.TestClass.testMethod(TestClass.java:43)

at com.aurora.trials.TestClass.main(TestClass.java:17)

microsoft.exchange.webservices.data.EWSHttpException: Connection not established

at microsoft.exchange.webservices.data.HttpClientWebRequest.throwIfConnIsNull(HttpClientWebRequest.java:394)

at microsoft.exchange.webservices.data.HttpClientWebRequest.getResponseHeaders(HttpClientWebRequest.java:280)

at microsoft.exchange.webservices.data.ExchangeServiceBase.processHttpResponseHeaders(ExchangeServiceBase.java:1045)

at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:58)

at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:144)

at microsoft.exchange.webservices.data.ExchangeService.internalCreateItems(ExchangeService.java:464)

at microsoft.exchange.webservices.data.ExchangeService.createItem(ExchangeService.java:535)

at microsoft.exchange.webservices.data.Item.internalCreate(Item.java:215)

at microsoft.exchange.webservices.data.EmailMessage.internalSend(EmailMessage.java:125)

at microsoft.exchange.webservices.data.EmailMessage.send(EmailMessage.java:253)

at com.aurora.trials.TestClass.testMethod(TestClass.java:43)

at com.aurora.trials.TestClass.main(TestClass.java:17)

我找不到任何解决这个问题的方法.请提供您认为我可以通过EWS验证的任何信息.造成这些例外的原因是什么?

 类似资料: