You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by vassilis <2b...@gmail.com> on 2016/11/30 10:39:43 UTC

Re: Problem with exception handler (onException) on Camel 2.12.X routes.

Hi,

It seems I have the same issue with Camel 22.15.1.redhat-621159. Did you
find a proper solution?

Just to be more specific, in my case OnException is executed fine if an
exception is thrown in the route, BUT it is not executed in cases when the
Database is down and no transaction can be even created. Which is the same
situation as you are facing.

For example, the NON working stack trace follows. Notice that all start from
a JMS consumer (onMessage) and the exception is thrown when Camel is trying
to create a NEW transaction (doBegin). It does not enter the route logic at
all.

On the other hand, if for example, a RuntimeException is thrown in the Route
(e.g. a validation error I throw under certain conditions), then OnException
is executed and the transaction rolls back successfully.  

*Non working stack trace:*

Caused by: org.springframework.transaction.CannotCreateTransactionException:
Could not open JDBC Connection for transaction; nested exceptio
n is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications
link failure

The last packet sent successfully to the server was 0 milliseconds ago. The
driver has not received any packets from the server.
        at
org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:243)[302:org.apache.se
rvicemix.bundles.spring-jdbc:3.2.12.RELEASE_2]
        at
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java
:372)[209:org.apache.servicemix.bundles.spring-tx:3.2.12.RELEASE_2]
        at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)[209:org.apache.servicemix.bundl
es.spring-tx:3.2.12.RELEASE_2]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.doInTransactionTemplate(TransactionErrorHandler.java:174)[210:org.apache.came
l.camel-spring:2.15.1.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.processInTransaction(TransactionErrorHandler.java:134)[210:org.apache.camel.c
amel-spring:2.15.1.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:103)[210:org.apache.camel.camel-spring:2
.15.1.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:112)[210:org.apache.camel.camel-spring:2
.15.1.redhat-621159]
        at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)[205:org.apache.camel.camel-core:2.15.1
.redhat-621159]
        at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)[205:org.apache.camel.camel-core:2.15.1
.redhat-621159]
        at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)[205:org.apache.camel.camel-core:2.15.1.redhat-6
21159]
        at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87)[205:org.apache.camel.camel-core:2.15.1.
redhat-621159]
        at
org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103)[216:org.apache.camel.camel-jms
:2.15.1.redhat-621159]
        ... 11 more
*
Working stacktrace:*

java.lang.IllegalArgumentException: The mandatory field defined at the
position 17 is empty for the line: 1
        at
org.apache.camel.dataformat.bindy.BindyCsvFactory.bind(BindyCsvFactory.java:188)[222:org.apache.camel.camel-bindy:2.15.1.redhat-6
21159]
        at
org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.unmarshal(BindyCsvDataFormat.java:185)[222:org.apache.camel.camel-bindy:
2.15.1.redhat-621159]
        at
org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:69)[205:org.apache.camel.camel-core:2.15.1.redhat-6
21159]
        at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[205:org.apache.camel.camel-core:2.
15.1.redhat-621159]
        at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)[205:org.apache.camel.camel-core:2.15.1
.redhat-621159]
        at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)[205:org.apache.camel.camel-core:2.15.1.redhat-6
21159]
        at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:329)[205:org.apache.camel.camel-core:2.15.1
.redhat-621159]
        at
org.apache.camel.processor.DefaultErrorHandler.process(DefaultErrorHandler.java:56)[205:org.apache.camel.camel-core:2.15.1.redhat
-621159]
        at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:172)[205:org.apache.camel.camel-core:2.15.1
.redhat-621159]
        at
org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[205:org.apache.camel.camel-core:2.15.1.redhat-621159]
        at
