Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • add a component-scan package in the Applicatioin-ContextapplicationContext.xml:
    Code Block
    xml
    xml
    <!-- configure the spring component scan package -->
    <context:component-scan base-package="org.apache.camel.web.example"/>
    
  • annotate the processor by adding one line code in the processor. Now the processor is as follows:
    Code Block
    package org.apache.camel.web.example;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.apache.camel.Exchange;
    import org.apache.camel.Processor;
    import org.apache.camel.ValidationException;
    import org.springframework.stereotype.Service;
    
    /**
     * a processor used to validate the message
     */
    @Service(value = "validatingProcessor")
    public class ValidatingProcessor implements Processor {
        public void process(Exchange exchange) throws Exception {
            Object value = exchange.getIn().getHeader("expiredDate");
            SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
            Date expiredDate = sdf.parse((String)value);
            if (new Date().after(expiredDate)) {
                throw new ValidationException(exchange, "The message has been expired!");
            }
        }
    }
    

Now you can run the sample, but it won't do the validation because we haven't configured the route to pass through the processor. You can complete it by editing the applicationContext.xml before running it, but now we want to show you how to do it through Web Console.

Use Content Based Router to orchestrate the processors

We should execute the validation before processing the message, so we edit the route1 as follows:

Code Block

from("file:src/data?noop=true").convertBodyTo(java.lang.String.class)
.processRef("validatingProcessor").to("stream:out").to("activemq:personnel.records")

Source code