You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by cmdr <sp...@yahoo.fr> on 2008/02/28 17:35:09 UTC

exception trace in message

Hi

I would like to send messages with exception trace

exception(Exception.class).to("activemq:queue:Exception");

from(XXX)
.process(new Processor()
{
   public void process(Exchange exchange) throws Exception 
   {
      throw new Exception("Processing Exception");
   }
})
.to(XXX)

I would like the activemq message to contain the exception message

cmdr
-- 
View this message in context: http://www.nabble.com/exception-trace-in-message-tp15740418s22882p15740418.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: exception trace in message

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

I do think we should pick this issue up when Camel 1.4 has been released hopefully in next week. Then we have time to discus and find a solution to this for the next release.

Could you create a JIRA ticket with this issue with a layout of the problem and some links to the user forum (from nabble etc.) to your requests etc.

When the ticket is in JIRA it is not forgotten (maybe there is at ticket for this already, please check).

When an exception is sent over the wire with JMS then the consumer/producer can have different jar libraries and thus the exception on the remote site can not be marshaled. At least I see a point in adding a header (if not 
already there) with a string property of the original exception name - eg. 

originalExceptionClassName=com.mycompany.business.CustomerDoesNotExistsException


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: jaco.uys [mailto:jaco.uys@gmail.com] 
Sent: 23. juni 2008 22:12
To: camel-user@activemq.apache.org
Subject: Re: exception trace in message


Hi,

Is there any resolution to this issue?

I am using the deadletterchannel to handle any exceptions, but so far unable
to set the original exception on the resulting message that is send to a
queue.

Regards Jaco
-- 
View this message in context: http://www.nabble.com/exception-trace-in-message-tp15740418s22882p18077402.html
Sent from the Camel - Users mailing list archive at Nabble.com.



Re: exception trace in message

Posted by "jaco.uys" <ja...@gmail.com>.
Hi,

Is there any resolution to this issue?

I am using the deadletterchannel to handle any exceptions, but so far unable
to set the original exception on the resulting message that is send to a
queue.

Regards Jaco
-- 
View this message in context: http://www.nabble.com/exception-trace-in-message-tp15740418s22882p18077402.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: exception trace in message

Posted by Gary Tully <ga...@gmail.com>.
I think the closest test to what you want is at
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java?view=markup

as you say, there is no reference to the exception but it is on the
exchange when it is handled.

adding:
assertTrue("Handled exception available on exchange",
                exceptionEndpoint.getExchanges().get(0).getException()
instanceof IllegalArgumentException);
to the end of the testExceptionWithHandler() case will verify that the
exception is accessible.

The EXCEPTION_CAUSE_PROPERTY could/should used to hold the exception
as a property of the exchange while it is begin handled such that
another pipe/route can be used to handle the exception reporting and
it can fail independently.

But it looks like this is not correctly implemented or is not the
intended behaviour. In a test I find that another private property is
used to hold the exception during processing:

In a processor placed in the handier chain for an exception I find
that the following works:

