2012-01-19 14:38:44 +00:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2011-05-23 11:37:56 -04:00
|
|
|
package akka.camel;
|
|
|
|
|
|
2012-05-11 09:46:49 +02:00
|
|
|
import akka.actor.Status;
|
2012-01-19 14:38:44 +00:00
|
|
|
import akka.camel.javaapi.UntypedConsumerActor;
|
|
|
|
|
import akka.util.Duration;
|
2011-05-23 11:37:56 -04:00
|
|
|
import org.apache.camel.builder.Builder;
|
|
|
|
|
import org.apache.camel.model.ProcessorDefinition;
|
|
|
|
|
import org.apache.camel.model.RouteDefinition;
|
2012-01-19 14:38:44 +00:00
|
|
|
import scala.Option;
|
2011-05-23 11:37:56 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Martin Krasser
|
|
|
|
|
*/
|
|
|
|
|
public class SampleErrorHandlingConsumer extends UntypedConsumerActor {
|
|
|
|
|
|
|
|
|
|
public String getEndpointUri() {
|
|
|
|
|
return "direct:error-handler-test-java";
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 14:38:44 +00:00
|
|
|
@Override
|
|
|
|
|
//TODO write test confirming this gets called in java
|
|
|
|
|
public ProcessorDefinition onRouteDefinition(RouteDefinition rd) {
|
|
|
|
|
return rd.onException(Exception.class).handled(true).transform(Builder.exceptionMessage()).end();
|
2011-05-23 11:37:56 -04:00
|
|
|
}
|
|
|
|
|
|
2012-01-19 14:38:44 +00:00
|
|
|
@Override
|
|
|
|
|
public Duration replyTimeout(){
|
|
|
|
|
return Duration.create(1, "second");
|
2011-05-23 11:37:56 -04:00
|
|
|
}
|
|
|
|
|
|
2012-01-19 14:38:44 +00:00
|
|
|
|
|
|
|
|
|
2011-05-23 11:37:56 -04:00
|
|
|
public void onReceive(Object message) throws Exception {
|
2012-03-01 17:32:10 +01:00
|
|
|
CamelMessage msg = (CamelMessage) message;
|
|
|
|
|
String body = msg.getBodyAs(String.class,this.getCamelContext());
|
2011-05-23 11:37:56 -04:00
|
|
|
throw new Exception(String.format("error: %s", body));
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void preRestart(Throwable reason, Option<Object> message){
|
2012-05-11 09:46:49 +02:00
|
|
|
getSender().tell(new Status.Failure(reason));
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
2011-05-23 11:37:56 -04:00
|
|
|
|
|
|
|
|
}
|