Force internet explorer header to get XML responses

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@184 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2008-11-30 18:05:36 +00:00
parent 1f5eb0d983
commit 39d4bafb91
4 changed files with 14 additions and 22 deletions

View File

@ -119,9 +119,9 @@ public class DavGateway {
public static String getReleasedVersion() { public static String getReleasedVersion() {
String version = null; String version = null;
BufferedReader versionReader = null; BufferedReader versionReader = null;
HttpClient httpClient = DavGatewayHttpClientFacade.getInstance();
GetMethod getMethod = new GetMethod("http://davmail.sourceforge.net/version.txt"); GetMethod getMethod = new GetMethod("http://davmail.sourceforge.net/version.txt");
try { try {
HttpClient httpClient = DavGatewayHttpClientFacade.getInstance();
httpClient.setConnectionTimeout(250); httpClient.setConnectionTimeout(250);
int status = httpClient.executeMethod(getMethod); int status = httpClient.executeMethod(getMethod);
if (status == HttpStatus.SC_OK) { if (status == HttpStatus.SC_OK) {

View File

@ -1,16 +1,9 @@
package davmail.exchange; package davmail.exchange;
import davmail.Settings; import davmail.Settings;
import davmail.tray.DavGatewayTray;
import davmail.http.DavGatewayHttpClientFacade; import davmail.http.DavGatewayHttpClientFacade;
import org.apache.commons.httpclient.Header; import davmail.tray.DavGatewayTray;
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpURL;
import org.apache.commons.httpclient.HttpsURL;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.PutMethod;
@ -20,13 +13,12 @@ import org.apache.webdav.lib.Property;
import org.apache.webdav.lib.ResponseEntity; import org.apache.webdav.lib.ResponseEntity;
import org.apache.webdav.lib.WebdavResource; import org.apache.webdav.lib.WebdavResource;
import org.apache.webdav.lib.methods.SearchMethod; import org.apache.webdav.lib.methods.SearchMethod;
import org.apache.webdav.lib.methods.PropFindMethod;
import javax.mail.internet.MimeUtility; import javax.mail.internet.MimeUtility;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
@ -694,8 +686,8 @@ public class ExchangeSession {
inHTML = false; inHTML = false;
} }
if (inHTML) { if (inHTML) {
// line = line.replaceAll("’", "'"); // line = line.replaceAll("’", "'");
// line = line.replaceAll("…", "..."); // line = line.replaceAll("…", "...");
} }
isoWriter.write(line); isoWriter.write(line);
isoWriter.write((char) 13); isoWriter.write((char) 13);
@ -973,8 +965,6 @@ public class ExchangeSession {
public String getEmail() throws IOException { public String getEmail() throws IOException {
String email = null; String email = null;
GetMethod getMethod = new GetMethod("/public/?Cmd=galfind&AN=" + getUserName()); GetMethod getMethod = new GetMethod("/public/?Cmd=galfind&AN=" + getUserName());
// force XML response with Internet Explorer header
getMethod.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
XMLStreamReader reader = null; XMLStreamReader reader = null;
try { try {
int status = wdr.retrieveSessionInstance().executeMethod(getMethod); int status = wdr.retrieveSessionInstance().executeMethod(getMethod);
@ -1057,7 +1047,6 @@ public class ExchangeSession {
} }
GetMethod getMethod = new GetMethod(url); GetMethod getMethod = new GetMethod(url);
getMethod.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
getMethod.setRequestHeader("Content-Type", "text/xml"); getMethod.setRequestHeader("Content-Type", "text/xml");
try { try {

View File

@ -42,12 +42,9 @@ public class ExchangeSessionFactory {
public static void checkConfig() throws IOException { public static void checkConfig() throws IOException {
String url = Settings.getProperty("davmail.url"); String url = Settings.getProperty("davmail.url");
HttpClient httpClient = DavGatewayHttpClientFacade.getInstance();
HttpMethod testMethod = new GetMethod(url); HttpMethod testMethod = new GetMethod(url);
try { try {
// create an HttpClient instance
HttpClient httpClient = DavGatewayHttpClientFacade.getInstance();
// get webmail root url (will not follow redirects) // get webmail root url (will not follow redirects)
testMethod.setFollowRedirects(false); testMethod.setFollowRedirects(false);
testMethod.setDoAuthentication(false); testMethod.setDoAuthentication(false);

View File

@ -16,6 +16,11 @@ import java.io.IOException;
* Create HttpClient instance according to DavGateway Settings * Create HttpClient instance according to DavGateway Settings
*/ */
public class DavGatewayHttpClientFacade { public class DavGatewayHttpClientFacade {
static {
// force XML response with Internet Explorer header
System.getProperties().setProperty("httpclient.useragent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
}
/** /**
* Create a configured HttpClient instance. * Create a configured HttpClient instance.
* *
@ -34,6 +39,7 @@ public class DavGatewayHttpClientFacade {
* @param httpClient current Http client * @param httpClient current Http client
*/ */
public static void configureClient(HttpClient httpClient) { public static void configureClient(HttpClient httpClient) {
// do not send basic auth automatically // do not send basic auth automatically
httpClient.getState().setAuthenticationPreemptive(false); httpClient.getState().setAuthenticationPreemptive(false);