Announcement Announcement Module
Collapse
No announcement yet.
Custom Exception Translation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Exception Translation

    Hello,

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

    I have declared my bean as followed:

    Code:
    	
    <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" />
    Code:
    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?

  • #2
    This works for me...

    Code:
    <bean id="myExceptionTranslator" class="xxx.MyExceptionTranslator"/>
    <flex:message-broker>
      <flex:exception-translator ref="myExceptionTranslator"/>
    </flex:message-broker>
    Code:
    package xxx;
    
    import org.springframework.flex.core.ExceptionTranslator;
    import org.springframework.security.AccessDeniedException;
    import org.springframework.security.AuthenticationException;
    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.class, clazz));
      }
      public MessageException translate(Throwable t) {
        MessageException ex = new MessageException();
        ex.setCode("Application.Service");
        ex.setMessage(t.getLocalizedMessage());
        ex.setRootCause(t);
        return ex;
      }
    }

    Comment


    • #3
      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..

      Comment


      • #4
        It cannot work in my place, do you get a solution?

        In my app, exception never go into ExceptionTranslator

        the result is same as you

        Do I miss some tips?

        Comment


        • #5
          Oh, it works

          my stupid mistake!
          It can work and work very well in my app.

          Comment

          Working...
          X