PDA

View Full Version : Custom Exception Translation



blueveinz
May 25th, 2009, 06:13 AM
Hello,

Does anyone have an example of how to use custom exception translation in Spring-Blazeds?

I have declared my bean as followed:



<flex:message-broker id="_messageBroker">
<flex:exception-translator ref="exceptionTranslator" />
</flex:message-broker>

<flex:message-destination id="messagingDestination" message-broker="_messageBroker" />

<bean id="exceptionTranslator" class="exceptions.MyExceptionTranslator" />


import org.springframework.flex.core.ExceptionTranslator;

import flex.messaging.MessageException;

public class MyExceptionTranslator implements ExceptionTranslator {

public boolean handles(Class<?> arg0) {
return true;
}

public MessageException translate(Throwable t) {
MessageException me = new MessageException();
//blabla
throw me;
}

But when an exception occures (I catch exceptions and throw them further) I never get into MyExceptionTranslator..

What am I doing wrong?

ARAsoft
May 25th, 2009, 07:10 AM
<bean id="myExceptionTranslator" class="xxx.MyExceptionTranslator"/>
<flex:message-broker>
<flex:exception-translator ref="myExceptionTranslator"/>
</flex:message-broker>



package xxx;

import org.springframework.flex.core.ExceptionTranslator;
import org.springframework.security.AccessDeniedException ;
import org.springframework.security.AuthenticationExcepti on;
import org.springframework.util.ClassUtils;

import flex.messaging.MessageException;

public class MyExceptionTranslator implements ExceptionTranslator {

public boolean handles(Class<?> clazz) {
return !(ClassUtils.isAssignable(AuthenticationException. class, clazz) ||
ClassUtils.isAssignable(AccessDeniedException.clas s, clazz));
}
public MessageException translate(Throwable t) {
MessageException ex = new MessageException();
ex.setCode("Application.Service");
ex.setMessage(t.getLocalizedMessage());
ex.setRootCause(t);
return ex;
}
}

blueveinz
May 25th, 2009, 07:53 AM
Can you tell me how you catch your errors? I have exactly the same configuration as you do but for some weird reasons it won't work..

poddd
Jun 23rd, 2009, 01:15 PM
In my app, exception never go into ExceptionTranslator

the result is same as you

Do I miss some tips?

poddd
Jun 23rd, 2009, 01:32 PM
my stupid mistake!
It can work and work very well in my app.