Java中MS-Exchange获取任务

Java中MS-Exchange获取任务,java,exchange-server-2007,outlook-2003,Java,Exchange Server 2007,Outlook 2003,从Exchange服务器检索任务列表时遇到问题。我已经有了添加和更新任务的代码,但是我无法继续进行检索。下面是它的代码: public void getEvents(String a_sPrefix, String a_sMailboxName, String a_sFolderName) throws ExchangeException, IOException { WebdavResource wrFolder = getExchangeWebdavResource

从Exchange服务器检索任务列表时遇到问题。我已经有了添加和更新任务的代码,但是我无法继续进行检索。下面是它的代码:

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; }
     */
}
我正在连接一个虚拟机,如果这有什么用的话。如果你想要更多的信息,不要犹豫

软件:

虚拟机:

  • 微软视窗服务器2003
  • MS Outlook 2003
  • 微软WindowsExchangeServer2007

编辑:一个小小的误解。我正在尝试从exchange日历中获取事件/任务。有什么帮助吗?
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);
}