Hopefully, this isn't too much of a newbie question. I tried finding an
answer by searching the forums but had no luck.
I created a simple route that contains a bean component that throws an
exception. I'm calling the route synchronously (ExchangePattern.InOut) using
CamelTemplate.sendBody. I was hoping that the call to sendBody would throw
an exception (hopefully one that contained details of the exception thrown
by the bean). Instead, it simply returns the original request object passed.
I'm aware that exceptions can be handled using an errorHandler and/or the
exception clause. But I wasn't sure how to use either to preserve the
original exception and return it to the caller synchronously. I was hoping
there was a fairly easy way to accomplish this.
I noticed in CamelCxfExample sample, calling the pingMe throws an exception
as I would expect. I was wondering about this apparent inconsistency between
calling a web service and calling a bean.
Below is some code that exemplifies the problem.
----------------------------------------
package biz.firethorn.interfaces;
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelTemplate;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.processor.SendProcessor;
public final class ExceptionTest {
public static void main(String args[]) throws Exception {
CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory = new
ActiveMQConnectionFactory(
"vm://localhost?broker.persistent=false");
context.addComponent("activemq", ActiveMQComponent
.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new RouteBuilder() {
public void configure() {
from("activemq:queue:input").bean(new
ExceptionBean());
}
});
CamelTemplate template = new CamelTemplate(context);
context.start();
try {
int result = (Integer)
template.sendBody("activemq:queue:input",
ExchangePattern.InOut, "Hello");
System.out.println("result = " + result);
}
catch (Exception e) {
System.out.println("Exception caught! e.message = " +
e.toString());
}
finally {
context.stop();
}
}
public static class ExceptionBean {
public int doSomething(String request) throws Exception {
//return 1;
throw new Exception("Ouch!");
}
}
}
-------------------------------
Thanks in advance for the help!
--
View this message in context:
http://www.nabble.com/Handling-Bean-exceptions-tp17671948s22882p17671948.html
Sent from the Camel - Users mailing list archive at Nabble.com.