<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Connecting Java to Exchange over WebDAV, with Apache HttpClient</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx</link><description>Earlier I mentioned a Java Exchange Connector I had seen, and in that post I also said that I had some code that connected from Java to Exchange Server via WebDAV. Some people have asked for the code, so here it is. I use a set of Apache libraries to</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>https server example</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx#8783581</link><pubDate>Mon, 28 Jul 2008 13:10:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8783581</guid><dc:creator>https server example</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://ivanblog.gigazu.com/httpsserverexample.html"&gt;http://ivanblog.gigazu.com/httpsserverexample.html&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Connecting Java to Exchange over WebDAV, with Apache HttpClient</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx#8784401</link><pubDate>Mon, 28 Jul 2008 17:32:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8784401</guid><dc:creator>Peter</dc:creator><description>&lt;p&gt;Dino,&lt;/p&gt;
&lt;p&gt;Thank you very much for taking the time to pull this together. It is greatly appreciated.&lt;/p&gt;
&lt;p&gt;Peter,&lt;/p&gt;</description></item><item><title>Connecting to Exchange using JAX-WS, part 1</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx#8789664</link><pubDate>Tue, 29 Jul 2008 21:56:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8789664</guid><dc:creator>All About Interop</dc:creator><description>&lt;p&gt;Yes, it is possible to Connect to Exchange using JAX-WS The fear and trepidation I had when considering&lt;/p&gt;
</description></item><item><title>re: Connecting Java to Exchange over WebDAV, with Apache HttpClient</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx#9291023</link><pubDate>Thu, 08 Jan 2009 02:00:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9291023</guid><dc:creator>mpredosin</dc:creator><description>&lt;p&gt;I've noticed a 302 is issued regardless of the credentials. &amp;nbsp;Is there a different way for determining when the correct credentials have been sent?&lt;/p&gt;
</description></item><item><title>re: Connecting Java to Exchange over WebDAV, with Apache HttpClient</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx#9302211</link><pubDate>Fri, 09 Jan 2009 20:06:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9302211</guid><dc:creator>mpredosin</dc:creator><description>&lt;p&gt;After inspecting the Evolution source (&lt;a rel="nofollow" target="_new" href="http://projects.gnome.org/evolution/index.shtml"&gt;http://projects.gnome.org/evolution/index.shtml&lt;/a&gt;), I found their Exchange connector checks for a &amp;lt;BASE&amp;gt; tag containing an href pointing to the user's mailbox.&lt;/p&gt;
&lt;p&gt;&amp;lt;HTML&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;HEAD&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;META HTTP-EQUIV=&amp;quot;Content-Type&amp;quot; CONTENT=&amp;quot;text/html; CHARSET=iso-8859-1&amp;quot;&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;TITLE&amp;gt;Microsoft Outlook Web Access&amp;lt;/TITLE&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;BASE href=&amp;quot;&lt;a rel="nofollow" target="_new" href="https://mail.nowhere.net/exchange/Nobody/&amp;quot;&amp;gt;"&gt;https://mail.nowhere.net/exchange/Nobody/&amp;quot;&amp;gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;/HEAD&amp;gt;&lt;/p&gt;
</description></item><item><title>re: Connecting Java to Exchange over WebDAV, with Apache HttpClient</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx#9302726</link><pubDate>Sat, 10 Jan 2009 00:39:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9302726</guid><dc:creator>DotNetInterop</dc:creator><description>&lt;P&gt;I think a 401 is returned when you need to authenticate, and then the next response is... I don't know what. &amp;nbsp;If it is a 302, whether or not the creds are correct, then I would guess you'd have to distinguish based on the target of the 302 redirection, or perhaps something else.&amp;nbsp; But it seems like the BASE element is a good one. &lt;/P&gt;
&lt;P&gt;Sorry I was not of more help but this topic has long been swapped out of my hippocampus at this point!&lt;/P&gt;
&lt;P&gt;Can you post your code that looked for the BASE ? &lt;/P&gt;</description></item><item><title>re: Connecting Java to Exchange over WebDAV, with Apache HttpClient</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx#9311885</link><pubDate>Tue, 13 Jan 2009 04:29:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9311885</guid><dc:creator>mpredosin</dc:creator><description>&lt;p&gt;I used an open source library called htmlparser (&lt;a rel="nofollow" target="_new" href="http://htmlparser.sourceforge.net/"&gt;http://htmlparser.sourceforge.net/&lt;/a&gt;) to do the actual parsing of the html.&lt;/p&gt;
&lt;p&gt;Sample code:&lt;/p&gt;
&lt;p&gt;Parser parser = new Parser(body);&lt;/p&gt;
&lt;p&gt;NodeList list = parser.parse (new TagNameFilter(&amp;quot;BASE&amp;quot;));&lt;/p&gt;
&lt;p&gt;if(list.size() &amp;gt; 0) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Node node = list.elementAt(0);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Tag tag = (Tag) node;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if (tag instanceof BaseHrefTag) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BaseHrefTag baseHref = (BaseHrefTag) tag;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;URL url = new URL(baseHref.getBaseUrl());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;The code will pass the body of the response into the Parser ctor. &amp;nbsp;Authentication succeeds if a valid href containing the user's mailbox is found in the BASE tag.&lt;/p&gt;
</description></item><item><title>re: Connecting Java to Exchange over WebDAV, with Apache HttpClient</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx#9459606</link><pubDate>Thu, 05 Mar 2009 14:57:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9459606</guid><dc:creator>Ben Empson</dc:creator><description>&lt;p&gt;Dino, thanks for this code, very useful :) In terms of checking for correct login, I found that this code works for me:&lt;/p&gt;
&lt;p&gt;			//The response from Exchange says redirect whether this is a successful login or not. &lt;/p&gt;
&lt;p&gt;			//Thus, we must follow the redirect to see where it takes us to determine whether we've&lt;/p&gt;
&lt;p&gt;			//logged in successfully or not...&lt;/p&gt;
&lt;p&gt;			if (stat == 302) {&lt;/p&gt;
&lt;p&gt;				Header location = method.getResponseHeader(&amp;quot;location&amp;quot;);&lt;/p&gt;
&lt;p&gt;				GetMethod getMethod = new GetMethod(location.getValue());&lt;/p&gt;
&lt;p&gt;				sb.append(&amp;quot;Following redirect to: &amp;quot; + location.getValue());&lt;/p&gt;
&lt;p&gt;				rc = httpclient.executeMethod(getMethod);&lt;/p&gt;
&lt;p&gt;				stat = getMethod.getStatusLine().getStatusCode();&lt;/p&gt;
&lt;p&gt;				headers = getMethod.getResponseHeaders();&lt;/p&gt;
&lt;p&gt;				sb.append(&amp;quot;\n\nSecond call&amp;quot;);&lt;/p&gt;
&lt;p&gt;				sb.append(&amp;quot;\nStatus: &amp;quot; + Integer.toString(stat) + &amp;quot;\n&amp;quot;);&lt;/p&gt;
&lt;p&gt;				for (int x=0; x&amp;lt;headers.length; x++)&lt;/p&gt;
&lt;p&gt;					sb.append(headers[x].toString());&lt;/p&gt;
&lt;p&gt;				String body = getMethod.getResponseBodyAsString();&lt;/p&gt;
&lt;p&gt;				sb.append(&amp;quot;Body: &amp;quot; + body);&lt;/p&gt;
&lt;p&gt;				//with a successful login we seem to get a 404, with an unsuccessful login we get the login page back. Therefore&lt;/p&gt;
&lt;p&gt;				//let's test for the login page&lt;/p&gt;
&lt;p&gt;				if (body.indexOf(&amp;quot;You could not be logged on to Outlook Web Access&amp;quot;) &amp;gt; -1)&lt;/p&gt;
&lt;p&gt;					//we have not logged in - return an error&lt;/p&gt;
&lt;p&gt;					throw new Exception(&amp;quot;Unable to login&amp;quot;);&lt;/p&gt;
&lt;p&gt;				if (debugRequests)&lt;/p&gt;
&lt;p&gt;					SaveToFile(GetLocalLogPath() + &amp;quot;webDAV_Login_&amp;quot; + accountID + &amp;quot;.txt&amp;quot;, sb.toString());&lt;/p&gt;
&lt;p&gt;			} else&lt;/p&gt;
&lt;p&gt;				throw new Exception(&amp;quot;Unexpected HTTP status code during login (&amp;quot; + stat +&amp;quot;)&amp;quot;);&lt;/p&gt;
&lt;p&gt;Seperately from this, I have a problem where Exchange is returning the entire contents of the users email folders, even when I request the Inbox and do a shallow traversal. Hence, I am being returned 1000's of historical emails that do not exist in the Inbox, they are in other folders. Do you have any idea why this would be the case? This is happening on more than 1 server, this is my query:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;SELECT &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;quot;DAV:id&amp;quot;,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;quot;DAV:href&amp;quot;, &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;quot;urn:schemas:httpmail:subject&amp;quot;,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;quot;urn:schemas:httpmail:from&amp;quot;,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;quot;urn:schemas:httpmail:datereceived&amp;quot; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;FROM SCOPE('shallow traversal of &amp;nbsp;&amp;quot;&lt;a rel="nofollow" target="_new" href="https://server/exchange/Clinton/Inbox&amp;quot;"&gt;https://server/exchange/Clinton/Inbox&amp;quot;&lt;/a&gt;')&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;WHERE &amp;quot;DAV:ishidden&amp;quot;=False AND &amp;quot;DAV:isfolder&amp;quot;=False &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;ORDER BY &amp;quot;urn:schemas:httpmail:datereceived&amp;quot; DESC&lt;/p&gt;
&lt;p&gt;AHA, Ben :)&lt;/p&gt;
</description></item><item><title>re: Connecting Java to Exchange over WebDAV, with Apache HttpClient</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx#9463225</link><pubDate>Fri, 06 Mar 2009 21:10:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9463225</guid><dc:creator>DotNetInterop</dc:creator><description>&lt;p&gt;Thanks for the hints, Ben. &amp;nbsp;Sorry I do not have any insight into your other question! &lt;/p&gt;
</description></item><item><title>re: Connecting Java to Exchange over WebDAV, with Apache HttpClient</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx#9678423</link><pubDate>Mon, 01 Jun 2009 19:18:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9678423</guid><dc:creator>Ahsan</dc:creator><description>&lt;p&gt;hi ,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; thx for this great information, i have done all these tasks like email fetch,contacts,and sent items,but u havnt mention here how to send email using it or how to add contact ??&lt;/p&gt;
&lt;p&gt; plz give me a simple example for sending mail &amp;nbsp; &amp;nbsp;&lt;/p&gt;
</description></item><item><title>re: Connecting Java to Exchange over WebDAV, with Apache HttpClient</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/07/21/connecting-java-to-exchange-over-webdav-with-apache-httpclient.aspx#9762575</link><pubDate>Tue, 16 Jun 2009 19:01:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9762575</guid><dc:creator>DotNetInterop</dc:creator><description>&lt;p&gt;I don't have a Java example handy. &amp;nbsp;But the wire protocol is just WebDAV. &amp;nbsp;If you can translate VB to Java, this article might help: &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/vikas/archive/2009/05/22/howto-webdav-send-mail-with-custom-form-and-set-properties.aspx"&gt;http://blogs.msdn.com/vikas/archive/2009/05/22/howto-webdav-send-mail-with-custom-form-and-set-properties.aspx&lt;/a&gt; &lt;/p&gt;
</description></item></channel></rss>