Versions Compared

Key

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

...

Code Block
/**
 * a processor used to validate the message
 */
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!");
        }
    }
}
{code]
h3. Register the processor
We can register the processor in the spring context in two steps.
* add a component-scan package in the 

Register the processor

We can register the processor in the spring context in two steps.

  • add a component-scan package in the Applicatioin-Context.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!");
            }
        }
    }
    

    Use Content Based Router to orchestrate the processors

...