Writing a Camel Component – Camel-Static-Resource

Blue and Red CubesMany times the Camel examples I write need to serve up  a simple web UI (usually using the ever so awesome AngularJS).  I’ve just have been pasting the code below into a Camel route. This is fine but lately I’ve been also using Mule on a project and I noticed that Mule has a static resource component. Since Camel didn’t have one it provided the perfect opportunity to show just how easy it is to create a new Camel component. The bulk of implementing the new component will be taking the Processor from my code and implementing the process method in the new component producer. [click to continue…]

Simple Github API Webapp – AngularJS Style

betterThis morning I saw a post by Jake Rocheleau on DZone titled Code a Simple Github API Webapp using jQuery & Ajax. Since I’ve been working with the GitHub API lately as well as AngularJS I decided to refactor his code using AngularJS instead of jQuery. I tried to make minimal changes from Jake’s example to make comparison easy.

The results show the power of AngularJS’ data binding and separation of logic and view.  There was no need to manipulate the DOM in Javascript or output HTML from Javascript.

It’s a simple, but very nice example, so the refactor wasn’t very difficult. Removing jQuery and using AngularJS, the initial form, getting the user data and displaying it which is two calls to the GitHub API. One to get the user information and another to get a list of that users repositories.

Using AngularJS

The first step is to remove jQuery and add support for an AngularJS application. This simply requires the removal of the jQuery script include a adding a script tag including AngularJS. Then the AngularJS app needs to be initialized and an empty controller added.

[click to continue…]

Camel SOAP – REST Bridge Example


This example of a Camel SOAP – REST bridge exposes part of the Github REST API as a SOAP interface using a code first approach using the Camel CXF component. Github provides an extensive REST API, we’ll just expose three of the many methods it provides. Get project tags, get project branches and get owner repos.

Define the contract

I used the Camel CXF component to expose a code first SOAP example.

[click to continue…]

Camel Release Package Version Differences

New version stampSomeone on the Camel developers mailing list mentioned that it’d be nice if the package versions were maintained in a separate file outside if parent/pom.xml. This may or may not happen. In the mean time I threw together a program that uses Camel to provide a service that serves up a JSON structure containing the version difference between 2 different versions. For the front end I added a simple AngularJS page (with Twitter Bootstrap thrown in to make it look better).

The page is hosted on Heroku at http://vdiff.notsoclever.cc . The AngularJS page and other content is served up from Jetty. Two REST resources are exposed to handle data chores. The first http://hostname/tags returns a JSON list of Camel release tags. The second, http://hostname/{v1}/v2} returns a JSON structure detailing the package version differences between the two releases specified.

During the development I discovered a bug in the Camel Restlet component that prevents this example from working on Heroku. The Restlet component incorrectly binds to port 80 when the only Restlet endpoints are servlet based. So I built a hacked version that prevented this error. However, it’s a specific hack for this example and I’ll have to work later on fixing the Restlet component in the Camel source.

The data is pulled from the github mirror because GitHub’s API made it convenient to retrieve a full list of releases.

Source code is at https://github.com/tjsnell/vdiff.


In this example the Camel CXFRS component is used to expose a REST interface to a database table.apache_feather

The database table we’re using is quite simple. It has an auto incrementing ID, a company name and a stock symbol. I used Derby for my database (though any JDBC database would work) to keep it simple. Since the example uses an in memory database it needs to be set  up  each time the example is run. DatabaseBean.java does this. The datasource field is injected by Spring  and the method create() creates the DB.

In the Spring camel context file create the datasource and an instance of DatabaseBean which calls create().

[click to continue…]

I was writing a route today to a internal REST service that required a custom header in the HTTP GET request. The solution wasn’t immediately obvious and I spent way too much time figuring it out. Fairly simple to do though far from concise.


Screen Shot 2013-07-24 at 11.53.52 PM

In the Freenode java channel ##java someone mentioned their next goal was to learn REST by writing a service to convert between Celsius and Fahrenheit. I mentioned how simple that’d be with the right tool (Camel of course) and wrote the example.

First step was so generate a project using one of the Maven Camel archetypes. In this case I chose the Java DSL archetype camel-archetype-java.

[click to continue…]

Camel CXF Component – WSDL First Example

cxf-eipThis is the first of a series of posts of simple examples in Camel designed to show a single simple use case. In this one I’ll show how to create a consumer and producer using the Camel CXF component and a WSDL first approach.

  1. Generate source from the WSDL
  2. Create a Consumer (our server)
  3. Create a Producer (client) that also acts as the test

Generate Source

The WSDL is simple. It defines two methods.

  1. getCustomersByName
  2. updateCustomer


[click to continue…]

Column and Row Based Tables in AngularJS

Row based dynamic tables are fairly easy. However, AngularJS makes building a column based dynamic table just as easy. The full code is also on JSFiddle

Screen Shot 2013-06-13 at 2.19.19 PM [click to continue…]