Hi You can use predicates to do type safe CBR http://davsclaus.blogspot.com/2009/02/apache-camel-and-using-compound.html
>From the Predicate you get access to Exchange which means you can get the body/headers etc. You can also use some of the scripting languages to do it in the DSL directly http://camel.apache.org/languages.html In Camel 2.3 onwards you can use the simple language which can check for type instances and has a OGNL like feature http://camel.apache.org/simple.html On Sun, May 2, 2010 at 4:26 PM, Mattias Severson <[email protected]> wrote: > > Hi, > > I have a configuration object, that contains many nested pojos, e.g: > > public class Configuration { > private OutputConfiguration outputConfiguration; > // More members... > > public OutputConfiguration getOutputConfiguration() { > return outputConfiguration; > } > > // Getters and setters... > } > > public class OutputConfiguration { > private FileFormat fileFormat; > private EnumSet<DeliveryMethod> deliveryMethod; > private EmailAddress emailAddress; > private FtpConfiguration ftpConfiguration; > > public FileFormat getFileFormat() { > return fileFormat; > } > > // More getters and setters... > } > > public enum FileFormat { > CHARACTER_SEPARATED, > FIXED_LENGTH, > XML > } > > > Depending on the file format, I would like to route my messages to different > Processors. They will in turn construct different files, that will be sent > to one or more remote clients. The method of transport will be depending on > the delivery method and its corresponding settings. > > Given that the message contains the Configuration message, I would like > type-safe routing (there are a lot configuration options and manual > conversion to a key-value map will be error prone and bad from a maintenance > point of view). > > > Now the questions: > > 1. Do I better place the Configuration object in the Body or in the Header > (considering that I in the latter half of the process chain intend to add > the generated files to the Body)? > > 2. Depending on the answer of the first question, how can I write a type > safe choice()-statement? Ideally, I would like something like > > from(direct:origin).choice() > ...((Configuration)configuration).getOutputConfiguration().getFileFormat().isEqualsTo(FileFormat.CHARACTER_SEPARATED) > .to(direct:char_separated) > > Alternatively using a bean > > from(direct:origin).choice() > .when(bean(FileFormatExtractor.class, > "getFileType").isEqualTo(FileType.CHARACTER_SEPARATED)) > .to(direct:char_separated); > > Where the FileFormatExtractor is something like > > public class FileFormatExtractor { > > public FileFormat getFileFormat() { > // How can I access the configuration instance here? > return configuration.getOutputConfiguration().getFileFormat(); > } > } > > > > Thanks in advance, > > Mattias > -- > View this message in context: > http://old.nabble.com/Java-DSL-routing-according-to-hierarchical-pojo-configuration-object--tp28427245p28427245.html > Sent from the Camel - Users mailing list archive at Nabble.com. > > -- Claus Ibsen Apache Camel Committer Author of Camel in Action: http://www.manning.com/ibsen/ Open Source Integration: http://fusesource.com Blog: http://davsclaus.blogspot.com/ Twitter: http://twitter.com/davsclaus
