Note that there are some explanatory texts on larger screens.

plurals
  1. POObtaining tasks by MS Exchange in Java
    text
    copied!<p>I'm having a problem retrieving a list of tasks from the Exchange Server. I already have the code for adding and updating tasks, but I cannot get the retrieving going. Here's the code for it:</p> <pre><code>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 &amp;&amp; a_sPrefix.length() &gt; 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 = "&lt;?xml version=\"1.0\"?&gt;" + "&lt;D:searchrequest xmlns:D = \"DAV:\" xmlns:e = \"http://schemas.microsoft.com/exchange/\"&gt;" + "&lt;D:sql&gt;" + "SELECT "/*\"DAV:uid\"*/ + "FROM \"" + sFolderUrl + "\" " + // "WHERE \"e:extensionattribute1\" = '"+a_exEvent.getId()+"'" + "&lt;/D:sql&gt;" + "&lt;/D:searchrequest&gt;"; 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&lt;String&gt; enumMatchingUrls = searchMethod.getAllResponseURLs(); while (enumMatchingUrls != null &amp;&amp; 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 &amp;&amp; enumMatchingUrls.hasMoreElements()) { * sEventUrl = (String)enumMatchingUrls.nextElement(); bExists = true; } * else { // This is a new contact: sEventUrl = sFolderUrl + "/" + * a_exEvent.getUniqueIdForUrl() + ".EML"; bExists = false; } */ } </code></pre> <p>Code for adding a task:</p> <pre><code>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); } </code></pre> <p>I'm connecting to a VM, if that's of any use. If you want some additional information, don't hesitate.</p> <p>Software:</p> <p>VM:</p> <ul> <li>MS Windows Server2003 </li> <li>MS Outlook 2003 </li> <li>MS Windows Exchange Server 2007.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload