private void handleArchivedRequest(File archivedFile, boolean sync) { handleArchivedRequest(archivedFile, sync, null); }
protected void handleAllArchivedRequest(boolean sync) { File commandCacheDir = AVPersistenceUtils.getCommandCacheDir(); File[] archivedRequests = commandCacheDir.listFiles(); if (archivedRequests != null && archivedRequests.length > 0) { Arrays.sort(archivedRequests, fileModifiedDateComparator); for (File file : archivedRequests) { if (file.isFile()) { handleArchivedRequest(file, sync); } else if (AVOSCloud.showInternalDebugLog()) { LogUtil.avlog.e(file.getAbsolutePath() + " is a dir"); } } } }
protected void handleAllArchivedRequest(boolean sync) { File commandCacheDir = InternalConfigurationController.globalInstance().getInternalPersistence() .getCommandCacheDir(); File[] archivedRequests = commandCacheDir.listFiles(); if (archivedRequests != null && archivedRequests.length > 0) { Arrays.sort(archivedRequests, fileModifiedDateComparator); for (File file : archivedRequests) { if (file.isFile()) { handleArchivedRequest(file, sync); } else if (InternalConfigurationController.globalInstance().getInternalLogger() .showInternalDebugLog()) { LogUtil.avlog.e(file.getAbsolutePath() + " is a dir"); } } } }
private void handleArchivedRequest(final File archivedFile, boolean sync, final GenericObjectCallback callback) { try { String archivedFileContent = InternalConfigurationController.globalInstance().getInternalPersistence() .readContentFromFile(archivedFile); Map<String, String> fileMap = null; fileMap = AVUtils.getFromJSON(archivedFileContent, Map.class); if (fileMap != null && !fileMap.isEmpty()) { String method = fileMap.get("method"); String relativePath = fileMap.get("relativePath"); String paramString = fileMap.get("paramString"); String objectId = fileMap.get("objectId"); String _internalId = fileMap.get("_internalId"); GenericObjectCallback newCallback = new GenericObjectCallback() { @Override public void onSuccess(String content, AVException e) { if (callback != null) { callback.onSuccess(content, e); } try { Map<String, String> objectMap = AVUtils.getFromJSON(content, Map.class); for (String _internalId : objectMap.keySet()) { if (internalObjectsForEventuallySave.get(_internalId) != null) { internalObjectsForEventuallySave.get(_internalId).getValue() .copyFromMap(objectMap); unregisterEvtuallyObject(internalObjectsForEventuallySave.get(_internalId) .getValue()); }
public void postObject(final String relativePath, String object, final Map<String, String> headers, boolean sync, boolean isEventually, GenericObjectCallback callback, String objectId, String _internalId) { try { if (isEventually) { File archivedFile = archiveRequest("post", relativePath, object, objectId, _internalId); handleArchivedRequest(archivedFile, sync, callback); } else { String url = buildUrl(relativePath); if (AVOSCloud.isDebugLogEnabled()) { dumpHttpPostRequest(null, url, object); } AsyncHttpResponseHandler handler = createPostHandler(callback); AVHttpClient client = AVHttpClient.clientInstance(); Request.Builder builder = new Request.Builder(); updateHeaders(builder, headers, callback != null && callback.isRequestStatisticNeed()); builder.url(url).post(RequestBody.create(AVHttpClient.JSON, object)); client.execute(builder.build(), sync, handler); } } catch (Exception exception) { processException(exception, callback); } }
public void postBatchSave(final List list, final boolean sync, final boolean isEventually, final Map<String, String> header, final GenericObjectCallback callback, final String objectId, final String _internalId) { try { Map params = new HashMap(); params.put("requests", list); String paramString = AVUtils.jsonStringFromMapWithNull(params); if (isEventually) { File archivedFile = archiveRequest("post", batchSaveRelativeUrl(), paramString, objectId, _internalId); handleArchivedRequest(archivedFile, sync, callback); } else { String url = buildUrl(batchSaveRelativeUrl()); if (AVOSCloud.isDebugLogEnabled()) { dumpHttpPostRequest(header, url, paramString); } AsyncHttpResponseHandler handler = createPostHandler(callback); AVHttpClient client = AVHttpClient.clientInstance(); Request.Builder builder = new Request.Builder(); builder.url(url).post(RequestBody.create(AVHttpClient.JSON, paramString)); updateHeaders(builder, header, callback != null && callback.isRequestStatisticNeed()); client.execute(builder.build(), sync, handler); } } catch (Exception exception) { processException(exception, callback); } }
public void putObject(final String relativePath, String object, boolean sync, boolean isEventually, Map<String, String> header, GenericObjectCallback callback, String objectId, String _internalId) { try { if (isEventually) { File archivedFile = archiveRequest("put", relativePath, object, objectId, _internalId); handleArchivedRequest(archivedFile, sync, callback); } else { String url = buildUrl(relativePath); AsyncHttpResponseHandler handler = createPostHandler(callback); if (AVOSCloud.isDebugLogEnabled()) { dumpHttpPutRequest(header, url, object); } AVHttpClient client = AVHttpClient.clientInstance(); Request.Builder builder = new Request.Builder(); builder.url(url).put(RequestBody.create(AVHttpClient.JSON, object)); updateHeaders(builder, header, callback != null && callback.isRequestStatisticNeed()); client.execute(builder.build(), sync, handler); } } catch (Exception exception) { processException(exception, callback); } }
public void deleteObject(final String relativePath, boolean sync, boolean isEventually, GenericObjectCallback callback, String objectId, String _internalId) { try { if (isEventually) { File archivedFile = archiveRequest("delete", relativePath, null, objectId, _internalId); handleArchivedRequest(archivedFile, sync, callback); } else { String url = buildUrl(relativePath); if (AVOSCloud.isDebugLogEnabled()) { dumpHttpDeleteRequest(null, url, null); } AsyncHttpResponseHandler handler = createPostHandler(callback); AVHttpClient client = AVHttpClient.clientInstance(); Request.Builder builder = new Request.Builder(); updateHeaders(builder, null, callback != null && callback.isRequestStatisticNeed()); builder.url(url).delete(); client.execute(builder.build(), sync, handler); } } catch (Exception exception) { processException(exception, callback); } }
public void postBatchSave(final List list, final boolean sync, final boolean isEventually, final Map<String, String> header, final GenericObjectCallback callback, final String objectId, final String _internalId) { try { Map params = new HashMap(); params.put("requests", list); String paramString = AVUtils.jsonStringFromMapWithNull(params); if (isEventually) { File archivedFile = archiveRequest("post", batchSaveRelativeUrl(), paramString, objectId, _internalId); handleArchivedRequest(archivedFile, sync, callback); } else { String url = buildUrl(batchSaveRelativeUrl()); if (InternalConfigurationController.globalInstance().getInternalLogger().isDebugEnabled()) { dumpHttpPostRequest(header, url, paramString); } AsyncHttpResponseHandler handler = createPostHandler(callback); AVHttpClient client = clientInstance(); Request.Builder builder = new Request.Builder(); updateHeaders(builder, header, callback != null && callback.isRequestStatisticNeed()); builder.url(url).post(RequestBody.create(AVHttpClient.JSON, paramString)); client.execute(builder.build(), sync, handler); } } catch (Exception exception) { processException(exception, callback); } }
public void postObject(final String relativePath, String object, boolean sync, boolean isEventually, GenericObjectCallback callback, String objectId, String _internalId) { try { if (isEventually) { File archivedFile = archiveRequest("post", relativePath, object, objectId, _internalId); handleArchivedRequest(archivedFile, sync, callback); } else { String url = buildUrl(relativePath); if (InternalConfigurationController.globalInstance().getInternalLogger().isDebugEnabled()) { dumpHttpPostRequest(null, url, object); } AsyncHttpResponseHandler handler = createPostHandler(callback); AVHttpClient client = clientInstance(); Request.Builder builder = new Request.Builder(); updateHeaders(builder, null, callback != null && callback.isRequestStatisticNeed()); builder.url(url).post(RequestBody.create(AVHttpClient.JSON, object)); client.execute(builder.build(), sync, handler); } } catch (Exception exception) { processException(exception, callback); } }
public void putObject(final String relativePath, String object, boolean sync, boolean isEventually, Map<String, String> header, GenericObjectCallback callback, String objectId, String _internalId) { try { if (isEventually) { File archivedFile = archiveRequest("put", relativePath, object, objectId, _internalId); handleArchivedRequest(archivedFile, sync, callback); } else { String url = buildUrl(relativePath); AsyncHttpResponseHandler handler = createPostHandler(callback); if (InternalConfigurationController.globalInstance().getInternalLogger().isDebugEnabled()) { dumpHttpPutRequest(header, url, object); } AVHttpClient client = clientInstance(); Request.Builder builder = new Request.Builder(); builder.url(url).put(RequestBody.create(AVHttpClient.JSON, object)); updateHeaders(builder, header, callback != null && callback.isRequestStatisticNeed()); client.execute(builder.build(), sync, handler); } } catch (Exception exception) { processException(exception, callback); } }
public void deleteObject(final String relativePath, Map<String, Object> object, boolean sync, boolean isEventually, GenericObjectCallback callback, String objectId, String _internalId) { try { if (isEventually) { File archivedFile = archiveRequest("delete", relativePath, null, objectId, _internalId); handleArchivedRequest(archivedFile, sync, callback); } else { String url = buildUrl(relativePath); String body = AVUtils.jsonStringFromMapWithNull(object); if (InternalConfigurationController.globalInstance().getInternalLogger().isDebugEnabled()) { dumpHttpDeleteRequest(null, url, body); } AsyncHttpResponseHandler handler = createPostHandler(callback); AVHttpClient client = clientInstance(); Request.Builder builder = new Request.Builder(); updateHeaders(builder, null, callback != null && callback.isRequestStatisticNeed()); builder.url(url) .delete(RequestBody.create(AVHttpClient.JSON, body)); client.execute(builder.build(), sync, handler); } } catch (Exception exception) { processException(exception, callback); } }