1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-08 08:26:10 +00:00

Merge pull request #143 from owncloud/release_0.9.15

Release 0.9.15
This commit is contained in:
David A. Velasco 2016-12-20 16:31:25 +01:00 committed by GitHub
commit a68f7769dc

View File

@ -39,6 +39,7 @@ import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpVersion; import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.URI; import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.httpclient.params.HttpMethodParams;
@ -90,13 +91,14 @@ public class OwnCloudClient extends HttpClient {
getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent); getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
getParams().setParameter( getParams().setParameter(
PARAM_PROTOCOL_VERSION, PARAM_PROTOCOL_VERSION,
HttpVersion.HTTP_1_1); HttpVersion.HTTP_1_1
);
getParams().setCookiePolicy( getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
CookiePolicy.IGNORE_COOKIES);
getParams().setParameter( getParams().setParameter(
PARAM_SINGLE_COOKIE_HEADER, // to avoid problems with some web servers PARAM_SINGLE_COOKIE_HEADER, // to avoid problems with some web servers
PARAM_SINGLE_COOKIE_HEADER_VALUE); PARAM_SINGLE_COOKIE_HEADER_VALUE
);
applyProxySettings(); applyProxySettings();
@ -113,7 +115,7 @@ public class OwnCloudClient extends HttpClient {
proxyPort = Integer.parseInt(proxyPortSt); proxyPort = Integer.parseInt(proxyPortSt);
} }
} catch (Exception e) { } catch (Exception e) {
// nothing to do here Log_OC.w(TAG, "Proxy port could not be read, keeping default value " + proxyPort);
} }
if (proxyHost != null && proxyHost.length() > 0) { if (proxyHost != null && proxyHost.length() > 0) {
@ -143,10 +145,9 @@ public class OwnCloudClient extends HttpClient {
/** /**
* Check if a file exists in the OC server * Check if a file exists in the OC server
* *
* @deprecated Use ExistenceCheckOperation instead
*
* @return 'true' if the file exists; 'false' it doesn't exist * @return 'true' if the file exists; 'false' it doesn't exist
* @throws Exception When the existence could not be determined * @throws Exception When the existence could not be determined
* @deprecated Use ExistenceCheckOperation instead
*/ */
@Deprecated @Deprecated
public boolean existsFile(String path) throws IOException, HttpException { public boolean existsFile(String path) throws IOException, HttpException {
@ -154,7 +155,7 @@ public class OwnCloudClient extends HttpClient {
try { try {
int status = executeMethod(head); int status = executeMethod(head);
Log_OC.d(TAG, "HEAD to " + path + " finished with HTTP status " + status + Log_OC.d(TAG, "HEAD to " + path + " finished with HTTP status " + status +
((status != HttpStatus.SC_OK)?"(FAIL)":"")); ((status != HttpStatus.SC_OK) ? "(FAIL)" : ""));
exhaustResponse(head.getResponseBodyAsStream()); exhaustResponse(head.getResponseBodyAsStream());
return (status == HttpStatus.SC_OK); return (status == HttpStatus.SC_OK);
@ -206,17 +207,18 @@ public class OwnCloudClient extends HttpClient {
*/ */
@Override @Override
public int executeMethod(HttpMethod method) throws IOException { public int executeMethod(HttpMethod method) throws IOException {
try {
// Update User Agent // Update User Agent
HttpParams params = method.getParams(); HttpParams params = method.getParams();
String userAgent = OwnCloudClientManagerFactory.getUserAgent(); String userAgent = OwnCloudClientManagerFactory.getUserAgent();
params.setParameter(HttpMethodParams.USER_AGENT, userAgent); params.setParameter(HttpMethodParams.USER_AGENT, userAgent);
preventCrashDueToInvalidPort(method);
Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " + Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " +
method.getName() + " " + method.getPath()); method.getName() + " " + method.getPath());
// logCookiesAtRequest(method.getRequestHeaders(), "before"); //logCookiesAtRequest(method.getRequestHeaders(), "before");
// logCookiesAtState("before"); //logCookiesAtState("before");
method.setFollowRedirects(false); method.setFollowRedirects(false);
int status = super.executeMethod(method); int status = super.executeMethod(method);
@ -225,15 +227,37 @@ public class OwnCloudClient extends HttpClient {
status = followRedirection(method).getLastStatus(); status = followRedirection(method).getLastStatus();
} }
// logCookiesAtRequest(method.getRequestHeaders(), "after"); //logCookiesAtRequest(method.getRequestHeaders(), "after");
// logCookiesAtState("after"); //logCookiesAtState("after");
// logSetCookiesAtResponse(method.getResponseHeaders()); //logSetCookiesAtResponse(method.getResponseHeaders());
return status; return status;
}
} catch (IOException e) {
//Log_OC.d(TAG + " #" + mInstanceNumber, "Exception occurred", e); /**
throw e; * Fix for https://github.com/owncloud/android/issues/1847#issuecomment-267558274
*
* The problem: default SocketFactory in HTTPClient 3.x for HTTP connections creates a separate thread
* to create the socket. When a port out of TCP bounds is passed, an exception is thrown in that
* separate thread, and our original thread is not able to catch it. This is not happenning with HTTPS
* connections because we had to define our own socket factory,
* {@link com.owncloud.android.lib.common.network.AdvancedSslSocketFactory}, and it does not mess with
* threads.
*
* The solution: validate the input (the port number) ourselves before let the work to HTTPClient 3.x.
*
* @param method HTTP method to run.
* @throws IllegalArgumentException If 'method' targets an invalid port in an HTTP URI.
* @throws URIException If the URI to the target server cannot be built.
*/
private void preventCrashDueToInvalidPort(HttpMethod method) throws URIException {
int port = method.getURI().getPort();
String scheme = method.getURI().getScheme().toLowerCase();
if ("http".equals(scheme) && port > 0xFFFF) {
// < 0 is not tested because -1 is used when no port number is specified in the URL;
// no problem, the network library will convert that in the default HTTP port
throw new IllegalArgumentException("Invalid port number " + port);
} }
} }
@ -243,7 +267,7 @@ public class OwnCloudClient extends HttpClient {
int status = method.getStatusCode(); int status = method.getStatusCode();
RedirectionPath result = new RedirectionPath(status, MAX_REDIRECTIONS_COUNT); RedirectionPath result = new RedirectionPath(status, MAX_REDIRECTIONS_COUNT);
while (redirectionsCount < MAX_REDIRECTIONS_COUNT && while (redirectionsCount < MAX_REDIRECTIONS_COUNT &&
( status == HttpStatus.SC_MOVED_PERMANENTLY || (status == HttpStatus.SC_MOVED_PERMANENTLY ||
status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_MOVED_TEMPORARILY ||
status == HttpStatus.SC_TEMPORARY_REDIRECT) status == HttpStatus.SC_TEMPORARY_REDIRECT)
) { ) {
@ -304,7 +328,7 @@ public class OwnCloudClient extends HttpClient {
public void exhaustResponse(InputStream responseBodyAsStream) { public void exhaustResponse(InputStream responseBodyAsStream) {
if (responseBodyAsStream != null) { if (responseBodyAsStream != null) {
try { try {
while (responseBodyAsStream.read(sExhaustBuffer) >= 0); while (responseBodyAsStream.read(sExhaustBuffer) >= 0) ;
responseBodyAsStream.close(); responseBodyAsStream.close();
} catch (IOException io) { } catch (IOException io) {
@ -367,7 +391,7 @@ public class OwnCloudClient extends HttpClient {
private void logCookiesAtRequest(Header[] headers, String when) { private void logCookiesAtRequest(Header[] headers, String when) {
int counter = 0; int counter = 0;
for (int i=0; i<headers.length; i++) { for (int i = 0; i < headers.length; i++) {
if (headers[i].getName().toLowerCase().equals("cookie")) { if (headers[i].getName().toLowerCase().equals("cookie")) {
Log_OC.d(TAG + " #" + mInstanceNumber, Log_OC.d(TAG + " #" + mInstanceNumber,
"Cookies at request (" + when + ") (" + counter++ + "): " + "Cookies at request (" + when + ") (" + counter++ + "): " +
@ -385,7 +409,7 @@ public class OwnCloudClient extends HttpClient {
Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at STATE before"); Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at STATE before");
} else { } else {
Log_OC.d(TAG + " #" + mInstanceNumber, "Cookies at STATE (before)"); Log_OC.d(TAG + " #" + mInstanceNumber, "Cookies at STATE (before)");
for (int i=0; i<cookies.length; i++) { for (int i = 0; i < cookies.length; i++) {
Log_OC.d(TAG + " #" + mInstanceNumber, " (" + i + "):" + Log_OC.d(TAG + " #" + mInstanceNumber, " (" + i + "):" +
"\n name: " + cookies[i].getName() + "\n name: " + cookies[i].getName() +
"\n value: " + cookies[i].getValue() + "\n value: " + cookies[i].getValue() +
@ -398,7 +422,7 @@ public class OwnCloudClient extends HttpClient {
private void logSetCookiesAtResponse(Header[] headers) { private void logSetCookiesAtResponse(Header[] headers) {
int counter = 0; int counter = 0;
for (int i=0; i<headers.length; i++) { for (int i = 0; i < headers.length; i++) {
if (headers[i].getName().toLowerCase().equals("set-cookie")) { if (headers[i].getName().toLowerCase().equals("set-cookie")) {
Log_OC.d(TAG + " #" + mInstanceNumber, Log_OC.d(TAG + " #" + mInstanceNumber,
"Set-Cookie (" + counter++ + "): " + headers[i].getValue()); "Set-Cookie (" + counter++ + "): " + headers[i].getValue());
@ -407,7 +431,6 @@ public class OwnCloudClient extends HttpClient {
if (counter == 0) { if (counter == 0) {
Log_OC.d(TAG + " #" + mInstanceNumber, "No set-cookie"); Log_OC.d(TAG + " #" + mInstanceNumber, "No set-cookie");
} }
} }
public String getCookiesString() { public String getCookiesString() {
@ -432,23 +455,23 @@ public class OwnCloudClient extends HttpClient {
} }
private void logCookie(Cookie cookie) { private void logCookie(Cookie cookie) {
Log_OC.d(TAG, "Cookie name: "+ cookie.getName() ); Log_OC.d(TAG, "Cookie name: " + cookie.getName());
Log_OC.d(TAG, " value: "+ cookie.getValue() ); Log_OC.d(TAG, " value: " + cookie.getValue());
Log_OC.d(TAG, " domain: "+ cookie.getDomain()); Log_OC.d(TAG, " domain: " + cookie.getDomain());
Log_OC.d(TAG, " path: "+ cookie.getPath() ); Log_OC.d(TAG, " path: " + cookie.getPath());
Log_OC.d(TAG, " version: "+ cookie.getVersion() ); Log_OC.d(TAG, " version: " + cookie.getVersion());
Log_OC.d(TAG, " expiryDate: " + Log_OC.d(TAG, " expiryDate: " +
(cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--")); (cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--"));
Log_OC.d(TAG, " comment: "+ cookie.getComment() ); Log_OC.d(TAG, " comment: " + cookie.getComment());
Log_OC.d(TAG, " secure: "+ cookie.getSecure() ); Log_OC.d(TAG, " secure: " + cookie.getSecure());
} }
public void setOwnCloudVersion(OwnCloudVersion version){ public void setOwnCloudVersion(OwnCloudVersion version) {
mVersion = version; mVersion = version;
} }
public OwnCloudVersion getOwnCloudVersion(){ public OwnCloudVersion getOwnCloudVersion() {
return mVersion; return mVersion;
} }
} }