You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hervé BARRAULT <he...@gmail.com> on 2012/08/17 18:20:03 UTC

ProducerTemplate and Exception Management

Hi,
I used a producer template to send a body.

I have found a method which is

void *sendBody*(String
<http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true>
endpointUri,
              Object
<http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true>
body)
              throws CamelExecutionException
<http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelExecutionException.html>

I have done some tests and only catch this exception as written in the
documentation.

But during my testing i had a configuration issue due to dynamic
endpoint and I have seen that another exception can be thrown by this
method which were not managed by the code.
The following Exception is : NoSuchEndpointException

I have seen thas this exception can be a usual error :
http://camel.apache.org/exception-orgapachecamelnosuchendpointexception.html

My question is why this exception is not intercepted by the producer
template and wrapped in a CamelExecutionException as defined in the
prototype of the method ?

I know that I am using an old version of camel (2.4.0-fuse-00-00) but
I looked to sources and the method which throws the exception has not
change since 2.4.0.

DefaultProducerTemplate.java
----------------------------------------------------------------------------------------------------
protected Endpoint resolveMandatoryEndpoint(String endpointUri) {
       Endpoint endpoint = context.getEndpoint(endpointUri);
       if (endpoint == null) {
           throw new NoSuchEndpointException(endpointUri);
       }
       return endpoint;
}
----------------------------------------------------------------------------------------------------

Could it be a good idea to wrap this exception or add it in the
documentation in order to avoid missing error cases ?

Regards
Hervé

Re: ProducerTemplate and Exception Management

Posted by Scott England-Sullivan <su...@gmail.com>.
Hi Hervé,

The two exceptions you are referring too are actually two different points
in the lifecycle of an endpoint.  The NoSuchEndpointException is an
initialization exception vs CamelExecutionException which is typically
thrown as a result of processing the exchange through a route.  Therefore
you would expect to see the NoSuchEndpointException at the invocation of
your ProducerTemplate while you would capture CamelExecutionException
events using a route exception handler.

See http://camel.apache.org/error-handling-in-camel.html and
http://camel.apache.org/exception-clause.html for further details.

Best Regards,
Scott ES

On Fri, Aug 17, 2012 at 11:20 AM, Hervé BARRAULT
<he...@gmail.com>wrote:

> Hi,
> I used a producer template to send a body.
>
> I have found a method which is
>
> void *sendBody*(String
> <
> http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true
> >
> endpointUri,
>               Object
> <
> http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true
> >
> body)
>               throws CamelExecutionException
> <
> http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelExecutionException.html
> >
>
> I have done some tests and only catch this exception as written in the
> documentation.
>
> But during my testing i had a configuration issue due to dynamic
> endpoint and I have seen that another exception can be thrown by this
> method which were not managed by the code.
> The following Exception is : NoSuchEndpointException
>
> I have seen thas this exception can be a usual error :
>
> http://camel.apache.org/exception-orgapachecamelnosuchendpointexception.html
>
> My question is why this exception is not intercepted by the producer
> template and wrapped in a CamelExecutionException as defined in the
> prototype of the method ?
>
> I know that I am using an old version of camel (2.4.0-fuse-00-00) but
> I looked to sources and the method which throws the exception has not
> change since 2.4.0.
>
> DefaultProducerTemplate.java
>
> ----------------------------------------------------------------------------------------------------
> protected Endpoint resolveMandatoryEndpoint(String endpointUri) {
>        Endpoint endpoint = context.getEndpoint(endpointUri);
>        if (endpoint == null) {
>            throw new NoSuchEndpointException(endpointUri);
>        }
>        return endpoint;
> }
>
> ----------------------------------------------------------------------------------------------------
>
> Could it be a good idea to wrap this exception or add it in the
> documentation in order to avoid missing error cases ?
>
> Regards
> Hervé
>



-- 
-- 
Scott England-Sullivan
----------------------------------
FuseSource
Web:     http://www.fusesource.com
Blog:     http://sully6768.blogspot.com
Twitter: sully6768