You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Nav <na...@yahoo.com> on 2010/06/29 11:55:15 UTC

Error Handling problem while trying to get stack trace

HI, 
   We have a requirement that, on error in any of our routes, the error
stack trace should be emailed to the developers. I am using Camel 2.3.0. I
am not able to get the stack trace in the processor. Please let me know what
is the best way to do this . 

   I have the following common error handling route. 

         <handled> 
              <constant>true</constant> 
            </handled> 
            <process ref="errorHandler" /> 
            <convertBodyTo type="java.lang.String"  /> 
           <!--   MAIL COMPONENT HERE  --> 
          </onException> 


In the processor 'errorHandler', I am doing the following: 

public class ErrorHandler implements Processor { 
    public void process(Exchange exchange) throws Exception { 
        Exception c = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, 
                          Exception.class); 
                   exchange.getIn().setBody(c.getStackTrace()); 
    } 
} 



The result I get instead of the stack trace is : 
[Ljava.lang.StackTraceElement;@4051b1fb 
which is the object representation of the stacktrace element. 

-- 
View this message in context: http://camel.465427.n5.nabble.com/Error-Handling-problem-while-trying-to-get-stack-trace-tp511830p511830.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Error Handling problem while trying to get stack trace

Posted by Nav <na...@yahoo.com>.
Thanks. Somehow I thought it was a Camel issue but it was not.  This is how
it was fixed. 

public class ErrorHandler implements Processor {
    public void process(Exchange exchange) throws Exception {
       Exception c = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
                          Exception.class);
      exchange.getIn().setBody(getStackTrace(c));
    }


    public static String getStackTrace(Exception ex) {

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    ex.printStackTrace(pw);
    return sw.toString();
  }

}

-- 
View this message in context: http://camel.465427.n5.nabble.com/Error-Handling-problem-while-trying-to-get-stack-trace-tp511830p511842.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Error Handling problem while trying to get stack trace

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jun 29, 2010 at 11:55 AM, Nav <na...@yahoo.com> wrote:
>
> HI,
>   We have a requirement that, on error in any of our routes, the error
> stack trace should be emailed to the developers. I am using Camel 2.3.0. I
> am not able to get the stack trace in the processor. Please let me know what
> is the best way to do this .
>
>   I have the following common error handling route.
>
>         <handled>
>              <constant>true</constant>
>            </handled>
>            <process ref="errorHandler" />
>            <convertBodyTo type="java.lang.String"  />
>           <!--   MAIL COMPONENT HERE  -->
>          </onException>
>
>
> In the processor 'errorHandler', I am doing the following:
>
> public class ErrorHandler implements Processor {
>    public void process(Exchange exchange) throws Exception {
>        Exception c = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
>                          Exception.class);
>                   exchange.getIn().setBody(c.getStackTrace());
>    }
> }
>
>
>
> The result I get instead of the stack trace is :
> [Ljava.lang.StackTraceElement;@4051b1fb
> which is the object representation of the stacktrace element.
>

Google for how to retrieve the stacktrace in a human readable manner.
You need to print it to a write as far as i remember.




> --
> View this message in context: http://camel.465427.n5.nabble.com/Error-Handling-problem-while-trying-to-get-stack-trace-tp511830p511830.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus