Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 230f2cf5 authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

change executeMethod in OwnCloudClient to be able to specified userAgent as...

change executeMethod in OwnCloudClient to be able to specified userAgent as wanted. Add add a decompress gzipInputStream method and use it it LightReadFolderRemoteOperation
parent e99c7bd2
Loading
Loading
Loading
Loading
+39 −14
Original line number Diff line number Diff line
@@ -201,7 +201,6 @@ public class OwnCloudClient extends HttpClient {
        }
    }


    /**
     * Requests the received method.
     *
@@ -211,23 +210,35 @@ public class OwnCloudClient extends HttpClient {
     */
    @Override
    public int executeMethod(HttpMethod method) throws IOException{
        return executeMethod(method,
                mUseNextcloudUserAgent ? OwnCloudClientManagerFactory.getNextcloudUserAgent() : OwnCloudClientManagerFactory.getUserAgent());
    }

    /**
     * Requests the received method.
     *
     * Executes the method through the inherited HttpClient.executedMethod(method).
     * With the specified userAgent
     *
     * @param method                HTTP method request.
     * @param userAgent value of user agent parameters.
     */
    public int executeMethod(HttpMethod method, String userAgent) throws IOException {
        try {
            // Update User Agent
            HttpParams params = method.getParams();

            String userAgent;
            /*String userAgent;
            if (mUseNextcloudUserAgent) {
                userAgent = OwnCloudClientManagerFactory.getNextcloudUserAgent();
            } else {
                userAgent = OwnCloudClientManagerFactory.getUserAgent();
            }
            }*/
            params.setParameter(HttpMethodParams.USER_AGENT, userAgent);

            Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " +
                    method.getName() + " " + method.getPath());

//	        logCookiesAtRequest(method.getRequestHeaders(), "before");
//	        logCookiesAtState("before");
            method.setFollowRedirects(false);

            int status = super.executeMethod(method);
@@ -236,10 +247,6 @@ public class OwnCloudClient extends HttpClient {
                status = followRedirection(method).getLastStatus();
            }

//	        logCookiesAtRequest(method.getRequestHeaders(), "after");
//	        logCookiesAtState("after");
//	        logSetCookiesAtResponse(method.getResponseHeaders());

            return status;

        } catch (IOException e) {
@@ -323,6 +330,24 @@ public class OwnCloudClient extends HttpClient {
        }
    }

    /**
     *
     * Decompress response from Gzip compression
     * @param responseBodyAsStream      InputStream with the HTTP response to exhaust.
     */
    public void exhaustGZippedResponse(InputStream responseBodyAsStream) {
        if (responseBodyAsStream != null) {
            try {
                while(responseBodyAsStream.read(sExhaustBuffer) >= 0);
                responseBodyAsStream.close();

            } catch (IOException io) {
                Log_OC.e(TAG, "Unexpected exception while exhausting not interesting HTTP response;" +
                        " will be IGNORED", io);
            }
        }
    }

    /**
     * Sets the connection and wait-for-data timeouts to be applied by default to the methods 
     * performed by this client.
+0 −1
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ public abstract class OCSRemoteOperation extends RemoteOperation {
    public ServerResponse<UserInfo> getServerResponse(HttpMethodBase method, Type type) throws IOException {
        String response = method.getResponseBodyAsString();


        Moshi moshi = new Moshi.Builder().build();
        JsonAdapter<ServerResponse<UserInfo>> jsonAdapter = moshi.adapter(type);

+9 −5
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import org.apache.jackrabbit.webdav.MultiStatus;
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;

import java.util.ArrayList;
import java.util.zip.GZIPInputStream;

/**
 * Remote operation performing the read of remote file or folder in the ownCloud server.
@@ -90,16 +91,16 @@ public class LightReadFolderRemoteOperation extends RemoteOperation {
        PropFindMethod query = null;

        try {


            // remote request
            query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
                WebdavUtils.getMinimumPropSet(),    // PropFind Properties
                this.depth);

            Log.d("ReadFolderRemoteOp", "Display query: "+query.getQueryString() );
            //query.setQueryString(new NameValuePair[]{new NameValuePair("format", "json")});
            Log.d("ReadFolderRemoteOp", "Display query: "+query.toString() );


            int status = client.executeMethod(query);
            int status = client.executeMethod(query, "gzipUserAgent");

            // check and process response
            boolean isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK);
@@ -116,8 +117,11 @@ public class LightReadFolderRemoteOperation extends RemoteOperation {
                    result.setData(mFolderAndFiles);
                }
            } else {
                GZIPInputStream gzipSteam = null;
                gzipSteam = new GZIPInputStream(query.getResponseBodyAsStream());
                // synchronization failed
                client.exhaustResponse(query.getResponseBodyAsStream());
                //client.exhaustResponse(query.getResponseBodyAsStream());
                client.exhaustGZippedResponse(gzipSteam);
                result = new RemoteOperationResult(false, query);
            }
        } catch (Exception e) {