Apache Camel SSL on http4

When creating a camel route using http, the destination might require a ssl connection with a self signed certificate.

Therefore on our http client we should register a TrustManager that suports the certificate.

In our case we will use the https4 component of Apache Camel
Therefore we should configure the routes and add them to the camel context

RouteBuilder routeBuilder = new RouteBuilder() {
            public void configure() throws Exception {

But before we proceed on starting the camel context we should register the trust store on the component we are going to use.
Therefore we should implement a function for creating an ssl context with the trustore.
Supposed the jks file that has the certificate imported is located on the root of our classpath.

   private void registerTrustStore(CamelContext camelContext) {

        try {
            KeyStore truststore = KeyStore.getInstance("JKS");
            truststore.load(getClass().getClassLoader().getResourceAsStream("example.jks"), "changeit".toCharArray());

            TrustManagerFactory trustFactory = TrustManagerFactory.getInstance("SunX509");

            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, trustFactory.getTrustManagers(), null);

            SSLSocketFactory factory = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

            SchemeRegistry registry = new SchemeRegistry();
            final Scheme scheme = new Scheme("https4", 443, factory);

            HttpComponent http4 = camelContext.getComponent("https4", HttpComponent.class);
            http4.setHttpClientConfigurer(new HttpClientConfigurer() {

                public void configureHttpClient(HttpClientBuilder builder) {


                    Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                            .register("https", factory)

                    HttpClientConnectionManager connectionManager = new  BasicHttpClientConnectionManager(registry);

        } catch (IOException e) {
        } catch (NoSuchAlgorithmException e) {
        } catch (CertificateException e) {
        } catch (KeyStoreException e) {
        } catch (KeyManagementException e) {

After that our route would be able to access the destination securly.


Set up Jenkins for Node.js

Jenkis is a great ci server with many options and plugins.
With a bit of time and configuration we can use Jenkins for our Node.js applications.

First of all the Node.js plugin on Jenkins enables us to run node.js scripts as a build step.

Screen Shot 2015-06-20 at 3.10.17 PM

In order to proceeed executing various node.js tasks we can use shell build step.

The next step is to install packages using npm

Screen Shot 2015-06-20 at 3.16.59 PM

The next problem is how to keep our application up and running.

To achieve this we can use forever.

Just add the latest version as a dependency inside your package.json

"dependencies": {
"forever": "0.14.1"

Then in the same build step we should stop any already running applications.

./node_modules/forever/bin/forever stopall

And by calling forever with BUILD_ID=dontKillMe in front of it we will ensure that Jenkins would not kill our node.js process running, which is most probably an application listening to a port.

BUILD_ID=dontKillMe ./node_modules/forever/bin/forever start bin/www


Screen Shot 2015-06-20 at 3.23.46 PM

For unit testing I prefer the mocha framework.
xunit-file is a great plugin that will transform the results of mocha into a JUnit result file. Therefore we will add the mocha and xunit-file dependencies.

"dependencies": {
"mocha": "~2.2.4",

As a build step we should setup

./node_modules/.bin/mocha --recursive --reporter xunit-file


Screen Shot 2015-06-20 at 3.31.53 PM 1

The xunit file produced on the workspace would be used from Jenkins in order to produce a JUnit report.

Therefore we should add a post build action to Jenkins that will publish the JUnit results.

Screen Shot 2015-06-20 at 3.33.31 PM