Search in sources :

Example 1 with Utf8PostMethod

use of org.apache.commons.httpclient.methods.Utf8PostMethod in project android by nextcloud.

the class RichDocumentsCreateAssetOperation method run.

protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result;
    Utf8PostMethod postMethod = null;
    try {
        postMethod = new Utf8PostMethod(client.getBaseUri() + ASSET_URL);
        postMethod.setParameter(PARAMETER_PATH, path);
        postMethod.setParameter(PARAMETER_FORMAT, PARAMETER_FORMAT_VALUE);
        // remote request
        postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
        int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
        if (status == HttpStatus.SC_OK) {
            String response = postMethod.getResponseBodyAsString();
            // Parse the response
            JSONObject respJSON = new JSONObject(response);
            String url = respJSON.getString(NODE_URL);
            result = new RemoteOperationResult(true, postMethod);
            result.setSingleData(url);
        } else {
            result = new RemoteOperationResult(false, postMethod);
            client.exhaustResponse(postMethod.getResponseBodyAsStream());
        }
    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Create asset for richdocuments with path " + path + " failed: " + result.getLogMessage(), result.getException());
    } finally {
        if (postMethod != null) {
            postMethod.releaseConnection();
        }
    }
    return result;
}
Also used : Utf8PostMethod(org.apache.commons.httpclient.methods.Utf8PostMethod) JSONObject(org.json.JSONObject) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult)

Example 2 with Utf8PostMethod

use of org.apache.commons.httpclient.methods.Utf8PostMethod in project android by nextcloud.

the class StreamMediaFileOperation method run.

protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result;
    Utf8PostMethod postMethod = null;
    try {
        postMethod = new Utf8PostMethod(client.getBaseUri() + STREAM_MEDIA_URL + JSON_FORMAT);
        postMethod.setParameter("fileId", fileID);
        // remote request
        postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
        int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
        if (status == HttpStatus.SC_OK) {
            String response = postMethod.getResponseBodyAsString();
            // Parse the response
            JSONObject respJSON = new JSONObject(response);
            String url = respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).getString(NODE_URL);
            result = new RemoteOperationResult(true, postMethod);
            ArrayList<Object> urlArray = new ArrayList<>();
            urlArray.add(url);
            result.setData(urlArray);
        } else {
            result = new RemoteOperationResult(false, postMethod);
            client.exhaustResponse(postMethod.getResponseBodyAsStream());
        }
    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Get stream url for file with id " + fileID + " failed: " + result.getLogMessage(), result.getException());
    } finally {
        if (postMethod != null) {
            postMethod.releaseConnection();
        }
    }
    return result;
}
Also used : Utf8PostMethod(org.apache.commons.httpclient.methods.Utf8PostMethod) JSONObject(org.json.JSONObject) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject)

Example 3 with Utf8PostMethod

use of org.apache.commons.httpclient.methods.Utf8PostMethod in project android by nextcloud.

the class CreateFileFromTemplateOperation method run.

protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result;
    Utf8PostMethod postMethod = null;
    try {
        postMethod = new Utf8PostMethod(client.getBaseUri() + NEW_FROM_TEMPLATE_URL + JSON_FORMAT);
        postMethod.setParameter("path", path);
        postMethod.setParameter("template", String.valueOf(templateId));
        // remote request
        postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
        int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
        if (status == HttpStatus.SC_OK) {
            String response = postMethod.getResponseBodyAsString();
            // Parse the response
            JSONObject respJSON = new JSONObject(response);
            String url = respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).getString("url");
            ArrayList<Object> templateArray = new ArrayList<>();
            templateArray.add(url);
            result = new RemoteOperationResult(true, postMethod);
            result.setData(templateArray);
        } else {
            result = new RemoteOperationResult(false, postMethod);
            client.exhaustResponse(postMethod.getResponseBodyAsStream());
        }
    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Create file from template " + templateId + " failed: " + result.getLogMessage(), result.getException());
    } finally {
        if (postMethod != null) {
            postMethod.releaseConnection();
        }
    }
    return result;
}
Also used : Utf8PostMethod(org.apache.commons.httpclient.methods.Utf8PostMethod) JSONObject(org.json.JSONObject) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject)

Example 4 with Utf8PostMethod

use of org.apache.commons.httpclient.methods.Utf8PostMethod in project android by nextcloud.

the class NotificationExecuteActionTask method doInBackground.

@Override
protected Boolean doInBackground(Action... actions) {
    HttpMethod method;
    Action action = actions[0];
    switch(action.type) {
        case "GET":
            method = new GetMethod(action.link);
            break;
        case "POST":
            method = new Utf8PostMethod(action.link);
            break;
        case "DELETE":
            method = new DeleteMethod(action.link);
            break;
        case "PUT":
            method = new PutMethod(action.link);
            break;
        default:
            // do nothing
            return Boolean.FALSE;
    }
    method.setRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE);
    int status;
    try {
        status = client.executeMethod(method);
    } catch (IOException e) {
        Log_OC.e(this, "Execution of notification action failed: " + e);
        return Boolean.FALSE;
    } finally {
        method.releaseConnection();
    }
    return status == HttpStatus.SC_OK || status == HttpStatus.SC_ACCEPTED;
}
Also used : Action(com.owncloud.android.lib.resources.notifications.models.Action) DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) Utf8PostMethod(org.apache.commons.httpclient.methods.Utf8PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.commons.httpclient.methods.PutMethod) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 5 with Utf8PostMethod

use of org.apache.commons.httpclient.methods.Utf8PostMethod in project android by nextcloud.

the class RichDocumentsUrlOperation method run.

@NextcloudServer(max = 18)
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result;
    Utf8PostMethod postMethod = null;
    try {
        postMethod = new Utf8PostMethod(client.getBaseUri() + DOCUMENT_URL + JSON_FORMAT);
        postMethod.setParameter(FILE_ID, fileID);
        // remote request
        postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
        int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
        if (status == HttpStatus.SC_OK) {
            String response = postMethod.getResponseBodyAsString();
            // Parse the response
            JSONObject respJSON = new JSONObject(response);
            String url = respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).getString(NODE_URL);
            result = new RemoteOperationResult(true, postMethod);
            result.setSingleData(url);
        } else {
            result = new RemoteOperationResult(false, postMethod);
            client.exhaustResponse(postMethod.getResponseBodyAsStream());
        }
    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Get rich document url for file with id " + fileID + " failed: " + result.getLogMessage(), result.getException());
    } finally {
        if (postMethod != null) {
            postMethod.releaseConnection();
        }
    }
    return result;
}
Also used : Utf8PostMethod(org.apache.commons.httpclient.methods.Utf8PostMethod) JSONObject(org.json.JSONObject) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) NextcloudServer(com.owncloud.android.utils.NextcloudServer)

Aggregations

Utf8PostMethod (org.apache.commons.httpclient.methods.Utf8PostMethod)5 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)4 JSONObject (org.json.JSONObject)4 ArrayList (java.util.ArrayList)2 Action (com.owncloud.android.lib.resources.notifications.models.Action)1 NextcloudServer (com.owncloud.android.utils.NextcloudServer)1 IOException (java.io.IOException)1 HttpMethod (org.apache.commons.httpclient.HttpMethod)1 DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 PutMethod (org.apache.commons.httpclient.methods.PutMethod)1