org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[205:org.apache.camel.camel-core:2.15.1.redhat-621159]
        at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)[205:org.apache.camel.camel-core:2.15.1
.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.processByErrorHandler(TransactionErrorHandler.java:218)[210:org.apache.camel.
camel-spring:2.15.1.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler$1.doInTransactionWithoutResult(TransactionErrorHandler.java:181)[210:org.apac
he.camel.camel-spring:2.15.1.redhat-621159]
        at
org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33
)[209:org.apache.servicemix.bundles.spring-tx:3.2.12.RELEASE_2]
        at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)[209:org.apache.servicemix.bundl
es.spring-tx:3.2.12.RELEASE_2]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.doInTransactionTemplate(TransactionErrorHandler.java:174)[210:org.apache.came
l.camel-spring:2.15.1.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.processInTransaction(TransactionErrorHandler.java:134)[210:org.apache.camel.c
amel-spring:2.15.1.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:103)[210:org.apache.camel.camel-spring:2
.15.1.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:112)[210:org.apache.camel.camel-spring:2
.15.1.redhat-621159]
        at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[205:org.apache.camel.camel-core:2.
15.1.redhat-621159]
        at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)[205:org.apache.camel.camel-core:2.15.1
.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.processByErrorHandler(TransactionErrorHandler.java:218)[210:org.apache.camel.
camel-spring:2.15.1.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler$1.doInTransactionWithoutResult(TransactionErrorHandler.java:181)[210:org.apac
he.camel.camel-spring:2.15.1.redhat-621159]
        at
org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33
)[209:org.apache.servicemix.bundles.spring-tx:3.2.12.RELEASE_2]
        at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)[209:org.apache.servicemix.bundl
es.spring-tx:3.2.12.RELEASE_2]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.doInTransactionTemplate(TransactionErrorHandler.java:174)[210:org.apache.came
l.camel-spring:2.15.1.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.processInTransaction(TransactionErrorHandler.java:134)[210:org.apache.camel.c
amel-spring:2.15.1.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:103)[210:org.apache.camel.camel-spring:2
.15.1.redhat-621159]
        at
org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:112)[210:org.apache.camel.camel-spring:2
.15.1.redhat-621159]
        at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)[205:org.apache.camel.camel-core:2.15.1
.redhat-621159]
        at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)[205:org.apache.camel.camel-core:2.15.1
		
		.redhat-621159]
        at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)[205:org.apache.camel.camel-core:2.15.1.redhat-6
21159]
        at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87)[205:org.apache.camel.camel-core:2.15.1.
redhat-621159]
        at
org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103)[216:org.apache.camel.camel-jms
:2.15.1.redhat-621159]





--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-exception-handler-onException-on-Camel-2-12-X-routes-tp5742605p5790794.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem with exception handler (onException) on Camel 2.12.X routes.

Posted by vassilis <2b...@gmail.com>.
After doing a little bit more investigation, what happens (as I understand
this at least..) is the following:

1. TransactionErrorHandler.processInTransaction() delegates the routing of
the exchange to be executed within a transaction. 

            logTransactionBegin(redelivered, ids);

* // HERE the  transactionTemplate.execute(new
TransactionCallbackWithoutResult() {} is executed
// see next snippet of code
            doInTransactionTemplate(exchange);*

            logTransactionCommit(redelivered, ids);

        } catch (TransactionRollbackException e) {
            // do not set as exception, as its just a dummy exception to
force spring TX to rollback
            logTransactionRollback(redelivered, ids, null, true);
        } catch (Throwable e) {
            exchange.setException(e);
            logTransactionRollback(redelivered, ids, e, false);
        } finally {
            // mark the end of this transaction boundary
            exchange.getUnitOfWork().endTransactedBy(transactionKey);
        }

To do so Camel passes an anonymous inner class to the TX Transaction
template:

TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) 
{
 // here the Camel processors and whatever is in the Route definition is
executed
 // AND the OnException() handling!
 // this is executed within a transaction
}
}

Also the code of the *transactionTemplate.execute()* that executes the above
Callback.

	public <T> T execute(TransactionCallback<T> action) throws
TransactionException {
		if (this.transactionManager instanceof
CallbackPreferringPlatformTransactionManager) {
			return ((CallbackPreferringPlatformTransactionManager)
this.transactionManager).execute(this, action);
		}
		else { 
                        *// here the exception is thrown, because DB is
down!*
			TransactionStatus status = this.transactionManager.getTransaction(this);
			T result;
			try {
				result = action.doInTransaction(status); *// the callback is executed
here*
			}


The result is that the Camel TransactionCallbackWithoutResult (Camels
anonymous inner class), that does the routing of the exchange and the
execution of the OnException() is never executed.

Code executes the following catch statements:

 } catch (Throwable e) {
            exchange.setException(e);
            logTransactionRollback(redelivered, ids, e, false);
        } finally {
            // mark the end of this transaction boundary
            exchange.getUnitOfWork().endTransactedBy(transactionKey);
        }

Is this expected behavior? I ask this, because the most probable scenario
that a Camel user would want is to be able to handle this exception and
probably send an alert and/ or a message to a DLQ.

Any hint is more than welcome!

Thanks!










--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-exception-handler-onException-on-Camel-2-12-X-routes-tp5742605p5790824.html
Sent from the Camel - Users mailing list archive at Nabble.com.