[
https://issues.apache.org/jira/browse/CAMEL-5139?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13252292#comment-13252292
]
Radoslaw Szymanek edited comment on CAMEL-5139 at 4/12/12 8:58 AM:
-------------------------------------------------------------------
Unfortunately, I do not have enough time to do proper bug reporting. I hope the
copy&paste from the example I am working with is enough to help you reproduce
it.
I post the route for which I hit the problem with continued.
The example works like this. There are two beans. Both are raising the same
exception but for different reasons. The first time exception is raised, the
problem is handled by processor and continued with predicate will return true,
so the the second bean is used for processing the exchange. The second bean
also raises the exception. Now, if FAILURE_HANDLED remains within the exchange
(check CRUCIAL in code) then the second time exception policy is not called and
exception propagated directly to the caller. If I remove the property then the
exception policy is called the exception is ignored due to the presence of the
header (isAdult) and the processing is completed.
If I remove FAILURE_HANDLED then my test of this route sees no exception, If I
keep this property then the test sees exception raised by ValidityCheck even if
it was AgeValidityBean that caused the final problem.
{code}
errorHandler(defaultErrorHandler().maximumRedeliveries(1));
onException(NullPointerException.class).setOnRedelivery(new
NullRegistrationDateProcessor());
onException(IllegalArgumentException.class).handled(new Predicate() {
public boolean matches(Exchange exchange) {
boolean result = simple("${header.isAdult} ==
true").matches(exchange);
return result;
}
});
from("direct:toPropertyFileSmart")
.errorHandler(defaultErrorHandler().maximumRedeliveries(0))
.onException(IllegalArgumentException.class)
.process(new NullRegistrationDateProcessor())
.continued(new Predicate() {
public boolean matches(Exchange exchange) {
Object body = exchange.getIn().getBody();
if (body instanceof Registration) {
Registration registration = (Registration) body;
if (registration.getRegistrationDate() != null
&&
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class).
getMessage().equals("Registration date
attribute of the registration is null")) {
// if the line below is removed then the error
raised by ValidityCheck will remain
// and cause problems when the second bean
raises the exception.
// CRUCIAL to have
exchange.removeProperty(Exchange.FAILURE_HANDLED);
return true;
}
}
return false;
}
}).end()
.bean(ValidityCheck.class)
.onException(IllegalArgumentException.class)
.continued(new Predicate() {
public boolean matches(Exchange exchange) {
boolean result = simple("${header.isAdult} ==
true").matches(exchange);
exchange.removeProperty(Exchange.FAILURE_HANDLED);
return result;
}
}).end()
.bean(AgeValidityBean.class).to("direct:toPropertyFile");
{code}
I decided not to remove any part of the code (making it rather poor bug report)
but I do not want to run a risk of removing an important clue of how to
reproduce this bug in a simpler test.
was (Author: radsz):
Unfortunately, I do not have enough time to do proper bug reporting. I hope
the copy&paste from the example I am working with is enough to help you
reproduce it.
I post the route for which I hit the problem with continued.
The example works like this. There are two beans. Both are raising the same
exception but for different reasons. The first time exception is raised, the
problem is handled by processor and continued with predicate will return true,
so the the second bean is used for processing the exchange. The second bean
also raises the exception. Now, if FAILURE_HANDLED remains within the exchange
(check CRUCIAL in code) then the second time exception policy is not called and
exception propagated directly to the caller. If I remove the property then the
exception policy is called the exception is ignored due to the presence of the
header (isAdult) and the processing is completed.
If I remove FAILURE_HANDLED then my test of this route sees no exception, If I
keep this property then the test sees exception raised by ValidityCheck even if
it was AgeValidityBean that caused the final problem.
{code}
errorHandler(defaultErrorHandler().maximumRedeliveries(1));
onException(NullPointerException.class).setOnRedelivery(new
NullRegistrationDateProcessor());
onException(IllegalArgumentException.class).handled(new Predicate() {
public boolean matches(Exchange exchange) {
boolean result = simple("${header.isAdult} ==
true").matches(exchange);
return result;
}
});
from("direct:toPropertyFileSmart")
.errorHandler(defaultErrorHandler().maximumRedeliveries(0))
.onException(IllegalArgumentException.class)
.process(new NullRegistrationDateProcessor())
.continued(new Predicate() {
public boolean matches(Exchange exchange) {
Object body = exchange.getIn().getBody();
if (body instanceof Registration) {
Registration registration = (Registration) body;
if (registration.getRegistrationDate() != null
&&
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class).
getMessage().equals("Registration date
attribute of the registration is null")) {
// if the line below is removed then the error
raised by ValidityCheck will remain
// and cause problems when the second bean
raises the exception.
// CRUCIAL to have
exchange.removeProperty(Exchange.FAILURE_HANDLED);
return true;
}
}
return false;
}
}).end()
.bean(ValidityCheck.class)
.onException(IllegalArgumentException.class)
.continued(new Predicate() {
public boolean matches(Exchange exchange) {
boolean result = simple("${header.isAdult} ==
true").matches(exchange);
exchange.removeProperty(Exchange.FAILURE_HANDLED);
return result;
}
}).end()
.bean(AgeValidityBean.class).to("direct:toPropertyFile");
{code}
I decided not to remove any part of the code (making it rather poor bug report)
but I do not want to run a risk of removing an import clue of how to reproduce
this bug in a simpler test.
> Continued(Predicate) does not work when invoked the second time in the Camel
> flow.
> ----------------------------------------------------------------------------------
>
> Key: CAMEL-5139
> URL: https://issues.apache.org/jira/browse/CAMEL-5139
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.9.1
> Reporter: Radoslaw Szymanek
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 2.9.2, 2.10.0
>
>
> When Camel flow contains error handling as continued(Predicate), it is not
> invoked when the error occurs for the second time (even in different
> onException). What is more the exception is not handled even by global
> onException and Camel flow is interrupted.
> It is similar issue to https://issues.apache.org/jira/browse/CAMEL-4057
> but not for continued(true) but continued(Predicate).
> The same fix also fixes this problem. Simply adding
> exchange.removeProperty(Exchange.FAILURE_HANDLED);
> just before returning true from the Predicate makes the second onException
> being called and the second time the exception is raised it can be continued
> again.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira