Author: sctrcdr

Using the KIE (Drools) Workbench REST API to create a project

I was playing around with the KIE Workbench Docker image and came across an issue whereby the container would become unusable if the IP address of the host changed. My sandbox is VirtualBox, running Ubuntu 16.04, so this would happen all the time. I needed some way to be able to blow away an existing container and start up a new one with the project I had been working on.

This turned out to be a bit fiddly. For example, I couldn’t clone the Git repository for my project and push it into a new container. The new container didn’t have a repository to push to. Similarly, it wasn’t enough to copy the myproject.git file out of the original image and into the new one. It clearly takes more than that.

Continue reading “Using the KIE (Drools) Workbench REST API to create a project”

Multiple databases with Spring Boot and Spring Data JPA

A little while back I knocked up a post describing how to enable a Spring application to connect to multiple data sources. At the time, I had only just heard about Spring Boot at the SpringOne 2GX conference in Santa Clara, so the examples didn’t take advantage of that and also didn’t work around some of the autowiring that it does.

Recently, I was working on a little ETL project to migrate data from one database to another with a different structure, so I returned to this problem and the following is the result.

Continue reading “Multiple databases with Spring Boot and Spring Data JPA”

A minimal Spring Boot Drools web service

A little while back, I knocked up Qzr to demonstrate using Spring Boot with the Drools rules engine. However, I also wanted to play around with a few more technologies (AngularJS and Spring HATEOAS), so it’s a bit large for just demonstrating exposing Drools rules as an HTTP web service.

A few folks found it difficult to pick out the essentials of running Drools in a Spring Boot application, so I thought I’d have a go at creating a simpler application, which does nothing more than that.

Hence, the Bus Pass Web Service.

Continue reading “A minimal Spring Boot Drools web service”

Spring Data repositories with multiple databases

The Spring Data project keeps making it easier to do database access in Spring applications, and one of the neatest  improvements of recent times is that by defining an interface which extends JpaRepository and referencing a JPA entity, an implementation will automatically be injected with all the usual CRUD methods: findAll(), findOne(id), save(entity), delete(id), etc.

Recently I was working on a project, where I had taken full advantage of this, and for which I needed to add domain objects from an additional database. Unfortunately, as soon as I added references to entities in a different database I started experiencing troubles. For instance:

Not an managed type: class

… which was being caused by my repository being injected with the entityManager and transactionManager for the other database. Here I walk through how I resolved the problems and got things working.

Continue reading “Spring Data repositories with multiple databases”

A web service powered by Spring and Drools

For the past few years I have been designing and building web services which make use of decision management technology such as Drools and FICO Blaze Advisor. The past year or so has all been about using Drools Guvnor to enable business users (legal and operations teams) manage rules, and using the Drools rules engine to evaluate trade requests against those rules.

My preference in setting up web services is to use the Spring Framework to configure my application and manage its various components. However, I struggled to find much information online about how best to wire up a Spring web application to make use of Drools for rules evaluation. The Drools documentation does include a chapter on Spring integration, but I found that it didn’t seem to make the integration any simpler, and forced dependencies on older versions of Spring that I didn’t want to use. In the end, I decided to hand-crank the integration in my application, and it turned out to be quite easy to do.

Continue reading “A web service powered by Spring and Drools”

A BigDecimal accumulator for Drools

Working in the financial industry, I have become rather strict about avoiding doubles in Java. The trouble is that they are a floating point representation of a number, which is just an approximation of the real value. This can lead to some unusual results.

For instance, according to this, 0.34 + 0.01 is not equal to 0.35.

double x = 0.35;
double y = 0.34 + 0.01;
System.out.println(x + " : " + y + " : " + (x == y));
0.35 : 0.35000000000000003 : false

Those inaccuracies might seem very small, but it’s surprisingly easy for them to start impacting a real world application. Imagine you wanted to sell dollars and buy Iranian Rial. You would be getting almost 20,000 Rial for every dollar. At that rate, imprecise floating point values could easily impact the final amount being sent. Although with the current US trade sanctions against Iran, that could be the least of your problems.

Continue reading “A BigDecimal accumulator for Drools”

Bundling project dependencies with the shade plugin

Have you ever struggled with the mass of .jar files that you can find in a directory of Java libraries? You have no idea what version each of them is and what its dependencies are. You want to put your own application jar in there, but you know that will mean needing to get hold of 20 other jar files to deal with its dependencies.

Continue reading “Bundling project dependencies with the shade plugin”

Getting the latest snapshot from Sonatype Nexus

Sonatype Nexus is a repository for build artifacts, which is particularly handy if you have a Maven project. Once you have your Maven project configured, every time you run mvn deploy Maven will do a bit of building and then upload the resulting artifacts (.jar, .war, …) to the repository. If you browse Nexus you will then be able to find those artifacts with a unique name and download them.

This is all great, but if your project is running on a snapshot version, then every time you deploy to Nexus, the artifact file name will be appended with date and an ever-incrementing number. For my purposes, I wanted to be able to go on to a Linux test server where I have Apache Tomcat installed and grab the latest .war file. Maybe I need to relax more, but I was getting a bit irritated with having to manually find the snapshot in Nexus, copy the link and then fire off a curl -O -L http://... command every time I updated the project.

Continue reading “Getting the latest snapshot from Sonatype Nexus”

Playing around with Apache Camel

Originally posted @ on May 12th 2011.

I have been playing around with Apache Camel for a couple of projects recently, and so far I’m very impressed. Camel is one of a number of frameworks that seem to have sprung up over the past few years in response to the book Enterprise Integration Patterns by Gregor Hohpe and Bobby Woolf. It attempts to provide mechanisms to support all the patterns described in the book. And it does so very well, from what I have experienced so far. So I thought I would mention a couple of things I have done with it.

Continue reading “Playing around with Apache Camel”