Announcement Announcement Module
Collapse
No announcement yet.
Error handling: how to access the message that thrown the exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error handling: how to access the message that thrown the exception

    Hallo all.
    I configured my gateway with a custom error channel.

    <int:gateway id="onlineMessageGateway" service-interface="it.alten.intesasanpaolo.contratto.onlin e.gateway.OnlineMessageGateway" default-request-channel="onlineMessagePreProcessingChannel" error-channel="errorHandler"/>

    Now when in one of my chains is raised an exception the service activator subscribed on the errorHandler channel is executed:

    Code:
    public void activate(Message<?> message) {
    		logger.debug("Calling error handler activator");
    		
    		logger.debug("Message {}", message);
    		Object payload = message.getPayload();
    		
    		logger.debug("Payload {}", payload);		
    	}
    And this is the log:

    Code:
    2011-05-25 18:26:35,921 DEBUG 01025649900982072 - 009 - 1343 [ReimpiantoContrattoActivator] Calling error handler activator 
    2011-05-25 18:26:35,921 DEBUG 01025649900982072 - 009 - 1343 [ReimpiantoContrattoActivator] Message [Payload=org.springframework.integration.MessageHandlingException: java.lang.NullPointerException][Headers={timestamp=1306340795828, id=23f207df-7e90-44e5-a903-ee558956589d}] 
    2011-05-25 18:26:35,921 DEBUG 01025649900982072 - 009 - 1343 [ReimpiantoContrattoActivator] Payload org.springframework.integration.MessageHandlingException: java.lang.NullPointerException
    Is it possible to access the message payload that thrown the exception?

    Kind regards
    Massimo

  • #2
    If the payload of the error message is an instance of MessagingException (which your MessageHandlingException is), you can access the message that caused the error like this:

    Code:
    import org.springframework.integration.Message;
    import org.springframework.integration.MessagingException;
    
    ...
    
    if (message.getPayload() instanceof MessagingException) {
        Message<?> failedMessage = ((MessagingException) message.getPayload()).getFailedMessage();
    }

    Comment


    • #3
      Ok, that was the way.
      Now I would like to use the DataAccessException translation.

      So I annotated my genericDao in this way:

      Code:
      @Repository
      public class GenericDaoJpaImpl<T, ID extends Serializable> implements GenericDao<T, ID> {
      	private Class<T> entityClass;
      
      	private EntityManagerFactory entityManagerFactory;
      	
      	public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
      		this.entityManagerFactory = entityManagerFactory;
      	}
      I enabled on the context the annotation config as described below:
      Code:
      <context:annotation-config/>
      But when I receive a constraint violation (so a SQLException) it seems that the translation is not executed

      Code:
      2011-05-30 16:16:30,156 ERROR 01025649900982072 - 009 - 1646 [ErrorHandlerActivator] Exception org.springframework.integration.MessageHandlingException: org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion: sync=[email protected]81cb6
      
      Internal Exception: java.sql.SQLException: [BEA][Oracle JDBC Driver][Oracle]ORA-00001: unique constraint (JSP_OWN.IDX_MC_CC_RAPPORTI_02) violated
      
      Error Code: 1
      Call: INSERT INTO S_MC_CC_RAPPORTI (COD_RAPPORTO, COD_MATRICOLAGESTORE, DESC_ATTRIBUTO, COD_TIPORAPPORTO, COD_ABI, NUM_RAPPORTO, FLAG_RENDICONTAZIONE, COD_CATEGORIA, COD_STATORAPPORTO, FLAG_SB_ATTIVO, COD_GESTORE, TIMESTAMP_AGGIORNAMENTO, COD_NSG, DEN_FILIALE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
       bind => [1234567, null, CC1000S0, 1 , 01025, 87654321, null, 3516, null, null, null, null, null, 00521]
      Query: InsertObjectQuery([ContoCorrente@3a2be1'[ContoCorrente@3a2be1'codiceRapporto1234567''abi=01025''filiale=[Filiale@34b48f codiceFiliale= = '00521''descrizioneFiliale=TORINO - AGENZIA 21']''categoria=3516''numeroRapporto=87654321''formaTecnica=CC1000S0''tipoRapporto=null''statoRapporto=null''rendicontazione=null''smallBusinessAttivo=null']''coordinateBancarieInterne=null''coordinateBancarieVisualizzate=null''divisa=null''codiceServizio=null'])
      Any idea?
      Kind regards
      Massimo

      Comment

      Working...
      X