Validate Camel routes with fabric8 maven plugin

One of the coolest things you can do with Fabric8 Maven plugin is the validation of Camel routes which can be done in your favorite IDE or with as little as a shell

Let's see a quick example of it. We will use any of the examples provided with Camel distribution such as the camel-example-jdbc. Move to the folder where the pom.xml is and issue:

$ mvn compile -DshowAll=true compile io.fabric8.forge:fabric8-camel-maven-plugin:2.3.80:validate

 The output will show all the routes which have been inspected and the validation result:

[INFO] Endpoint validation passsed at: META-INF.spring.camel-context(camel-context.xml:54)

	dataset:sampleGenerator


[INFO] Endpoint validation passsed at: META-INF.spring.camel-context(camel-context.xml:63)

	jdbc:dataSource?useHeadersAsParameters=true


[WARNING] Endpoint validation error at: META-INF.spring.camel-context(camel-context.xml:64)

	log:insertLog?showHeaders=true

	             showHeaders    Unknown option


[INFO] Endpoint validation passsed at: META-INF.spring.camel-context(camel-context.xml:70)

	timer://timer1?period=2s


[INFO] Endpoint validation passsed at: META-INF.spring.camel-context(camel-context.xml:76)

	jdbc:dataSource


[INFO] Endpoint validation passsed at: META-INF.spring.camel-context(camel-context.xml:79)

	bean:recordProcessor


[INFO] Endpoint validation passsed at: META-INF.spring.camel-context(camel-context.xml:80)

	direct:updateDone


[INFO] Endpoint validation passsed at: META-INF.spring.camel-context(camel-context.xml:84)

	direct:updateDone


[INFO] Endpoint validation passsed at: META-INF.spring.camel-context(camel-context.xml:93)

	jdbc:dataSource?useHeadersAsParameters=true


[INFO] Endpoint validation passsed at: META-INF.spring.camel-context(camel-context.xml:97)

	log:updateDone


[WARNING] Endpoint validation error: (9 = passed, 1 = invalid, 0 = incapable, 0 = unknown components)
[INFO] Simple validation passed at: META-INF.spring.camel-context(camel-context.xml:78)

	${body}


[INFO] Simple validation passed at: META-INF.spring.camel-context(camel-context.xml:86)

	${body['ID']}


[INFO] Simple validation passed at: META-INF.spring.camel-context(camel-context.xml:95)

	Record ID=${headers.camelTestId} has been marked as 'DONE'


[INFO] Simple validation success: (3 = passed, 0 = invalid)

 Let's test for  example what happens if we include a typo in any of the above rules:

[WARNING] Endpoint validation error at: META-INF.spring.camel-context(camel-context.xml:63)

	jdbc:dataSource?XXuseHeadersAsParameters=true

	XXuseHeadersAsParameters    Unknown option. Did you mean: [useHeadersAsParameters, allowNamedParameters]

 As you can see, the plugin even suggests potential matches with other parameters or components!

 You can also enable the plugin to automatic run as part of the build to catch errors by including in your pom.xml file:

  <plugin>
    <groupId>io.fabric8.forge</groupId>
    <artifactId>fabric8-camel-maven-plugin</artifactId>
    <version>2.3.80</version>
    <executions>
      <execution>
        <phase>process-classes</phase>      
        <goals>
          <goal>validate</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

 


Advertisement

Cookie Alert