You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "dariusz.skrudlik" <da...@gmail.com> on 2013/08/09 16:13:49 UTC

How catch exception with endpoint was created dynamicly

I found a lot of post about that, but any working for me.

I have tested options
- throwExceptionOnConnectFailed
- consumer.bridgeErrorHandler
- pollStrategy


I have spring bean where define route:

@Service
public class MyRouteRunner {

    @Autowired
    CamelContext camelContext;

    public void startRoute( /* some arguments */) {

        route =
"ftp:username@ftp.com.pl?pollStrategy=#myPollStrategy&throwExceptionOnConnectFailed=true&consumer.bridgeErrorHandler=true";

        Exchange exchange = null;
        ConsumerTemplate consumerTemplate =
camelContext.createConsumerTemplate();

        Endpoint endpoint = camelContext.getEndpoint(route);
        consumerTemplate.start();
        exchange = consumerTemplate.receive(endpoint, 2000);

        // I NEED EXCEPTION HERE because must perform extra action depends
for argument

}

I have also own PoolStrategy bean

public class FtpConsumerPollStrategy implements PollingConsumerPollStrategy
{

 
    @Override
    public boolean rollback(Consumer consumer, Endpoint endpoint, int
retryCounter, Exception e) throws Exception {

        //HERE I GET EXCEPTION but any code don't propagate exception to
main bean
//1
// throw e; // this should work

//2
//        Exchange exchange = endpoint.createExchange();
//        exchange.setException(e);
//       ((FtpConsumer)consumer).getProcessor().process(exchange);

        return false;
    }
}

Generally when all is ok and file on server exists I receive it, but when
exception occurs then I cann't perform any  action.
How can I handle exception where I need it ?




--
View this message in context: http://camel.465427.n5.nabble.com/How-catch-exception-with-endpoint-was-created-dynamicly-tp5737037.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How catch exception from endpoint which was created in code

Posted by ReDiya <su...@gmail.com>.
dariusz.skrudlik, 

Did you find a way to return the Exception back to the bean ? Please share
the same. 

regards
ReDiya



--
View this message in context: http://camel.465427.n5.nabble.com/How-catch-exception-from-endpoint-which-was-created-in-code-tp5737037p5757202.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How catch exception with endpoint was created dynamicly

Posted by Łukasz Dywicki <lu...@code-house.org>.
Hey Dariusz,
According to javadoc on PollingConsumerPollStrategy.rollback() throwing exception from this method have side effect and in general is used to hold scheduler.

You probably did that already, but having debug or trace logging helps a little bit. Also going with debugger may be helpful for you.

In General you may also try to add new route definition to Camel Context. This rute will be fully functional and let you use normal error handling you have. Routes may be stopped and removed dynamically. So maybe you could try doing that?

Some working code examples you may find in SwitchYard project [1].

[1] https://github.com/jboss-switchyard/core/blob/master/bus/camel/src/main/java/org/switchyard/bus/camel/CamelExchangeBus.java#L97

Cheers,
Łukasz Dywicki
--
luke@code-house.org
Twitter: ldywicki
Blog: http://dywicki.pl
Code-House - http://code-house.org

Wiadomość napisana przez dariusz.skrudlik <da...@gmail.com> w dniu 9 sie 2013, o godz. 16:13:

> I found a lot of post about that, but any working for me.
> 
> I have tested options
> - throwExceptionOnConnectFailed
> - consumer.bridgeErrorHandler
> - pollStrategy
> 
> 
> I have spring bean where define route:
> 
> @Service
> public class MyRouteRunner {
> 
>    @Autowired
>    CamelContext camelContext;
> 
>    public void startRoute( /* some arguments */) {
> 
>        route =
> "ftp:username@ftp.com.pl?pollStrategy=#myPollStrategy&throwExceptionOnConnectFailed=true&consumer.bridgeErrorHandler=true";
> 
>        Exchange exchange = null;
>        ConsumerTemplate consumerTemplate =
> camelContext.createConsumerTemplate();
> 
>        Endpoint endpoint = camelContext.getEndpoint(route);
>        consumerTemplate.start();
>        exchange = consumerTemplate.receive(endpoint, 2000);
> 
>        // I NEED EXCEPTION HERE because must perform extra action depends
> for argument
> 
> }
> 
> I have also own PoolStrategy bean
> 
> public class FtpConsumerPollStrategy implements PollingConsumerPollStrategy
> {
> 
> 
>    @Override
>    public boolean rollback(Consumer consumer, Endpoint endpoint, int
> retryCounter, Exception e) throws Exception {
> 
>        //HERE I GET EXCEPTION but any code don't propagate exception to
> main bean
> //1
> // throw e; // this should work
> 
> //2
> //        Exchange exchange = endpoint.createExchange();
> //        exchange.setException(e);
> //       ((FtpConsumer)consumer).getProcessor().process(exchange);
> 
>        return false;
>    }
> }
> 
> Generally when all is ok and file on server exists I receive it, but when
> exception occurs then I cann't perform any  action.
> How can I handle exception where I need it ?
> 
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-catch-exception-with-endpoint-was-created-dynamicly-tp5737037.html
> Sent from the Camel - Users mailing list archive at Nabble.com.