Hello,

thanks for your answer. Now i understand how it works. My solution with the
bean component was the right way, but i didn't see that i have to put it
between the two components. I'll test it and if there are questions i'll
write again.

Thanks Ashwin

Cheers,
Stefan 













Ashwin Karpe wrote:
> 
> Oops, the code should be
> 
> example of this code is
> 
> import org.apache.servicemix.jbi.listener.MessageExchangeListener;
> import org.apache.servicemix.jbi.util.MessageUtil;
> 
> import javax.annotation.Resource;
> import javax.jbi.messaging.DeliveryChannel;
> import javax.jbi.messaging.ExchangeStatus;
> import javax.jbi.messaging.MessageExchange;
> import javax.jbi.messaging.MessagingException;
> 
> public class ListenerBean implements MessageExchangeListener {
> 
>     @Resource
>     private DeliveryChannel channel;
> 
>     public void onMessageExchange(MessageExchange exchange) throws
> MessagingException {
>         if (exchange.getStatus() == ExchangeStatus.ERROR) {
>              NormalizedMessage message = exchange.getMessage("in");
>              Source content = message.getContent();
>              String body = (new SourceTransformer()).toString(content);
>             
>             // ***** Write the message to a directory ****
>             channel.send(exchange);
> 
>         }
>     }
> 
> }
> 
> 
> Ashwin Karpe wrote:
>> 
>> Hi,
>> 
>> The way to do this is the following.
>> 
>>    - Create a servicemix-bean that exclusively does error handling (i.e
>> check the exchange for Exchange status to be Error/Fault) and writes the
>> message to a specific directory. The Exception handling bean will
>> typically be a pass through and only kkick in when an exceptionis
>> received in the Message Exchange
>>    - Introduce this bean between the File SU and the Transformer by
>> changing the target Service in the File SU and the Exception Handling
>> Bean
>>            File SU --> Exception Processing Bean --> Transformer
>> 
>> An example of this code is
>> 
>> import org.apache.servicemix.jbi.listener.MessageExchangeListener;
>> import org.apache.servicemix.jbi.util.MessageUtil;
>> 
>> import javax.annotation.Resource;
>> import javax.jbi.messaging.DeliveryChannel;
>> import javax.jbi.messaging.ExchangeStatus;
>> import javax.jbi.messaging.MessageExchange;
>> import javax.jbi.messaging.MessagingException;
>> 
>> public class ListenerBean implements MessageExchangeListener {
>> 
>>     @Resource
>>     private DeliveryChannel channel;
>> 
>>     public void onMessageExchange(MessageExchange exchange) throws
>> MessagingException {
>>         if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
>>              NormalizedMessage message = exchange.getMessage("in");
>>              Source content = message.getContent();
>>              String body = (new SourceTransformer()).toString(content);
>>             
>>             // ***** Write the message to a directory ****
>>             channel.send(exchange);
>> 
>>         }
>>     }
>> 
>> }
>> 
>> Hope this helps.
>> 
>> Cheers,
>> 
>> Ashwin...
>> 
>> 
>> smo001 wrote:
>>> 
>>> 
>>> Hi all,
>>> 
>>> i'v got some questions about the exchange status which is used in the
>>> Servicemix ESB.
>>> i'd like to use it to get a user defined handling if an error occurs. My
>>> projekt is a file - unit which sends the file into a pipeline. the
>>> pipeline sends it to a xslt - transformer unit which returns the
>>> transformed message back to the pipeline. 
>>> 
>>> on Success: the message will be received to a jms unit which writes the
>>> message to a messagequeue
>>> 
>>> on Error: the file shoud be moved to an other directory. 
>>> 
>>> I think, an error could only occur in the  tranformation unit if the xml
>>> document is not valid. So the component receives the exchange status =
>>> error back to the pipeline.
>>> 
>>> The Filepoller only deletes the file if it got the status done (is it
>>> write?) . Therefore i think it should be possible to add for example a
>>> bean with an own class to copy the file to an other directory, but i
>>> don't know how to implement the bean in the file component.  
>>> 
>>> Has anybody en idea how to realize it?
>>> 
>>> My filepoller is a simple one like this:
>>> <beans xmlns:f="http://servicemix.apache.org/file/1.0";
>>>        xmlns:b="http://servicemix.apache.org/OpenTransToPdf/bridge";>
>>> 
>>>   <f:poller
>>>       service="b:FilePoller"
>>>       endpoint="FilePoller"
>>>       file="file:///C:\Servicemix\inbox"
>>>       targetService="b:Pipeline"
>>>       period="30000"
>>>       recursive="true"
>>>       autoCreateDirectory="true">
>>>       
>>>       <property name="filter">
>>>             <bean
>>> class="org.apache.commons.io.filefilter.WildcardFilter">
>>>                 <constructor-arg value="*.xml" />
>>>             </bean>
>>>       </property>
>>> 
>>>        <property name="marshaler">
>>>                   <bean 
>>>                     
>>> class="org.apache.servicemix.components.util.DefaultFileMarshaler">     
>>>             </bean>
>>>       </property>
>>>       
>>>     </f:poller>
>>> 
>>> Thanks for your Help 
>>> Regards Stefan
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Exchange-Status-to-handle-Errors-tp21328296p21333331.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply via email to