Skip to main content
Close announcements banner

Routing files conditionally to different file paths

This scenario applies only to Talend ESB, Talend Data Services Platform, Talend MDM Platform, Talend Real-Time Big Data Platform, and Talend Data Fabric.

For more technologies supported by Talend, see Talend Mediation Components.

In this scenario, three file messages containing people information are routed to different endpoints according to the city names they contain.

The following is an extract of the example XML files used in this use case:

Message_1.xml:

<person>
  <firstName>Ellen</firstName>
  <lastName>Ripley</lastName>
  <city>Washington</city>
</person>

Message_2.xml:

<person>
  <firstName>Peter</firstName>
  <lastName>Green</lastName>
  <city>London</city>
</person>

Message_3.xml:

<person>
  <firstName>Alice</firstName>
  <lastName>Yang</lastName>
  <city>Beijing</city>
</person>

A predefined JavaBean, setDynaURI, is called in this use case to return endpoint URIs according to the city name contained in each message, so that the message containing the city name Washington will be routed to endpoint Washington and so forth.

For more information about creating and using JavaBeans, see Using Beans.

package beans;

import org.apache.camel.Exchange;
import org.apache.camel.Header;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class setDynaURI {

 public String setURI(Document document,
      @Header(Exchange.SLIP_ENDPOINT) String previous) {
    if(previous!=null){
     return null;
    }
  NodeList cities = document.getDocumentElement().getElementsByTagName(
    "city");
  Element city = (Element) cities.item(0);
  String textContent = city.getTextContent();
   return "direct:"+textContent;
  } 
}

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!