You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by focaldi <fe...@tav.aero> on 2011/12/06 07:34:10 UTC

How can I handle exception message?

Hi,

I want to do some special thing according to Exception Type. But there are a
lot of route and when an exeption occured I send the message to deadletter
queue.

        errorHandler(
        		deadLetterChannel("jms:queue:deadletterqueue")
        );

I wrote a class for deadletterchannel processor.

@Component("ProcessorForSendingEmail") 
public class ProcessorForSendingEmail implements Processor {

	@Override
	public void process(Exchange exchange) {
		
		System.out.println("HATAAAAAAAAAA :"+exchange.getOut().isFault());
		System.out.println("YYYYYYYYYYYYY
:"+exchange.getOut().getHeader(Exchange.EXCEPTION_CAUGHT));
		System.out.println("FFFFFFFFFFFFF :"+exchange.getException());
		System.out.println("HATAAAAAAAAAA :"+exchange.getIn().isFault());
		System.out.println("YYYYYYYYYYYYY
:"+exchange.getIn().getHeader(Exchange.EXCEPTION_CAUGHT));

	}

}


But all of them is null... I need to write Exception Message... How can I
reach exception message in Dead Queue. Thanks...
 

--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-handle-exception-message-tp5051151p5051151.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I handle exception message?

Posted by focaldi <fe...@tav.aero>.
Thanks Willem I used "seda:error" for deadletterurl and it works. Thanks for
your help Willem and Claus...

--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-handle-exception-message-tp5051151p5051307.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I handle exception message?

Posted by Willem Jiang <wi...@gmail.com>.
You are using the jms endpoint to receive the message, you need to 
enable the transferExchange option and make sure your exceptions are 
serializable.

On Tue Dec  6 15:25:42 2011, focaldi wrote:
> Thanks my friends, but it didnt work :(
>
> In my main classs :
> ...
> camelContext.setHandleFault(true);
> ...
>
> My Dead Letter Queue URL :
>
> jms:queue:deadletterqueue
>
>
> Dead Letter Queueu Processor :
> from("jms:queue:deadletterqueue").process(new ProcessorForSendingEmail ());
>
> Processor class for deadletterqueue :
>
> @Component("ProcessorForSendingEmail")
> public class ProcessorForSendingEmail implements Processor {
>
> 	@Override
> 	public void process(Exchange exchange) {		
> 		Throwable exception =
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT,Throwable.class);
> 		System.out.println("HATAAAAAAAAAA :"+exception);		
> 	}
>
> }
>
> For test I throw an exception from a proccessor :
>
> @Component("Test3")
> public class Test3 implements Processor {
> 	
> 	@Override
> 	public void process(Exchange exchange) throws Exception {
> 		if (1==1) throw new Exception("BENDEEEEEEEEEE");
> 		exchange.getIn().setHeader("IB.messageName", "rmsPlstAssign");
> 	}
>
> }
>
> Result : HATAAAAAAAAAA :null
>
> I NEED EXCEPTION MESSAGE... Please help me :(
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-can-I-handle-exception-message-tp5051151p5051266.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Re: How can I handle exception message?

Posted by Claus Ibsen <cl...@gmail.com>.
If you use a JMS destination as dead letter channel, then it only
stores the message. Not the stacktrace.

If you want to include the stacktrace, you will have to put that into
the message as a header yourself, and ensure the value of the header
is valid according to the JMS spec, such as a java.lang.String type.

See the JMS wiki page for details about mapping to/from JMS.


On Tue, Dec 6, 2011 at 8:25 AM, focaldi <fe...@tav.aero> wrote:
> Thanks my friends, but it didnt work :(
>
> In my main classs :
> ...
> camelContext.setHandleFault(true);
> ...
>
> My Dead Letter Queue URL :
>
> jms:queue:deadletterqueue
>
>
> Dead Letter Queueu Processor :
> from("jms:queue:deadletterqueue").process(new ProcessorForSendingEmail ());
>
> Processor class for deadletterqueue :
>
> @Component("ProcessorForSendingEmail")
> public class ProcessorForSendingEmail implements Processor {
>
>        @Override
>        public void process(Exchange exchange) {
>                Throwable exception =
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT,Throwable.class);
>                System.out.println("HATAAAAAAAAAA :"+exception);
>        }
>
> }
>
> For test I throw an exception from a proccessor :
>
> @Component("Test3")
> public class Test3 implements Processor {
>
>        @Override
>        public void process(Exchange exchange) throws Exception {
>                if (1==1) throw new Exception("BENDEEEEEEEEEE");
>                exchange.getIn().setHeader("IB.messageName", "rmsPlstAssign");
>        }
>
> }
>
> Result : HATAAAAAAAAAA :null
>
> I NEED EXCEPTION MESSAGE... Please help me :(
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-can-I-handle-exception-message-tp5051151p5051266.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: How can I handle exception message?

Posted by focaldi <fe...@tav.aero>.
Thanks my friends, but it didnt work :(

In my main classs : 
...
camelContext.setHandleFault(true);
...

My Dead Letter Queue URL : 

jms:queue:deadletterqueue


Dead Letter Queueu Processor :
from("jms:queue:deadletterqueue").process(new ProcessorForSendingEmail ());

Processor class for deadletterqueue : 

@Component("ProcessorForSendingEmail") 
public class ProcessorForSendingEmail implements Processor {

	@Override
	public void process(Exchange exchange) {		
		Throwable exception =
exchange.getProperty(Exchange.EXCEPTION_CAUGHT,Throwable.class);
		System.out.println("HATAAAAAAAAAA :"+exception);		
	}

}

For test I throw an exception from a proccessor : 

@Component("Test3") 
public class Test3 implements Processor {
	
	@Override
	public void process(Exchange exchange) throws Exception {
		if (1==1) throw new Exception("BENDEEEEEEEEEE");
		exchange.getIn().setHeader("IB.messageName", "rmsPlstAssign");
	}

}

Result : HATAAAAAAAAAA :null

I NEED EXCEPTION MESSAGE... Please help me :(

--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-handle-exception-message-tp5051151p5051266.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I handle exception message?

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

The exception is stored in the properties of exchange.
You can get it by using below code

Throwable exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, 
Throwable.class);

On Tue Dec  6 14:34:10 2011, focaldi wrote:
> Hi,
>
> I want to do some special thing according to Exception Type. But there are a
> lot of route and when an exeption occured I send the message to deadletter
> queue.
>
>          errorHandler(
>          		deadLetterChannel("jms:queue:deadletterqueue")
>          );
>
> I wrote a class for deadletterchannel processor.
>
> @Component("ProcessorForSendingEmail")
> public class ProcessorForSendingEmail implements Processor {
>
> 	@Override
> 	public void process(Exchange exchange) {
> 		
> 		System.out.println("HATAAAAAAAAAA :"+exchange.getOut().isFault());
> 		System.out.println("YYYYYYYYYYYYY
> :"+exchange.getOut().getHeader(Exchange.EXCEPTION_CAUGHT));
> 		System.out.println("FFFFFFFFFFFFF :"+exchange.getException());
> 		System.out.println("HATAAAAAAAAAA :"+exchange.getIn().isFault());
> 		System.out.println("YYYYYYYYYYYYY
> :"+exchange.getIn().getHeader(Exchange.EXCEPTION_CAUGHT));
>
> 	}
>
> }
>
>
> But all of them is null... I need to write Exception Message... How can I
> reach exception message in Dead Queue. Thanks...
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-can-I-handle-exception-message-tp5051151p5051151.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Re: How can I handle exception message?

Posted by Claus Ibsen <cl...@gmail.com>.
Use exchange.getIn() to access the message.



On Tue, Dec 6, 2011 at 7:34 AM, focaldi <fe...@tav.aero> wrote:
> Hi,
>
> I want to do some special thing according to Exception Type. But there are a
> lot of route and when an exeption occured I send the message to deadletter
> queue.
>
>        errorHandler(
>                        deadLetterChannel("jms:queue:deadletterqueue")
>        );
>
> I wrote a class for deadletterchannel processor.
>
> @Component("ProcessorForSendingEmail")
> public class ProcessorForSendingEmail implements Processor {
>
>        @Override
>        public void process(Exchange exchange) {
>
>                System.out.println("HATAAAAAAAAAA :"+exchange.getOut().isFault());
>                System.out.println("YYYYYYYYYYYYY
> :"+exchange.getOut().getHeader(Exchange.EXCEPTION_CAUGHT));
>                System.out.println("FFFFFFFFFFFFF :"+exchange.getException());
>                System.out.println("HATAAAAAAAAAA :"+exchange.getIn().isFault());
>                System.out.println("YYYYYYYYYYYYY
> :"+exchange.getIn().getHeader(Exchange.EXCEPTION_CAUGHT));
>
>        }
>
> }
>
>
> But all of them is null... I need to write Exception Message... How can I
> reach exception message in Dead Queue. Thanks...
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-can-I-handle-exception-message-tp5051151p5051151.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/