我在从 Exchange Server 检索任务列表时遇到问题。我已经有了添加和更新任务的代码,但我无法进行检索。这是它的代码:
public void getEvents(String a_sPrefix, String a_sMailboxName,
String a_sFolderName) throws ExchangeException, IOException {
WebdavResource wrFolder = getExchangeWebdavResource(a_sPrefix,
a_sMailboxName, a_sFolderName);
// Get the session:
HttpClient httpClient = wrFolder.retrieveSessionInstance();
String sPrefix = "";
if (a_sPrefix != null && a_sPrefix.length() > 0) {
sPrefix = a_sPrefix + "/";
}
// Build the Url of the contacts folder:
String sFolderUrl = m_sExchangeUrl + sPrefix + a_sMailboxName + "/"
+ a_sFolderName;
// Escape any spaces:
sFolderUrl = sFolderUrl.replaceAll("\\s", "%20");
// Try to find the event first:
String sQuery = "<?xml version=\"1.0\"?>"
+ "<D:searchrequest xmlns:D = \"DAV:\" xmlns:e = \"http://schemas.microsoft.com/exchange/\">"
+ "<D:sql>" + "SELECT "/*\"DAV:uid\"*/ + "FROM \"" + sFolderUrl + "\" " +
// "WHERE \"e:extensionattribute1\" = '"+a_exEvent.getId()+"'" +
"</D:sql>" + "</D:searchrequest>";
System.out.println("The Query:" + sQuery);
SearchMethod searchMethod = new SearchMethod(sFolderUrl, sQuery);
int iStatusCode = httpClient.executeMethod(searchMethod);
// See if there was an error:
handleReturnCode(iStatusCode);
Enumeration resp = searchMethod.getResponses();
byte[] b = searchMethod.getResponseBody();
Enumeration<String> enumMatchingUrls = searchMethod.getAllResponseURLs();
while (enumMatchingUrls != null && enumMatchingUrls.hasMoreElements()) {
String sEventUrl = (String) enumMatchingUrls.nextElement();
Enumeration ob = searchMethod.getResponseProperties(sEventUrl);
while (ob.hasMoreElements()) {
BaseProperty v = (BaseProperty) ob.nextElement();
log(v.toString());
}
}
/*
* if (enumMatchingUrls != null && enumMatchingUrls.hasMoreElements()) {
* sEventUrl = (String)enumMatchingUrls.nextElement(); bExists = true; }
* else { // This is a new contact: sEventUrl = sFolderUrl + "/" +
* a_exEvent.getUniqueIdForUrl() + ".EML"; bExists = false; }
*/
}
添加任务的代码:
public static void addEventToExchange(String login, String password,
TaskDTO task) {
// TODO: iommi - finish
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
String sExchangeServerUrl = "http://url.which.pings.com";
// Account name of an exchange user that has permission to see and modify
// other user's mailboxes.
String sApplicationUserAccountName = "login";
String sApplicationUserPassword = "p@ssw0rd";
// Connect to exchange.
ExchangeBridge exchangeBridge = new ExchangeBridge(sExchangeServerUrl,
sApplicationUserAccountName, sApplicationUserPassword);
HashMap out = new HashMap();
Vector ret = null;
try {
String mailbox = "iommi";
String folder = ExchangeConstants.k_sInboxName;
long lSince_TimeInMillisecs = System.currentTimeMillis()
- (1000 * 60 * 60 * 24);
/*
* ret = exchangeBridge.getEmails(mailbox, folder, lSince_TimeInMillisecs,
* null, null, 100);
*/
java.util.Calendar c = java.util.Calendar.getInstance();
ExchangeEvent a_exEvent = task.getDTOasExchangeEvent();
// a_exEvent.setBusyStatus(ExchangeEvent.);
// a_exEvent.setStartDate(c.getTime());
// c.add(java.util.Calendar.HOUR, 1);
// a_exEvent.setEndDate(c.getTime());
// a_exEvent.setSubject(subject);
// a_exEvent.setDescription(decription);
// a_exEvent.setUniqueIdForUrl("i" + c.getTimeInMillis());
String a_sPrefix = ExchangeConstants.k_sExchangeName;
exchangeBridge.updateEvent(a_sPrefix, "iommi",
ExchangeConstants.k_sCalendarName, a_exEvent);
exchangeBridge.getEvents(a_sPrefix, "iommi",
ExchangeConstants.k_sCalendarName);
} catch (ExchangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// exchangeBridge.getContacts(a_sPrefix, a_sMailboxName, a_sFolderName);
// exchangeBridge.getEmails(a_sMailboxName, a_sFolderName,
// a_lDateReceived, a_hmFromEmailFilter, a_hmToEmailFilter, a_iMaxAtATime);
}
我正在连接到一个虚拟机,如果这有任何用处的话。如果您想了解更多信息,请不要犹豫。
软件:
虚拟机:
- 微软视窗服务器2003
- 微软展望 2003
- 微软视窗交换服务器 2007。