public void onTransportSuccess(String payload) {
ResponseMessage response = AutoBeanCodex.decode(
MessageFactoryHolder.FACTORY, ResponseMessage.class, payload).as();
if (response.getGeneralFailure() != null) {
ServerFailureMessage failure = response.getGeneralFailure();
ServerFailure fail = new ServerFailure(failure.getMessage(),
failure.getExceptionType(), failure.getStackTrace(),
failure.isFatal());
fail(receiver, fail);
return;
}
// Process violations and then stop
if (response.getViolations() != null) {
Set<Violation> errors = new HashSet<Violation>();
for (ViolationMessage message : response.getViolations()) {
errors.add(new MyViolation(message));
}
reuse();
for (AbstractRequest<?> request : new ArrayList<AbstractRequest<?>>(
invocations)) {
request.onViolation(errors);
}
if (receiver != null) {
receiver.onViolation(errors);
}
return;
}
// Process operations
processReturnOperations(response);
// Send return values
for (int i = 0, j = invocations.size(); i < j; i++) {
if (response.getStatusCodes().get(i)) {
invocations.get(i).onSuccess(response.getInvocationResults().get(i));
} else {
ServerFailureMessage failure = AutoBeanCodex.decode(
MessageFactoryHolder.FACTORY, ServerFailureMessage.class,
response.getInvocationResults().get(i)).as();
invocations.get(i).onFail(
new ServerFailure(failure.getMessage(),
failure.getExceptionType(), failure.getStackTrace(),
failure.isFatal()));
}
}