use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class UploadFileAsyncTask method doInBackground.
private void doInBackground(final File file, final String path) {
final AsyncUploadMessage asyncUploadMessage = new AsyncUploadMessage(uploadCallback);
ThreadPoolService.getPoolExecutor().execute(new Runnable() {
@Override
public void run() {
try {
FileOutputStreamRouter fileOutputStreamRouter = new FileOutputStreamRouter(file, new UploadCallback() {
public void onProgressUpdate(Integer progress) {
asyncUploadMessage.setCurrentProgress(progress);
ResponseCarrier.getInstance().deliverMessage(asyncUploadMessage);
}
});
BackendlessFile result = Backendless.Files.uploadFromStream(fileOutputStreamRouter, file.getName(), path, overwrite);
ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<BackendlessFile>(result, responder));
} catch (Exception e) {
ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<BackendlessFile>(new BackendlessFault(e), responder));
}
}
});
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class UserService method getUserRoles.
public void getUserRoles(final AsyncCallback<List<String>> responder) {
try {
AsyncCallback<String[]> callback = new AsyncCallback<String[]>() {
@Override
public void handleResponse(String[] response) {
if (responder != null)
responder.handleResponse(Arrays.asList(response));
}
@Override
public void handleFault(BackendlessFault fault) {
if (responder != null)
responder.handleFault(fault);
}
};
Invoker.invokeAsync(USER_MANAGER_SERVER_ALIAS, "getUserRoles", new Object[] {}, callback);
} catch (Throwable e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class UserService method register.
public void register(final BackendlessUser user, final AsyncCallback<BackendlessUser> responder) {
try {
checkUserToBeProper(user);
BackendlessSerializer.serializeUserProperties(user);
Invoker.invokeAsync(USER_MANAGER_SERVER_ALIAS, "register", new Object[] { user.getProperties() }, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
response.setPassword(user.getPassword());
user.clearProperties();
user.putProperties(response.getProperties());
if (responder != null)
responder.handleResponse(response);
}
@Override
public void handleFault(BackendlessFault fault) {
if (responder != null)
responder.handleFault(fault);
}
}, new AdaptingResponder(BackendlessUser.class, new BackendlessUserAdaptingPolicy()));
} catch (BackendlessException e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class UserServiceAndroidExtra method getSocialDialogResponder.
private AsyncCallback<JSONObject> getSocialDialogResponder(final AsyncCallback<BackendlessUser> responder) {
return new AsyncCallback<JSONObject>() {
@Override
public void handleResponse(JSONObject response) {
try {
BackendlessUser result = new BackendlessUser();
Iterator keys = response.keys();
while (keys.hasNext()) {
String key = String.valueOf(keys.next());
result.setProperty(key, JSONObjectConverter.fromJson(response.get(key)));
}
if (responder != null)
responder.handleResponse(result);
} catch (Exception e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
@Override
public void handleFault(BackendlessFault fault) {
if (responder != null)
responder.handleFault(fault);
}
};
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class AtomicCallback method handleResponse.
@Override
public void handleResponse(Object response) {
Number numberResult = null;
if (response instanceof Integer)
numberResult = Long.valueOf(response.toString());
else if (response instanceof Double)
numberResult = Double.valueOf(response.toString());
else
realCallback.handleFault(new BackendlessFault("Result is not a number. Expecting either Integer or Double, but received " + response.getClass()));
Class counterType = (Class) ReflectionUtil.getCallbackGenericType(realCallback);
Number result = Counters.convertToType(numberResult, counterType);
realCallback.handleResponse((T) result);
}
Aggregations