You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-user@jakarta.apache.org by Tim Kitchens <tk...@Unwiredexpress.com> on 2002/08/02 21:55:00 UTC

RE: Help needed with SearchMethod

John,

I've had success with getting calendar data from Exchange.  Here are some code snippets:

            public final static String EXCHANGE_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss";
            public final static SimpleDateFormat EXCHANGE_DATE_FORMATTER =
                    new SimpleDateFormat(EXCHANGE_DATE_FORMAT);

            ...

            public String[] getAppointmentsForDateRange(Date from, Date to,
                String domainAndUser, String password, String exchangeHost,
                String relativePathToUserFolder, String resourceURL)
            {

                StringBuffer query = new StringBuffer();
                query.append("<?xml version=\"1.0\"?>");
                query.append("<d:searchrequest xmlns:d=\"DAV:\">");
                query.append("<d:sql>");
                query.append("SELECT  \"urn:schemas:mailheader:subject\", ");
                query.append("        \"urn:schemas:mailheader:to\",  ");
                query.append("        \"urn:schemas:calendar:dtstart\",  ");
                query.append("        \"urn:schemas:calendar:dtend\",  ");
                query.append("FROM SCOPE('shallow traversal of ");
                query.append("\"" + resourceURL + "\"')");
                String fromDate = EXCHANGE_DATE_FORMATTER.format(from);
                String toDate = EXCHANGE_DATE_FORMATTER.format(to);
                query.append(" WHERE \"urn:schemas:calendar:dtstart\" &gt; \'" + fromDate + "\'");
                query.append(" AND \"urn:schemas:calendar:dtend\" &lt; \'" + toDate + "\'");         
                query.append("</d:sql>");
                query.append("</d:searchrequest>");
                query.append("        \"urn:schemas:calendar:location\"  ");

                ...
            }

However, I'm now trying to get the contacts for an appointment.  I'm referring to the contacts that are associated with an appointment when a user selects the "Contacts" button at the bottom of the Outlook window.  Does anyone know whether is available via WebDav.  I've tried including various URNs in my query, including the "urn:schemas:contacts:*" URNs.  These are always returned as "404 Resource Not Found", when I can see there are contacts associated with the appointment.  Maybe the contacts info is stored on the client and not on the server?


Thanks,
Tim



NOTICE:  This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.

To contact our email administrator directly, send to postmaster@unwiredexpress.com


-----Original Message-----
From: John Scudder [mailto:jscudder@cis.ysu.edu]
Sent: Friday, June 14, 2002 1:11 PM
To: slide-user@jakarta.apache.org
Subject: Help needed with SearchMethod 


/*
Tim

In my work, I haven't had to access calendaring and contacts yet,
but I'd be interested to see a small example of what you come up with.

To explore your
Exchange 2000 server without writing code, use the Web Storage System
Explorer,
available as part of a download from Microsoft at
http://download.microsoft.com/download/exchplatinumbeta/Update/March_2002/NT5/EN-US/ExchangeSDKTools.exe
.
It will give you most if not all of the properties with Exchange

Some other recommended reading of a Slide competitor I am aware of is at
http://www.compoze.com/products_hme.html

Javadocs for the HttpClient can be found at
http://nagoya.apache.org/gump/javadoc/jakarta-commons/httpclient/dist/docs/api/index.html

If you're programming Exchange with Java, you also might want to have this
on your bookshelf
http://www.amazon.com/exec/obidos/ASIN/0130618276/qid%3D1023986090/ref%3Dsr%5F11%5F0%5F1/002-4036701-8700869

With the following example, you'll need commons-httpclient.jar,
webdav.jar, and webdavlib.jar
in your classpath, all of which are available from the apache website. If
you are using
JDK 1.4 you won't need any XML jar files in your classpath, but if you are
using any JDK
less than that you'll need a DOM parser.
Here is some code to access and query Exchange messages:

*/


import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
import org.apache.webdav.lib.methods.SearchMethod;
import org.w3c.dom.Document;

public class Exchange2000QueryExample {

  public static void main(String [] args) {

    HttpClient client = new HttpClient();

    try {

      client.setDebug(10);
      client.startSession(//String-IP ADDRESS of Exchange server,
                          //int-PORT,
                          //new Credentials(String-DOMAIN/Username,
                          //                String-PASSWORD));
                          "IPADDRESS", 80,
                          new Credentials("DOMAIN/USERNAME", "PASSWORD")
                         );


      StringBuffer query = new StringBuffer();
      query.append("<?xml version=\"1.0\"?>");
      query.append("<d:searchrequest xmlns:d=\"DAV:\">");
      query.append("<d:sql>");
      query.append("SELECT  \"DAV:id\", ");
      query.append("        \"urn:schemas:httpmail:subject\",  ");
      query.append("        \"urn:schemas:httpmail:from\",  ");
      query.append("        \"urn:schemas:httpmail:displayto\",  ");
      query.append("        \"urn:schemas:httpmail:textdescription\"  ");
      query.append("FROM SCOPE('shallow traversal of ");
      //query.append("\"" + "String-path to exact user folder such as
inbox" + "\"')");
      query.append("\"" + "http://IPADDRESS/exchange/USERNAME/inbox" +
"\"')");
      query.append("</d:sql>");
      query.append("</d:searchrequest>");

      System.out.println(query.toString());

      SearchMethod sm = new SearchMethod(
                     //String-path to user's folder such as
/exchange/username/,
                     "/exchange/USERNAME/",
                     query.toString());

      client.executeMethod(sm);

      Document domResponseDocument = sm.getResponseDocument();
      if (domResponseDocument == null) {
        System.out.println("No exchange messages found");
      } else {
        System.out.println("you have a DOM document with the results of
your query ");
      }

    } catch (Exception e) {
      System.out.println("Error with Exchange");
      e.printStackTrace();
    } finally {
      try {
        client.endSession();
      } catch (Exception e) {
        System.out.println("Error closing connection to Exchange");
        e.printStackTrace();
      }
    }
  }

}


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>