Hello java guru,
have some task to do, any useful replies need.
It is get mail (contacts, calendar, etc ... ) from Exchange webdav (OWA outlook web access) server. I use jackrabbit and httpclient, I can connect to exchange webdav folder like ( http://server/exchange/test ) get properties from it, but have no idea how to get information. I think i must use some XML query to exchange and get XML responce, but have no idea, how to do it.
appreciate for any useful information.
Thanks.
sources i using
package exchFetchMail;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.jackrabbit.webdav.DavConstants;
import org.apache.jackrabbit.webdav.DavMethods;
import org.apache.jackrabbit.webdav.MultiStatus;
import org.apache.jackrabbit.webdav.client.methods.BaselineControlMethod;
import org.apache.jackrabbit.webdav.client.methods.CheckoutMethod;
import org.apache.jackrabbit.webdav.client.methods.CopyMethod;
import org.apache.jackrabbit.webdav.client.methods.DavMethod;
import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
import org.apache.jackrabbit.webdav.property.DavPropertySet;
import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
public class ExchangeAccess {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String uri = "http://192.168.132.140/exchange/test/";
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setHost(uri);
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
int maxHostConnections = 20;
params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
connectionManager.setParams(params);
HttpClient client = new HttpClient(connectionManager);
client.setHostConfiguration(hostConfig);
Credentials creds = new NTCredentials("Administrator", "q1", "192.168.132.140", "company.com");
client.getState().setCredentials(AuthScope.ANY, creds);
// GetMethod get = new GetMethod("http://192.168.132.140/exchange/test/");
// get.setDoAuthentication( true );
// try {
// // execute the GET
// int status = client.executeMethod( get );
//
// // print the status and response
// System.out.println(status + "\n" + get.getResponseBodyAsString());
// } finally {
// // release any connection resources used by the method
// get.releaseConnection();
// }
DavMethod pFind = new PropFindMethod("http://192.168.132.140/exchange/test/", DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_INFINITY);
System.out.println();
client.executeMethod(pFind);
MultiStatus multiStatus = pFind.getResponseBodyAsMultiStatus();
//Not quite nice, but for a example ok
DavPropertySet props = multiStatus.getResponses()[0].getProperties(200);
Collection<DefaultDavProperty> propertyColl=props.getContent();
propertyColl.iterator();
for(Iterator<DefaultDavProperty> iterator = propertyColl.iterator(); iterator.hasNext();){
DefaultDavProperty tmpProp=iterator.next();
System.out.println(tmpProp.getName() +" "+ tmpProp.getValue());
}
// String propfindUri = "http://192.168.132.140/exchange/test/Inbox";
// DavMethod method = new PropFindMethod(propfindUri, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1);
// client.executeMethod(method);
//
// method.checkSuccess();
// MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
}
}