You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Glen Robson <gl...@llgc.org.uk> on 2010/11/26 09:48:55 UTC

Throwing exceptions from Enrichers

Hi,

I was wondering what the best way to throw an exception from an  
aggregator is so I can catch it in the camel route. Currently I have  
the following route:

<route>
             <from uri="jms:ethos_marc_loaded" />
             <bean ref="marc2marcxml" />
             <setHeader headerName="CamelHttpUri">
                 <simple>http://localhost:8888/ethos/upload/$ 
{header.llgc_ethos_oai_harvest_location}/$ 
{header.llgc_ethos_transaction_id}/mets.xml</simple>
             </setHeader>
             <enrich uri="http://localhost:8888"  
strategyRef="AddBibIdsToMETS" />
             <to uri="jms:ethos_ingest" />
</route>

<bean id="AddBibIdsToMETS"  
class="uk.org.llgc.projects.ethos.AddBibIdsToMETS" />

AddBibIdsToMETS is a custom aggregation strategy implementing the  
org.apache.camel.processor.aggregate.AggregationStrategy interface and  
it implements the following method:

Exchange aggregate(Exchange oldExchange, Exchange newExchange)
which means I can't just throw the exception from the method.

Whats the best way to get round this?

Thanks for your help

Glen 

Re: Throwing exceptions from Enrichers

Posted by Glen Robson <gl...@llgc.org.uk>.
On 26 Nov 2010, at 08:54, Claus Ibsen wrote:

> On Fri, Nov 26, 2010 at 9:48 AM, Glen Robson  
> <gl...@llgc.org.uk> wrote:
>> Hi,
>>
>> I was wondering what the best way to throw an exception from an  
>> aggregator
>> is so I can catch it in the camel route. Currently I have the  
>> following
>> route:
>>
>> <route>
>>            <from uri="jms:ethos_marc_loaded" />
>>            <bean ref="marc2marcxml" />
>>            <setHeader headerName="CamelHttpUri">
>>
>>  <simple>http://localhost:8888/ethos/upload/$ 
>> {header.llgc_ethos_oai_harvest_location}/$ 
>> {header.llgc_ethos_transaction_id}/mets.xml</simple>
>>            </setHeader>
>>            <enrich uri="http://localhost:8888"  
>> strategyRef="AddBibIdsToMETS"
>> />
>>            <to uri="jms:ethos_ingest" />
>> </route>
>>
>> <bean id="AddBibIdsToMETS"
>> class="uk.org.llgc.projects.ethos.AddBibIdsToMETS" />
>>
>> AddBibIdsToMETS is a custom aggregation strategy implementing the
>> org.apache.camel.processor.aggregate.AggregationStrategy interface  
>> and it
>> implements the following method:
>>
>> Exchange aggregate(Exchange oldExchange, Exchange newExchange)
>> which means I can't just throw the exception from the method.
>>
>> Whats the best way to get round this?
>>
>> Thanks for your help
>>
>> Glen
>
> You can throw an runtime exception or set an exception on the exchange
> you return using the setException method.

Thanks Claus using the setException method worked as I hoped.

Cheers

Glen


Re: Throwing exceptions from Enrichers

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Nov 26, 2010 at 9:48 AM, Glen Robson <gl...@llgc.org.uk> wrote:
> Hi,
>
> I was wondering what the best way to throw an exception from an aggregator
> is so I can catch it in the camel route. Currently I have the following
> route:
>
> <route>
>            <from uri="jms:ethos_marc_loaded" />
>            <bean ref="marc2marcxml" />
>            <setHeader headerName="CamelHttpUri">
>
>  <simple>http://localhost:8888/ethos/upload/${header.llgc_ethos_oai_harvest_location}/${header.llgc_ethos_transaction_id}/mets.xml</simple>
>            </setHeader>
>            <enrich uri="http://localhost:8888" strategyRef="AddBibIdsToMETS"
> />
>            <to uri="jms:ethos_ingest" />
> </route>
>
> <bean id="AddBibIdsToMETS"
> class="uk.org.llgc.projects.ethos.AddBibIdsToMETS" />
>
> AddBibIdsToMETS is a custom aggregation strategy implementing the
> org.apache.camel.processor.aggregate.AggregationStrategy interface and it
> implements the following method:
>
> Exchange aggregate(Exchange oldExchange, Exchange newExchange)
> which means I can't just throw the exception from the method.
>
> Whats the best way to get round this?
>
> Thanks for your help
>
> Glen

You can throw an runtime exception or set an exception on the exchange
you return using the setException method.




-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/