简体   繁体   English

如何从Java中将错误传回Flex / BlazeDS

[英]How to relay error back to Flex/BlazeDS from Java

We have a Flex application communicating with a Java backend via BlazeDS. 我们有一个Flex应用程序通过BlazeDS与Java后端进行通信。

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. 之前,如果发生SQL错误,SQL异常将在Flex应用程序中显示为警报,并且调用CallResponder的错误处理程序,通知用户出现了问题。

Flex code: Call Responder: Flex代码:呼叫响应者:

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

Call to service: 致电服务:

var authenticationMessage:String = loginResult.lastResult as String;

Old Java Code: 旧Java代码:

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). 现在,从上面的代码可以看出,SQL execute语句不在try-catch块中(编码错误)。 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. 这实际上不会造成太多麻烦,但我们希望能够将异常打印到错误日志中,并且无论如何将execute语句放在try-catch块中是正确的。 So, the code became as follows: 所以,代码变成如下:

New Java code: 新的Java代码:

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. 之前(没有try-catch块),如果发生异常,则异常的消息被传递回Flex,在那里它被显示为警报并且调用了CallResponder的错误处理程序。 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. 现在(使用try-catch块),如果发生异常,则会根据需要将异常放到日志中,但不会调用CallResponder的错误处理程序。 Flex thinks that the service returned successfully with a null value which is not correct. Flex认为服务成功返回,其null ,这是不正确的。

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? 有没有其他方法向Flex表明调用不成功,并且应该调用错误处理程序而不是删除try-catch块?

Thanks in advance. 提前致谢。

只需在服务器端登录之后重新抛出异常,它就像以前一样适用于Flex前端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM