camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen">
Subject RE: Error Handler and OutHeaders
Date Tue, 14 Oct 2008 10:49:20 GMT

Id is null because the exchange that is caught by onException is a snapshot of the exchange
just before your bean listTransformer is invoked. 

Any changes to the exchange that happens in listTransformer is not effective/visible for the
error handler.

You can use 2 bean calls to let the id be visible
		.beanRef("listTransformer", "initId")
		.beanRef("listTransformer", "fromStringToFundList")		.to("bean:fundListDao?methodName=save");

For instance a initId() method that is simple and just set the id.

Then if there is a failure in the 2nd bean then the snapshot is from just before the 2nd bean

Med venlig hilsen
Claus Ibsen
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576

-----Original Message-----
From: borgel [] 
Sent: 14. oktober 2008 12:38
Subject: Error Handler and OutHeaders

I have set up a route with an error handler like this:
	public void configure() throws Exception
		.beanRef("listTransformer", "transformFailed")
		.beanRef("listTransformer", "fromStringToFundList")

in the listTransformer I add an id value to the map:
public List<Fund> fromStringToFundList(@Headers Map in,
@org.apache.camel.Body String payload, @OutHeaders Map out)
Header  header = getHeader(payload);
id = header.getId();
out.put("headerId", id);"Id in transformer: " + id);
List<Fund> funds = getFunds(payload)

return funds

When an error occurs in getFunds the errorHandler kicks in and calls
public Object transformFailed(@Headers Map in, @org.apache.camel.Body String
payload, @OutHeaders Map out)
{"Id in transformFailed: " + in.get("headerId"));
	return "ERROR";

This will produce the following output:
Id in transformer: 586
Id in transformFailed: null

Why is id in transformFailed null?
View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message