We have a Flex application communicating with a Java backend via BlazeDS.

Before, if an SQL error occurred, the SQL exception would be shown as an alert in the Flex application and the CallResponder's fault handler was called informing the user that something had gone wrong.

Flex code: Call Responder:

<s:CallResponder id="loginResult" result="loginResult_resultHandler(event)" fault="displayGenericErrorMessage(event)"/>

Call to service:

var authenticationMessage:String = loginResult.lastResult as String;

Old Java Code:

Map resultSet = simpleJdbcCall.execute();
ArrayList list = (ArrayList) resultSet.get("RESULT_SET");

Now, as can be seen from the code above, the SQL execute statement is not inside a try-catch block (a coding error). This actually doesn't cause too much trouble but we wanted to be able to print the exception to the error log and it's correct to put the execute statement inside a try-catch block anyway. So, the code became as follows:

New Java code:

ArrayList list = new ArrayList();

        try {
            Map resultSet = simpleJdbcCall.execute();
            list = (ArrayList) resultSet.get("RESULT_SET");
        }
        catch (Exception e) {
            logger.error(e.getMessage());
        }

Before (without the try-catch block), if an exception occurred, the exception's message was passed back to Flex where it was displayed as an alert and the CallResponder's fault handler was called. We didn't necessarily want the exception shown as an alert but having the fault handler being called was good as it informed the user that something had gone wrong.

Now (with the try-catch block), if an exception occurs, the exception is put out to the log as required but the CallResponder's fault handler is not called. Flex thinks that the service returned successfully with a null value which is not correct.

Is there some other way to indicate to Flex that the call was not successful and that the fault handler should be called other than removing the try-catch block?

Thanks in advance.

有帮助吗?

解决方案

Just rethrow the exception after it's been logged on the server-side and it will propergate to the Flex frontend as before.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top