You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by shyenuganti <sh...@gmail.com> on 2013/05/08 23:15:17 UTC

Issue with using onException()

Hi All, 

Here is my route. The goal I am trying to achieve is to send a STATUS
(0=success, 1= failure) back to the caller.  It works for a successful
execution. I am returning a 0 from the onCompletion().

When the route fails at the ".unmarshal(beanIO)" step I need to stop
processing the route any further, and reply back with a 0 to the consumer on
"direct:routeStatus".

But, As of now, the route does not stop on exception as it is handled it in
doCatch(). How can I stop the route here and send a response back? Currently
it gives me an error saying "no consumers present on direct:routeStatus".
Why is this a problem when it was working for the success scenario?

Does the onCompletion() execute even on exception cases?

When I try to use one single try catch(), It is giving me an error saying
ChoiceDefinition do not support doCatch(). Why is it so ? 




onException(Exception.class).handled(true).maximumRedeliveries(0)
				.setBody(constant(1))
				.log("Returning Status of the route: ${body}")
				.to("direct:routeStatus");


	from(getDirectEndPoint()).routeId(getRouteId())
			.onCompletion()
				.setBody(constant(0)).to("direct:routeStatus")
			.end()
		.pollEnrich(getFileEndPoint())
			.beanRef("loggingBean", "logDebug(${id}, '"+this.getClass().getName()+"',
'Reading Flat File')")
			.doTry()	
				.unmarshal(beanIO)
			.doCatch(Throwable.class)
				.beanRef("loggingBean", "endError(${id},
'"+this.getClass().getName()+"',  ${exception}, 'Exception while
Unmarshalling File : ${header.CamelFileName} ')")
			.end()
			.split(body())
			.choice()
				   .when(transactionRecord)
					   .choice()
					   		.when(UNDERNOTICE_OR_RESCISSION)
					   		.doTry()
						   		.bean(PolicyStatusRequestHelper.class,"getStatusRequest")
						   		.marshal().json()
						   		.inOut(getJmsEndPoint())
						   		.beanRef("loggingBean", "logDebug( ${id},
'"+this.getClass().getName()+"', 'Transaction Status :"+ simple("${body}")
+"')")               
							.doCatch(Throwable.class)
								.beanRef("loggingBean", "endError(${id},
'"+this.getClass().getName()+"',  ${exception}, 'Exception while sending
StatusRequest to JMS queue')")
							.end();	


How can I properly use onException() in my above route to achieve the same?
I tried putting it at different places. But nothing seems to work. I am not
able to propagate the exception properly. 

Can anyone really help with this?

THanks !



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-using-onException-tp5732200.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue with using onException()

Posted by shyenuganti <sh...@gmail.com>.
FILE ARRAY LIST refers to the array list of all records in the file. 
Success Route refers to a separate direct route that just returns a "0" to
the caller.
The whole cases are sub parts of the main route presented in post 1. Log
statements are changed for simplicity.

Please let me know if you need any more clarifications on what we are trying
to do. 

Thanks !




--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-using-onException-tp5732200p5732230.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue with using onException()

Posted by shyenuganti <sh...@gmail.com>.
Here is more research done on my route. I am presenting you with different
ways Camel is  behaving based on the end() or endChoice() statements
placement. I am adding my questions here. 

Can the Camel experts help me to understand how camel works under the
covers? This is getting really frustrating. Any help would be appreciated. 


CASE 1 :	
	
	.split(body()).stopOnException()
				.log("Inside SPlit. Record under Processs :  ${body}")
				.choice()
					   .when(transactionRecord)
					      .choice()
						   		.when(UNDERNOTICE_OR_RESCISSION)
						   				.log("Record of interested type")
								   		.bean(PolicyStatusRequestHelper.class,"getPolicyStatusRequest")
								   		.log("Marshalling to JSON")
								   		.marshal().json()
								   		.log("Sending to JMS Queue")
								   		.inOut(getJmsEndPoint())
								   		.log("JMS Reply - Transaction Status : ${body} ")               
									//.endChoice() //Actually ends when(UNDERNOTICE_OR_RESCISSION)
						.endChoice() //Actually ends when(transactionRecord)
			.end() //Ends split()
			.log("Done with record :  ${body}")
			.end() // May be ends PollEnrich
	   		.log("Completed Processing of File. Sending to Success Route")        
			.to(getDirectSuccess());
			
			
Result :

Success Status returned : 0
Times Success Route called : Once
Input file moved : No
Lock File Deleted : No


Questions:
Does one endChoice() end 2 choice()/When definitions in case of nested
choice() 

CASE 2:

	.split(body()).stopOnException()
				.log("Inside SPlit. Record under Processs :  ${body}")
				.choice()
					   .when(transactionRecord)
					      .choice()
						   		.when(UNDERNOTICE_OR_RESCISSION)
						   				.log("Record of interested type")
								   		.bean(PolicyStatusRequestHelper.class,"getPolicyStatusRequest")
								   		.log("Marshalling to JSON")
								   		.marshal().json()
								   		.log("Sending to JMS Queue")
								   		.inOut(getJmsEndPoint())
								   		.log("JMS Reply - Transaction Status : ${body} ")               
									//.endChoice() //Actually ends when(UNDERNOTICE_OR_RESCISSION)
						.endChoice() //Actually ends when(transactionRecord)
			.end() //Ends split()
			.log("Done with record :  ${body}")
			//.end() // May be ends PollEnrich
	   		.log("Completed Processing of File. Sending to Success Route")        
			.to(getDirectSuccess());

Result :

Success Status returned : FILE ARRAY LIST
Times Success Route called : More than Once
Input file moved : No
Lock File Deleted : YES


Questions:
What does the second end() close in this case?
The whole route runs to the end after SPLIT() in this case. Where does scope
of split actually end?

CASE 3 : 

	.split(body()).stopOnException()
				.log("Inside SPlit. Record under Processs :  ${body}")
				.choice()
					   .when(transactionRecord)
					      .choice()
						   		.when(UNDERNOTICE_OR_RESCISSION)
						   				.log("Record of interested type")
								   		.bean(PolicyStatusRequestHelper.class,"getPolicyStatusRequest")
								   		.log("Marshalling to JSON")
								   		.marshal().json()
								   		.log("Sending to JMS Queue")
								   		.inOut(getJmsEndPoint())
								   		.log("JMS Reply - Transaction Status : ${body} ")               
									//.endChoice() //Actually ends when(UNDERNOTICE_OR_RESCISSION)
						.endChoice() //Actually ends when(transactionRecord)
			.end() //Ends split()
			.log("Done with record :  ${body}")
			.end() // May be ends PollEnrich
	   		.log("Completed Processing of File. Sending to Success Route")        
			.to(getDirectSuccess());

Result :

Success Status returned : 0
Times Success Route called : Once
Input file moved : No
Lock File Deleted : NO


Questions:
Split works as expected in this case. 
Array List is sent to success route. But success route returns a 0.

CASE 4:

	.split(body()).stopOnException()
				.log("Inside SPlit. Record under Processs :  ${body}")
				.choice()
					   .when(transactionRecord)
					      .choice()
						   		.when(UNDERNOTICE_OR_RESCISSION)
						   				.log("Record of interested type")
								   		.bean(PolicyStatusRequestHelper.class,"getPolicyStatusRequest")
								   		.log("Marshalling to JSON")
								   		.marshal().json()
								   		.log("Sending to JMS Queue")
								   		.inOut(getJmsEndPoint())
								   		.log("JMS Reply - Transaction Status : ${body} ")               
									//.endChoice() //Actually ends when(UNDERNOTICE_OR_RESCISSION)
						//.endChoice() //Actually ends when(transactionRecord)
			.end() //Ends split()
			.log("Done with record :  ${body}")
			.end() // May be ends PollEnrich
	   		.log("Completed Processing of File. Sending to Success Route")        
			.to(getDirectSuccess());
			
Result :

Success Status returned : File ARRAY LIST
Times Success Route called : More than Once
Input file moved : No
Lock File Deleted : YES


Questions:
After Split the route runs to the end. What does the two end() statements
actually end in this case?
JMS reply is sent is sent to success route. No sure where the Success route
reply is going to. 
Main class is recieving the whole file array list in the response. Not sure
where this is getting returned from.			


Why is the lock file or the input file not moved to the processed directory
when done processing? What is camel actually waiting on ? 
 Here is my file endpoint : 

"file://"+getFolderLocation()+"?moveFailed=.ErroredFiles&move=.ProcessedFiles&doneFileName=${file:name.noext}.don";

Thanks !
Sri Harsha Y.


			
			
			



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-using-onException-tp5732200p5732229.html
Sent from the Camel - Users mailing list archive at Nabble.com.