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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations