diff options
author | Damian Minkov <damencho@jitsi.org> | 2011-04-01 14:56:34 +0000 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2011-04-01 14:56:34 +0000 |
commit | 21403fc25a517771277c26aaf33aa44ba2b298c0 (patch) | |
tree | 6996caacda441cbc7218b41c66f47d31f7958572 /src/net/java/sip/communicator/service | |
parent | be1218c038662d6cf4a7206cf81ba4120e983e82 (diff) | |
download | jitsi-21403fc25a517771277c26aaf33aa44ba2b298c0.zip jitsi-21403fc25a517771277c26aaf33aa44ba2b298c0.tar.gz jitsi-21403fc25a517771277c26aaf33aa44ba2b298c0.tar.bz2 |
Fix Master Password background.
Fix post http redirects in HttpUtils.
Enable google contacts in separate thread to avoid blocking initial felix registering of accounts.
Diffstat (limited to 'src/net/java/sip/communicator/service')
-rw-r--r-- | src/net/java/sip/communicator/service/httputil/HttpUtils.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/service/httputil/HttpUtils.java b/src/net/java/sip/communicator/service/httputil/HttpUtils.java index d175acd..b15bf01 100644 --- a/src/net/java/sip/communicator/service/httputil/HttpUtils.java +++ b/src/net/java/sip/communicator/service/httputil/HttpUtils.java @@ -9,9 +9,11 @@ package net.java.sip.communicator.service.httputil; import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.swing.*; import org.apache.http.*; +import org.apache.http.Header; import org.apache.http.auth.*; import org.apache.http.client.*; import org.apache.http.client.methods.*; +import org.apache.http.client.params.*; import org.apache.http.client.utils.*; import org.apache.http.conn.scheme.*; import org.apache.http.conn.ssl.SSLSocketFactory; @@ -53,6 +55,11 @@ public class HttpUtils "net.java.sip.communicator.util.http.credential."; /** + * Maximum number of http redirects (301, 302, 303). + */ + private static final int MAX_REDIRECTS = 10; + + /** * Opens a connection to the <tt>address</tt>. * @param address the address to contact. * @return the result if any or null if connection was not possible @@ -116,6 +123,7 @@ public class HttpUtils { // do it when response (first execution) or till we are unauthorized HttpResponse response = null; + int redirects = 0; while(response == null || response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) @@ -147,6 +155,44 @@ public class HttpUtils logger.debug("User canceled credentials input."); break; } + + // check for post redirect as post redirects are not handled + // automatically + // RFC2616 (10.3 Redirection 3xx). + // The second request (forwarded method) can only be a GET or HEAD. + Header locationHeader = response.getFirstHeader("location"); + + if(locationHeader != null + && req instanceof HttpPost + && (response.getStatusLine().getStatusCode() + == HttpStatus.SC_MOVED_PERMANENTLY + || response.getStatusLine().getStatusCode() + == HttpStatus.SC_MOVED_TEMPORARILY + || response.getStatusLine().getStatusCode() + == HttpStatus.SC_SEE_OTHER) + && redirects < MAX_REDIRECTS) + { + HttpRequestBase oldreq = req; + oldreq.abort(); + + String newLocation = locationHeader.getValue(); + + // append query string if any + HttpEntity en = ((HttpPost) oldreq).getEntity(); + if(en != null && en instanceof StringEntity) + { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + en.writeTo(out); + newLocation += "?" + out.toString("UTF-8"); + } + + req = new HttpGet(newLocation); + req.setParams(oldreq.getParams()); + req.setHeaders(oldreq.getAllHeaders()); + + redirects++; + response = httpClient.execute(req); + } } // if we finally managed to login return the result. @@ -361,6 +407,7 @@ public class HttpUtils HttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); + params.setParameter(ClientPNames.MAX_REDIRECTS, MAX_REDIRECTS); DefaultHttpClient httpClient = new DefaultHttpClient(params); |