2016-12-05

Camel Maven Plugin can now parse your source code and report invalid endpoints

I have previously blogged about the fabric8 Camel Maven Plugin which is able to parse your source code and parse all the Java RouteBuilder and XML routes and report invalid Camel endpoints.

That was in the start of 2016. Now at the end of 2016, the code has stabilized and the fabric8 team has gracefully donated the source to to ASF so it will be included out of the box from Apache Camel 2.19.0 onwards.

To see the plugin in action you can watch the video from my previous blog. The plugin would work the same when its from Apache Camel.

To give a demonstration of the plugin, I have modified the camel-example-twitter-websocket example from Apache Camel to make some invalid configurations:

- Renamed the polling to poling in the twitter endpoint
- Added foo=bar as option to the log endpoint
- Spelt the sendToAll option with a lower case a.

And when I run the plugin I see

mvn camel:validate

Then Maven outputs:

[INFO] --- camel-maven-plugin:2.19.0-SNAPSHOT:validate (default-cli) @ camel-example-twitter-websocket ---
[INFO] Using Camel version: 2.19.0-SNAPSHOT
[WARNING] Endpoint validation error at: org.apache.camel.example.websocket.TwitterWebSocketRoute.configure(TwitterWebSocketRoute.java:109)

twitter://search?type=poling&delay={{%s}}&keywords={{%s}}

                   type    Invalid enum value: poling. Possible values: [polling, direct, event]. Did you mean: [polling]. Default value: direct


[WARNING] Endpoint validation error at: org.apache.camel.example.websocket.TwitterWebSocketRoute.configure(TwitterWebSocketRoute.java:110)

log:tweet?foo=bar

                    foo    Unknown option


[WARNING] Endpoint validation error at: org.apache.camel.example.websocket.TwitterWebSocketRoute.configure(TwitterWebSocketRoute.java:112)

websocket:camel-tweet?sendToall=true

              sendToall    Unknown option. Did you mean: [sendToAll]


[WARNING] Endpoint validation error: (0 = passed, 3 = invalid, 0 = incapable, 0 = unknown components)
[INFO] Simple validation success: (0 = passed, 0 = invalid)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

As you can see it discovered 3 invalid endpoints, and reported suggestions what is the error.

By default the maven goal does not fail maven itself, and hence why you see BUILD SUCCESS. The plugin has a number of options you can configure.

For more information see the Camel Maven Plugin documentation.

PS: The plugin also parses your Simple expressions and report invalid configurations as well.

We may in the future add parsers for other languages so we can parse XPath, XQuery, Groovy and others.


2 comments:

Souciance Eqdam Rashti said...

Really cool, a very valuable part of the CI build process to catch these errors that do occur. Great!

Frank Wein said...

Now that looks like a very good feature for us Camel users, good work!