0

I am developing a simple processor to verify the existence of mandatory properties in a route. I need to add that list on the route definition before calling the processor.

    <route id="test1">
        <from uri="/v1/test1" />
        <setProperty propertyName="mandatoryProperties">
            <simple resultType="java.util.List">${[A,B,C]}</simple>
        </setProperty>
        <bean ref="propertiesProcessor" />
    </route>

My Processor is:

@Component
public class MandatoryPropertiesProcessor {

@Handler
public void process(final Exchange exchange, final @Properties Map properties, final @ExchangeProperty("mandatoryProperties") List<String> mandatoryProperties) {

    List<String> missingPropertiesList = new ArrayList<>();

    if (!CollectionUtils.isEmpty(mandatoryProperties)) {

        for (String mandatoryProperty : mandatoryProperties) {

            if (!properties.containsKey(mandatoryProperty)) {
                missingPropertiesList.add(mandatoryProperty);
            }
        }
    }

    exchange.setProperty(MISSING_PROPERTIES, missingPropertiesList);
}

}

when i try to call this route i get:

Caused by: org.apache.camel.language.simple.types.SimpleParserException: Unknown function: ["A","B","C"]
    at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createSimpleExpression(SimpleFunctionExpression.java:216)
    at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createExpression(SimpleFunctionExpression.java:40)
    at org.apache.camel.language.simple.ast.SimpleFunctionStart.doCreateLiteralExpression(SimpleFunctionStart.java:58)
    at org.apache.camel.language.simple.ast.SimpleFunctionStart.createExpression(SimpleFunctionStart.java:48)
    at org.apache.camel.language.simple.SimpleExpressionParser.createExpressions(SimpleExpressionParser.java:163)
    at org.apache.camel.language.simple.SimpleExpressionParser.doParseExpression(SimpleExpressionParser.java:86)
    at org.apache.camel.language.simple.SimpleExpressionParser.parseExpression(SimpleExpressionParser.java:53)

Is possible to achieve this in XML?

João Gomes
  • 332
  • 4
  • 15

1 Answers1

0

You seem to use Spring Framework and the mandatory properties seem to be a static list, right?

If so, just use Spring configuration to create the list or any other collection of mandatory properties and inject it into your MandatoryPropertiesProcessor bean. No Camel at all for this part.

If the list changes, only the config and the bean change, but not your Camel route. This is reasonable since the "processing workflow" implemented through your route does not change.

burki
  • 6,741
  • 1
  • 15
  • 31
  • It seems a good idea but with this solution i cant reuse the processor in another route because each one has different mandatory parameters. – João Gomes Mar 12 '18 at 08:52
  • 1
    Why? You can configure multiple instances of the same bean class with Spring and inject them into the corresponding routes. – burki Mar 12 '18 at 08:58