{code}
final Processor exceptionStackTraceHandler = new Processor() {
            public void process(Exchange exchange) throws Exception {
                assertNull("no ex on exchange in handler",
exchange.getException());
                //a public accessor property should be there
                //Throwable ex = (Throwable)
exchange.getProperty(DeadLetterChannel.EXCEPTION_CAUSE_PROPERTY);
                Throwable ex = (Throwable)
exchange.getProperty("org.apache.camel.processor.DeadLetterChannel.FAILURE_HANDLED");
                exchange.getIn().setHeader("my.stackTrace", stackToString(ex));
            }
{code}


>From what I understand, the exception handler are another form of
error handler, so if no exception error handler matches, the default
dead letter error handler is in effect.

The exception cause should be easily available through a property,
either the existing public property should be used or the private
property should be made public. I think this warrants a jira.


On 10/03/2008, Magnus Heino <ma...@filur.org> wrote:
> Did anyone come up with a working solution for this?
>
>  DeadLetterChannel.EXCEPTION_CAUSE_PROPERTY is not used or tested anywhere.
>  And even if that was not the case, dead letter channel isn't the same as
>  exception() and tryBlock(), right?
>
>  I also looked through all the
>  org.apache.camel.processor.Validation*Testtests, but none of them
>  expose or use the actual exception.
>
>  Is this possible? It seems weird to have a xml schema validation component
>  if it's impossible to get hold of the actual error message...
>
>  /Magnus
>
>
>  On Fri, Feb 29, 2008 at 5:39 PM, cmdr <sp...@yahoo.fr> wrote:
>
>  >
>  > Here is an example of code that work as I aspected.:-(
>  > Here is an example of code that works as I wanted.
>  > I fail to get the exception using setHeader("exception",
>  > header("CamelCauseException")).
>  > Can you provide a piece of code?
>  >
>  > When should we use exchange.getIn().setBody() or
>  > exchange.getOut().setBody()?
>  >
>  >
>  > public class ExceptionTest extends ContextTestSupport
>  > {
>  >        MockEndpoint endEndpoint;
>  >
>  >        @Override
>  >        protected void setUp() throws Exception
>  >        {
>  >                super.setUp();
>  >                endEndpoint = getMockEndpoint("mock:end");
>  >        }
>  >
>  >        @Override
>  >        protected RouteBuilder createRouteBuilder() throws Exception
>  >        {
>  >                return new RouteBuilder()
>  >                {
>  >                        @Override
>  >                        public void configure() throws Exception
>  >                        {
>  >                                from("direct:start").process
>  >                                 (       new Processor()
>  >                                        {
>  >                                                public void
>  > process(Exchange exchange) throws Exception
>  >                                                {
>  >                                                         try
>  >                                                        {
>  >                                                                throw new
>  > Exception("Test exception");
>  >                                                        }
>  >                                                        catch (Exception e)
>  >                                                        {
>  >
>  >  StringWriter stringWritter = new StringWriter();
>  >                                                                PrintWriter
>  > printWritter = new PrintWriter(stringWritter, true);
>  >
>  > e.printStackTrace(printWritter);
>  >
>  > printWritter.flush();
>  >
>  > stringWritter.flush();
>  >
>  >
>  > exchange.getIn().setBody(stringWritter.toString());
>  >
>  >
>  > template.send("activemq:queue:Exception", exchange);
>  >                                                        }
>  >                                                }
>  >                                        }
>  >                                );
>  >                        }
>  >                };
>  >        }
>  >
>  >        public void testException() throws InterruptedException
>  >        {
>  >                endEndpoint.expectedMessageCount(1);
>  >
>  >                template.sendBody("direct:start", "test Exception");
>  >
>  >                MockEndpoint.assertIsSatisfied(endEndpoint);
>  >        }
>  > }
>  >
>  > --
>  > View this message in context:
>  > http://www.nabble.com/exception-trace-in-message-tp15740418s22882p15762404.html
>  > Sent from the Camel - Users mailing list archive at Nabble.com.
>  >
>  >
>
>
>
> --
>
>
>   /Magnus Heino
>

Re: exception trace in message

Posted by Magnus Heino <ma...@filur.org>.
Did anyone come up with a working solution for this?

DeadLetterChannel.EXCEPTION_CAUSE_PROPERTY is not used or tested anywhere.
And even if that was not the case, dead letter channel isn't the same as
exception() and tryBlock(), right?

I also looked through all the
org.apache.camel.processor.Validation*Testtests, but none of them
expose or use the actual exception.

Is this possible? It seems weird to have a xml schema validation component
if it's impossible to get hold of the actual error message...

/Magnus

On Fri, Feb 29, 2008 at 5:39 PM, cmdr <sp...@yahoo.fr> wrote:

>
> Here is an example of code that work as I aspected.:-(
> Here is an example of code that works as I wanted.
> I fail to get the exception using setHeader("exception",
> header("CamelCauseException")).
> Can you provide a piece of code?
>
> When should we use exchange.getIn().setBody() or
> exchange.getOut().setBody()?
>
>
> public class ExceptionTest extends ContextTestSupport
> {
>        MockEndpoint endEndpoint;
>
>        @Override
>        protected void setUp() throws Exception
>        {
>                super.setUp();
>                endEndpoint = getMockEndpoint("mock:end");
>        }
>
>        @Override
>        protected RouteBuilder createRouteBuilder() throws Exception
>        {
>                return new RouteBuilder()
>                {
>                        @Override
>                        public void configure() throws Exception
>                        {
>                                from("direct:start").process
>                                 (       new Processor()
>                                        {
>                                                public void
> process(Exchange exchange) throws Exception
>                                                {
>                                                         try
>                                                        {
>                                                                throw new
> Exception("Test exception");
>                                                        }
>                                                        catch (Exception e)
>                                                        {
>
>  StringWriter stringWritter = new StringWriter();
>                                                                PrintWriter
> printWritter = new PrintWriter(stringWritter, true);
>
> e.printStackTrace(printWritter);
>
> printWritter.flush();
>
> stringWritter.flush();
>
>
> exchange.getIn().setBody(stringWritter.toString());
>
>
> template.send("activemq:queue:Exception", exchange);
>                                                        }
>                                                }
>                                        }
>                                );
>                        }
>                };
>        }
>
>        public void testException() throws InterruptedException
>        {
>                endEndpoint.expectedMessageCount(1);
>
>                template.sendBody("direct:start", "test Exception");
>
>                MockEndpoint.assertIsSatisfied(endEndpoint);
>        }
> }
>
> --
> View this message in context:
> http://www.nabble.com/exception-trace-in-message-tp15740418s22882p15762404.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>


-- 

 /Magnus Heino

Re: exception trace in message

Posted by cmdr <sp...@yahoo.fr>.
Here is an example of code that work as I aspected.:-(
Here is an example of code that works as I wanted.
I fail to get the exception using setHeader("exception",
header("CamelCauseException")).
Can you provide a piece of code?

When should we use exchange.getIn().setBody() or
exchange.getOut().setBody()?


public class ExceptionTest extends ContextTestSupport 
{
	MockEndpoint endEndpoint;

	@Override
	protected void setUp() throws Exception 
	{
		super.setUp();
		endEndpoint = getMockEndpoint("mock:end");
	}

	@Override
	protected RouteBuilder createRouteBuilder() throws Exception 
	{
		return new RouteBuilder() 
		{
			@Override
			public void configure() throws Exception 
			{
				from("direct:start").process
				(	new Processor()
					{
						public void process(Exchange exchange) throws Exception 
						{
							try
							{
								throw new Exception("Test exception");
							}
							catch (Exception e) 
							{
								StringWriter stringWritter = new StringWriter();
								PrintWriter printWritter = new PrintWriter(stringWritter, true);
								e.printStackTrace(printWritter);
								printWritter.flush();
								stringWritter.flush();
								
								exchange.getIn().setBody(stringWritter.toString());
								
								template.send("activemq:queue:Exception", exchange);
							} 
						}
					}
				);
			}
		};
	}

	public void testException() throws InterruptedException 
	{
		endEndpoint.expectedMessageCount(1);
		
		template.sendBody("direct:start", "test Exception");
		
		MockEndpoint.assertIsSatisfied(endEndpoint);
	}
}

-- 
View this message in context: http://www.nabble.com/exception-trace-in-message-tp15740418s22882p15762404.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: exception trace in message

Posted by James Strachan <ja...@gmail.com>.
On 28/02/2008, Roman Kalukiewicz <ro...@gmail.com> wrote:
> 2008/2/28, cmdr <sp...@yahoo.fr>:
>  >
>  >  Hi
>
>  Hello!
>
>
>  >  I would like to send messages with exception trace
>  >
>  >  exception(Exception.class).to("activemq:queue:Exception");
>  >
>  >  from(XXX)
>  >  .process(new Processor()
>  >  {
>  >    public void process(Exchange exchange) throws Exception
>  >    {
>  >       throw new Exception("Processing Exception");
>  >    }
>  >  })
>  >  .to(XXX)
>  >
>  >  I would like the activemq message to contain the exception message
>
>
> It looks that this exception is already associated with the exchange
>  as a property named 'CamelCauseException'.
>  What I think you should try, is to add
>
>  .setHeader("exception", header("CamelCauseException"))
>
>  to your exception handlig flow, so it will be used as an 'exception'
>  property on JMS message. If it doesn't work you can try to explicitely
>  use processor to extract the stacktrace from the exception.
>
>  BTW. Maybe we could have converter toString(Throwable) to make it easier?

Good idea!
-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: exception trace in message

Posted by Roman Kalukiewicz <ro...@gmail.com>.
2008/2/28, cmdr <sp...@yahoo.fr>:
>
>  Hi

Hello!

>  I would like to send messages with exception trace
>
>  exception(Exception.class).to("activemq:queue:Exception");
>
>  from(XXX)
>  .process(new Processor()
>  {
>    public void process(Exchange exchange) throws Exception
>    {
>       throw new Exception("Processing Exception");
>    }
>  })
>  .to(XXX)
>
>  I would like the activemq message to contain the exception message

It looks that this exception is already associated with the exchange
as a property named 'CamelCauseException'.
What I think you should try, is to add

.setHeader("exception", header("CamelCauseException"))

to your exception handlig flow, so it will be used as an 'exception'
property on JMS message. If it doesn't work you can try to explicitely
use processor to extract the stacktrace from the exception.

BTW. Maybe we could have converter toString(Throwable) to make it easier?

Roman