Hi Antony,

because I can receive a message:
- in the DONE status by the previous endpoint.
- in the ERROR status (and that contains the Fault message) by the previous endpoint.

Most of the time, the previous component takes care of blocking message exchange depending of the MEP or in case of error. Nevertheless, it's safe to check the incoming exchange status before processing it.

Regards
JB

Antony Paul wrote:
I have some questions on this.
Why it is checking exchange status is active before doing anything?.
Antony


Jean-Baptiste Onofré wrote:

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();
             //process content according to your logic
             //e.g. to access the message body as a String use
             String body = (new SourceTransformer()).toString(content);
             body = MyPOJO.transform(body);
             message.setContent(new StringSource(body));
             exchange.setMessage(message, "out");
             channel.send(exchange);
         }
     }

}

This POJO is the listener one: it receives a message, extracts the content and send out (if the MEP InOut is used).

You can deploy it with the following xbean.xml:
<bean:endpoint service="MyService" endpoint="listener" bean="#myBean"/>
<bean id="myBean" class="com.my.package.Bean"/>

For the poller, you can use servicemix-quartz component to call a bean that trigger the message sending. You can define your own servicemix-quartz marshaler to define the message content. After you deploy it using a xbean.xml like this:

<quartz:endpoint service="MyService endpoint="provider" targetService="MyService" endpoint="listener">
   <quartz:jobDetail>
     <quartz:jobDetail>
       <quartz:jobDataAsMap>
         <quartz:property key="xml"><![CDATA[
           <hello>world</hello>
         ]]></quartz:property>
       </quartz:jobDataAsMap>
     </quartz:jobDetail>
   </quartz:jobDetail>
   <quartz:triggers>
     <quartz:simple repeatCount="0" repeatInterval="1000" />
     <quartz:cron cronExpression="0 * 1 * * ?" />
   </quartz:triggers>
   <quartz:marshaler>
     <bean class="org.apache.servicemix.quartz.CustomMarshaler" />
   </quartz:marshaler>
</quartz:endpoint>

Regards
JB





--
Jean-Baptiste Onofré (Nanthrax)
BuildProcess/AutoDeploy Project Leader
http://buildprocess.sourceforge.net
[email protected]
PGP : 17D4F086

Reply via email to