mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-14 11:42:23 -05:00
Allow follow redirects on /public GET requests
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@782 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
53ddf0ef49
commit
b5b3839341
@ -729,6 +729,7 @@ public class ExchangeSession {
|
|||||||
*/
|
*/
|
||||||
public void updateMessage(Message message, Map<String, String> properties) throws IOException {
|
public void updateMessage(Message message, Map<String, String> properties) throws IOException {
|
||||||
PropPatchMethod patchMethod = new PropPatchMethod(URIUtil.encodePathQuery(message.messageUrl), buildProperties(properties)) {
|
PropPatchMethod patchMethod = new PropPatchMethod(URIUtil.encodePathQuery(message.messageUrl), buildProperties(properties)) {
|
||||||
|
@Override
|
||||||
protected void processResponseBody(HttpState httpState, HttpConnection httpConnection) {
|
protected void processResponseBody(HttpState httpState, HttpConnection httpConnection) {
|
||||||
// ignore response body, sometimes invalid with exchange mapi properties
|
// ignore response body, sometimes invalid with exchange mapi properties
|
||||||
}
|
}
|
||||||
@ -1393,7 +1394,7 @@ public class ExchangeSession {
|
|||||||
method.setRequestHeader("Translate", "f");
|
method.setRequestHeader("Translate", "f");
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
try {
|
try {
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method);
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, false);
|
||||||
|
|
||||||
reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
|
reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
|
||||||
OutputStreamWriter isoWriter = new OutputStreamWriter(os);
|
OutputStreamWriter isoWriter = new OutputStreamWriter(os);
|
||||||
@ -1548,7 +1549,7 @@ public class ExchangeSession {
|
|||||||
method.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
|
method.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
|
||||||
method.setRequestHeader("Translate", "f");
|
method.setRequestHeader("Translate", "f");
|
||||||
try {
|
try {
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method);
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, false);
|
||||||
|
|
||||||
MimeMessage mimeMessage = new MimeMessage(null, method.getResponseBodyAsStream());
|
MimeMessage mimeMessage = new MimeMessage(null, method.getResponseBodyAsStream());
|
||||||
Object mimeBody = mimeMessage.getContent();
|
Object mimeBody = mimeMessage.getContent();
|
||||||
@ -1621,7 +1622,7 @@ public class ExchangeSession {
|
|||||||
" ORDER BY \"urn:schemas:calendar:dtstart\" DESC\n";
|
" ORDER BY \"urn:schemas:calendar:dtstart\" DESC\n";
|
||||||
result = getEvents(folderPath, searchQuery);
|
result = getEvents(folderPath, searchQuery);
|
||||||
} catch (HttpException e) {
|
} catch (HttpException e) {
|
||||||
// failover to DAV:content property on some Exchange servers
|
// failover to DAV:comment property on some Exchange servers
|
||||||
if (DEFAULT_SCHEDULE_STATE_PROPERTY.equals(scheduleStateProperty)) {
|
if (DEFAULT_SCHEDULE_STATE_PROPERTY.equals(scheduleStateProperty)) {
|
||||||
scheduleStateProperty = DavPropertyName.create("comment", Namespace.getNamespace("DAV:"));
|
scheduleStateProperty = DavPropertyName.create("comment", Namespace.getNamespace("DAV:"));
|
||||||
result = getEventMessages(folderPath);
|
result = getEventMessages(folderPath);
|
||||||
@ -2592,7 +2593,7 @@ public class ExchangeSession {
|
|||||||
try {
|
try {
|
||||||
path = getCmdBasePath() + "?Cmd=galfind&AN=" + URIUtil.encodeWithinQuery(alias);
|
path = getCmdBasePath() + "?Cmd=galfind&AN=" + URIUtil.encodeWithinQuery(alias);
|
||||||
getMethod = new GetMethod(path);
|
getMethod = new GetMethod(path);
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, getMethod);
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, getMethod, true);
|
||||||
Map<String, Map<String, String>> results = XMLStreamUtil.getElementContentsAsMap(getMethod.getResponseBodyAsStream(), "item", "AN");
|
Map<String, Map<String, String>> results = XMLStreamUtil.getElementContentsAsMap(getMethod.getResponseBodyAsStream(), "item", "AN");
|
||||||
Map<String, String> result = results.get(alias.toLowerCase());
|
Map<String, String> result = results.get(alias.toLowerCase());
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
@ -2670,7 +2671,7 @@ public class ExchangeSession {
|
|||||||
BufferedReader optionsPageReader = null;
|
BufferedReader optionsPageReader = null;
|
||||||
GetMethod optionsMethod = new GetMethod(path + "?ae=Options&t=About");
|
GetMethod optionsMethod = new GetMethod(path + "?ae=Options&t=About");
|
||||||
try {
|
try {
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, optionsMethod);
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, optionsMethod, false);
|
||||||
optionsPageReader = new BufferedReader(new InputStreamReader(optionsMethod.getResponseBodyAsStream()));
|
optionsPageReader = new BufferedReader(new InputStreamReader(optionsMethod.getResponseBodyAsStream()));
|
||||||
String line;
|
String line;
|
||||||
// find mailbox full name
|
// find mailbox full name
|
||||||
@ -2704,7 +2705,7 @@ public class ExchangeSession {
|
|||||||
BufferedReader optionsPageReader = null;
|
BufferedReader optionsPageReader = null;
|
||||||
GetMethod optionsMethod = new GetMethod(path + "?ae=Options&t=About");
|
GetMethod optionsMethod = new GetMethod(path + "?ae=Options&t=About");
|
||||||
try {
|
try {
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, optionsMethod);
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, optionsMethod, false);
|
||||||
optionsPageReader = new BufferedReader(new InputStreamReader(optionsMethod.getResponseBodyAsStream()));
|
optionsPageReader = new BufferedReader(new InputStreamReader(optionsMethod.getResponseBodyAsStream()));
|
||||||
String line;
|
String line;
|
||||||
// find email
|
// find email
|
||||||
@ -2765,7 +2766,7 @@ public class ExchangeSession {
|
|||||||
Map<String, Map<String, String>> results;
|
Map<String, Map<String, String>> results;
|
||||||
GetMethod getMethod = new GetMethod(URIUtil.encodePathQuery(getCmdBasePath() + "?Cmd=galfind&" + searchAttribute + '=' + searchValue));
|
GetMethod getMethod = new GetMethod(URIUtil.encodePathQuery(getCmdBasePath() + "?Cmd=galfind&" + searchAttribute + '=' + searchValue));
|
||||||
try {
|
try {
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, getMethod);
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, getMethod, true);
|
||||||
results = XMLStreamUtil.getElementContentsAsMap(getMethod.getResponseBodyAsStream(), "item", "AN");
|
results = XMLStreamUtil.getElementContentsAsMap(getMethod.getResponseBodyAsStream(), "item", "AN");
|
||||||
} finally {
|
} finally {
|
||||||
getMethod.releaseConnection();
|
getMethod.releaseConnection();
|
||||||
@ -2931,7 +2932,7 @@ public class ExchangeSession {
|
|||||||
GetMethod getMethod = null;
|
GetMethod getMethod = null;
|
||||||
try {
|
try {
|
||||||
getMethod = new GetMethod(URIUtil.encodePathQuery(getCmdBasePath() + "?Cmd=gallookup&ADDR=" + person.get("EM")));
|
getMethod = new GetMethod(URIUtil.encodePathQuery(getCmdBasePath() + "?Cmd=gallookup&ADDR=" + person.get("EM")));
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, getMethod);
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, getMethod, true);
|
||||||
Map<String, Map<String, String>> results = XMLStreamUtil.getElementContentsAsMap(getMethod.getResponseBodyAsStream(), "person", "alias");
|
Map<String, Map<String, String>> results = XMLStreamUtil.getElementContentsAsMap(getMethod.getResponseBodyAsStream(), "person", "alias");
|
||||||
// add detailed information
|
// add detailed information
|
||||||
if (!results.isEmpty()) {
|
if (!results.isEmpty()) {
|
||||||
@ -2999,7 +3000,7 @@ public class ExchangeSession {
|
|||||||
getMethod.setRequestHeader("Content-Type", "text/xml");
|
getMethod.setRequestHeader("Content-Type", "text/xml");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, getMethod);
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, getMethod, true);
|
||||||
String body = getMethod.getResponseBodyAsString();
|
String body = getMethod.getResponseBodyAsString();
|
||||||
int startIndex = body.lastIndexOf("<a:fbdata>");
|
int startIndex = body.lastIndexOf("<a:fbdata>");
|
||||||
int endIndex = body.lastIndexOf("</a:fbdata>");
|
int endIndex = body.lastIndexOf("</a:fbdata>");
|
||||||
|
@ -359,17 +359,25 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
*
|
*
|
||||||
* @param httpClient Http client instance
|
* @param httpClient Http client instance
|
||||||
* @param method Http method
|
* @param method Http method
|
||||||
|
* @param followRedirects Follow redirects flag
|
||||||
* @throws IOException on error
|
* @throws IOException on error
|
||||||
*/
|
*/
|
||||||
public static void executeGetMethod(HttpClient httpClient, GetMethod method) throws IOException {
|
public static void executeGetMethod(HttpClient httpClient, GetMethod method, boolean followRedirects) throws IOException {
|
||||||
// do not follow redirects in expired sessions
|
// do not follow redirects in expired sessions
|
||||||
method.setFollowRedirects(false);
|
method.setFollowRedirects(followRedirects);
|
||||||
int status = httpClient.executeMethod(method);
|
int status = httpClient.executeMethod(method);
|
||||||
if (status != HttpStatus.SC_OK) {
|
if (status != HttpStatus.SC_OK) {
|
||||||
LOGGER.warn("GET failed with status " + status + " at " + method.getURI() + ": " + method.getResponseBodyAsString());
|
LOGGER.warn("GET failed with status " + status + " at " + method.getURI() + ": " + method.getResponseBodyAsString());
|
||||||
throw new DavMailException("EXCEPTION_GET_FAILED", status, method.getURI());
|
throw new DavMailException("EXCEPTION_GET_FAILED", status, method.getURI());
|
||||||
}
|
}
|
||||||
|
// check for expired session
|
||||||
|
if (followRedirects) {
|
||||||
|
String queryString = method.getQueryString();
|
||||||
|
if (queryString != null && queryString.contains("reason=2")) {
|
||||||
|
LOGGER.warn("GET failed, session expired at " + method.getURI() + ": " + method.getResponseBodyAsString());
|
||||||
|
throw new DavMailException("EXCEPTION_GET_FAILED", status, method.getURI());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user