There was an unhandled failure on the server

3 篇文章 0 订阅

在Spring BlazeDS Integration 集成环境中,我们尝试抛出以下自定义异常

	public void remove() throws Exception {
			try {
				throw new LmxException("删除失败!");
			} catch (LmxException e) {
				throw e;
			}
	}
	

  
  在Flex端是这样捕获的

private  function operateFaultHandler(event:FaultEvent):void{ 
var exception:LmxException = event.fault.rootCause as LmxException; 
Alert.show(exception.message,"提示"); 
} 


 

   
但是抛出了There was an unhandled failure on the server.Spring BlazeDS Integration 的原文DOC如下。小弟英语不好,

简单翻译几句,服务器端抛出异常时,为了让Flex端获取到更为友好的信息,原始的异常的信息必须能够被解析成MessageException类的实例

2.8. Using Custom Exception Translators

In order to propagate useful information back to the Flex client when an exception occurs on the server, the original exception must be translated into an instance of flex.messaging.MessageException. If special translation logic is not applied, a generic "Server.Processing" error will propagate to the client that doesn't give the client the chance to reason on the real cause of the error to take appropriate action. Special exception translators are configured by default for transforming Spring Security exceptions into an appropriate MessageException, but it could also be useful to provide custom translation for your own application-level exceptions.


Custom exception translation logic can be provided through implementations of the org.springframework.flex.core.ExceptionTranslator interface. These implementations must be configured as Spring beans and then registered through the XML configuration namespace as follows:


  自定义异常解析逻辑可以由实现ExceptionTranslator 的接口实现,这些实现类必须按照以下的配置,LmxException 是自定义异常类

public class ExceptionTranslatorImpl implements ExceptionTranslator { 

@Override 
public boolean handles(Class> clazz) { 
// TODO Auto-generated method stub 
return Boolean.TRUE; 
} 

@Override 
public MessageException translate(Throwable throwable) { 
// TODO Auto-generated method stub 
MessageException messageException = null; 
if (throwable != null) { 
if (throwable instanceof LmxException) { 
messageException = new MessageException(); 

LmxException lmxException = new LmxException(); 
lmxException.setMessage("异常"); 
messageException.setRootCause(lmxException); 
} 
} 
return messageException; 
} 
} 
<!-- Custom exception translator configured as a Spring bean -->
<bean id="myExceptionTranslator" class="com.foo.app.MyBusinessExceptionTranslator"/>

<flex:message-broker>
	<flex:exception-translator ref="myExceptionTranslator"/>
</flex:message-broker>   

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值