Deploying a NinjaFramework Application on OpenShift

Deploy a fat jar to OpenShift… Hmmmmm

A NinjaFramework application is built and deployed as a fat jar by default. Given this fact, I popped this question on StackOverflow. I figured that one would need to be some kind of Maven guru in order to build some kind of configuration to deploy it on OpenShift. Not so as it turns out. The guys at NinjaFramework have once again come up trumps. It turns out the process is effortless. This blog describes the steps involved from beginning to end. This process uses Netbeans.

Continue reading

JQuery-Mobile with AngularJS and Angular-Route (ngRoute)


The following details how JQuery-Mobile and AngularJS can play together seamlessly. Angular-Route (ngRoute) is used for navigation. A simple Angular directive invokes JQuery-Mobile styling and enhancements as each page is loaded. This includes pages loaded via  ng-include

A working example is available here as a Plunker

Continue reading

JSON Web Token (JWT) with CORS Stateless REST Service with Facebook Authentication


This blog will demonstrate how to authenticate a REST(ish) service with Facebook authentication, using a JSON Web Token (JWT).

This blog is follows on from previous blogs:

  1. Cross-Origin-Resource-Sharing (CORS) is detailed here
  2. Creating the REST Service and HTML5 Client is detailed here
  3. Adding authentication using Facebook is detailed here (but does not use JWT)

The previous blogs led up to situation where the user is able to authenticate with Facebook thus receiving a Facebook authentication token. Authentication with Facebook results in a request being sent to our REST service. The intent of that request is to authenticate with our Rest service. The request contains the Facebook authentication token and the users Facebook email address (from their Facebook profile). The Rest Service will receive the Facebook authentication token from the client, it then invokes Facebook itself using RestFB to retrieve the users profile. The email address received from the client is now compared with the email address taken from the Facebook profile just retrieved via RestFB.

  • If the email addresses match, the user is authentic. (Now the REST service generates a token for the client which identifies that client. Any time the client wants to invoke the service, it supplies that token).
  • If the email addresses do not match, the client supplied a valid Facebook authentication token but for a different account; reject this user.
  • If the profile cannot be retrieved, the client may have supplied an invalid Facebook authentication token; reject this user.

If the email addresses match, the user is authentic. At this point in the previous blog, the server just responds to the client with an email address, i.e. the matched email address. The client stores this and passes it to the service in a request-header on each request. Our REST service will use this each time to extract the user from persistence.

There are a couple of problems with this approach.

  1. The email address in transit is exposed unless HTTPS is used. HTTPS should be used so this is not such a big issue.
  2. The email address alone may not be sufficient information. Date/Time issued or Date/Time expires may be of use so that the token can be expired after a defined idle period.
  3. Data other than the email address may be required, i.e. a bunch of key-value pairs.

This blog will take the existing application created here and enhance it use a JWT token.

A Maven project and HTML5 client are available for download at the bottom of this blog.

Continue reading

Spring 4 Web MVC with AngularJS


The project downloadable below is an answer to a question repeated in this blog (Spring 3 MVC – Adding Objects to a List element on the fly at form submit – (Generic method))

“How can I submit nested lists of objects?”

The answer is AJAX and JSON.

A very good approach to this is with AngularJS and Spring as demonstrated here.

When the page loads it makes an AJAX call to the server to fetch the model.

The model is bound on the page using AngularJS.

The controls (buttons and input fields) on the page allow the model to be edited.

The model can then be sent to the server via AJAX where it can be persisted. The updated model is returned to the client where it is again bound using angularJS.

The application looks like this



This is a Maven project so just navigate to it using your IDE, open it and run it.





CORS Stateless REST Service with Facebook Authentication


This blog will demonstrate one way to enable authentication with Facebook on a Stateless CORS enabled REST service.

The CORS REST service will be created using the Ninja Framework.

Facebook authentication is via the Facebook JavaScript API.

RestFB is used to consolidate the authentication with the REST Service.

This blog is follows on from previous blogs:

  1. CORS Cross-Origin-Resource-Sharing is detailed here
  2. Creating the REST Service and HTML5 Client is detailed here

This blog focuses on adding authentication using Facebook to the application.

The HTML5 application and NinjaFramework Maven application are available for download at the bottom of this page.

Continue reading

Spring 4 Web MVC – JSON Handling


This blog demonstrates how to process JSON using Spring 4 Web MVC.

The JavaScript AJAX call is described in terms of request headers and request data formatting.

Spring uses Jackson for JSON parsing. Jackson is configured to ignore extra JSON properties that do not match properties of the bean being populated at the @Controller request end-point method.

This blog demonstrates populating complex objects n levels deep thus overcoming some difficulties encountered as per many of the comments in this blog.

Unlike Spring 3 MVC – Adding Objects to a List element on the fly at form submit – (Generic method) a generic JavaScript library is not provided. Populating JSON objects is easily achieved with JavaScript. For that reason, the difficulties of the HTML form implementation described (and partially solved) in that blog do not arise in the first place. Therefore it is hugely favorable to use JSON over conventional HTML forms for complex objects (and in general).

This demonstration conforms to a useful and popular design pattern. Specifically, the form is submitted asynchronously, the response is handled by the client JavaScript.

This provides for:

  • A far better user experience as there is no page load. Feedback is immediate.
  • Ease of development
  • Ease of validation handling
  • Support for complex forms
  • Code portability (think HTML5 clients and single page applications)

Continue reading

AngularJS – Radio Buttons – Three Scenarios


This post will detail how to AngularJS can enhance the usage and functionality of Radio Buttons.

Three scenarios are covered.

  1. Each radio button represents an object. For example, there may be a radio button for each element of an array. When one of the radio buttons is selected, a variable is assigned the corresponding array element. So, a variable called $scope.selectedPerson can be automatically assigned to the selected ‘person’ in an array of ‘person’ objects.
  2. Similar to ‘1’ except instead of selecting a complete object, it’s possible to select just a property of an object. E.g. instead of $scope.selectedPerson, the variable can be $scope.selectedPersonName. This is a simple elaboration on the first scenario purely for emphasis.
  3. This scenario is considerably different. Take elements being added to an array dynamically through a UI, the user adding the elements needs to assign one of them as the default element. This is achieved by setting a property (isDefault = true for example) in the array element object. The other array elements have their isDefault property set to false. Unlike the previous two examples, an external variable is not being set, the elements of the array themselves are being manipulated.

Continue reading

AngularJS – isolate scope – ‘=’ (function reference)


This blog demonstrates how to pass a reference to a function to an angular directive/template.

The way in which the child directive/template calls the parent is also demonstrated.

The example is available as a working JSFiddle here.

This tutorial details creating directive/templates in general (without an isolated scope).

This tutorial demonstrates passing values by value to angular directives/templates (@).

This tutorial demonstrates passing values by reference to angular directives/templates (=).

Continue reading

CORS Stateless REST Service with detached HTML5 client


This blog will detail in precise steps how to create a stateless REST service that is consumed by a HTML5 client on another domain. The HTML5 client could easily be a Cordova or Phonegap app.

The HTML5 client is simple and basic just for demonstration purposes. It shows the characteristics necessary for Cross-Origin-Resource-Sharing (CORS) communication.

The REST service is also simple. It demonstrates how to enable CORS on the server application.

While both Client and Server projects are proliferated throughout this blog, the completed artifacts are available for download at the bottom of this page.

Related Posts

Authenticating a REST Service using Facebook authentication

Adding JSON Web Token (JWT) enhancements to “Authenticating a REST Service using Facebook authentication”

Continue reading

AngularJS – isolate scope – ‘=’ (pass by reference)


This blog will explore the concept of passing object to angularJS directives / templates using by reference.
When an object is passed by reference both the parent (controller or parent directive) and the child directive/template have access to the object. The relationship is bidirectional.

This tutorial details creating directive/templates in general (without an isolated scope).
This tutorial demonstrates passing values by value to angular directives/templates (@).

Continue reading

AngularJS – isolate scope – ‘@’ (pass by value)


Objects can be passed into an angularJS directive in any one of the following ways:
By value using ‘@’
By reference using ‘=’
As a reference to a function in the parent controller using ‘&’

The next few blogs will detail each of these techniques.

This blog will detail the ‘@’ (by value technique).
For detail on creating an angularJS template via a directive please see this blog

Continue reading

Spring 4 Web MVC – Hello World using Annotation and Java configuration with Netbeans

This blog will go through the steps required to setup a basic Spring 4 MVC web application using Netbeans and Maven. The Spring 4 project will be configured using annotations and plain Java rather than XML.

It is a step by step guide to getting up and running quickly. There are plenty alternative methods to doing this but this one is simple, lightweight and to the point. A maven project is available for download at the end of this blog.

Continue reading

Rounding a number up to it’s nearest order of ten

I’m hopeless at math, this is just for future reference as it really bugged me. How to round a number up to it’s upper order of 10. Not a simple as it may seem.


800 -> 1000
125 -> 1000
80 -> 100
43 -> 100
8 -> 10
9 -> 10
0.8 -> 1
0.23 -> 1
.08 -> 0.1
(consider -> to be “goes-to” or “rounds-up-to”)


The solution Continue reading

Using templates with AngularJs

The purpose of this blog is to demonstrate how to use templates in AngularJS. A fully worked example is provided via jsFiddle. The example is simple and easy to follow. A detailed but succinct explanation of the code is provided.

The template is “complex html” that we’ll want to reuse. The directive will allow this complex html to be delivered anywhere without code duplication. This obviously has advantages in terms of code reuse and maintainability.

Continue reading

AngularJS – Permitting AngularJS templates in IE8

So, you’ve got something like this:

But you find that in IE8 the directive that populates the <mytemplate/> element is not working at all in IE8. IE8 will not initialise the controller and hence your $scope is null.

Continue reading

Hibernate-Search Multiple-value Facet-Counts


The hibernate-search facet search API is pretty amazing but it lacks a little on the following:

  • Facet-Count values are incorrect where a facet matches a fields that have multiple values. I.e. the facet-counts are correct where the facet has a 1-to-many relationship with result-set items but the facet-counts are entirely incorrect where the facet has a many-to-many relationship with result-set items.
  • The facet-count values are that of the number of matched result-set items within the result-set as distinct from the number of matched result-set items that will be merged into the result-set if the facet is applied. This is highly undesirable where more than one facet-group is used conjunctively. Let’s explain…
    • Facet-counts are available before any facets are applied. Adjusted facet-counts are available after facets are applied. This is great because it facilitates two different usages. With the former, the facet-counts can remain static as facets are selected and deselected. With the latter, applying one facet will reduce the facet-count for other facets. In fact, the other facet-counts can reduce to zero. This zero count does not necessarily mean no result-set items will result from applying the facet. Consequently, we don’t know if clicking on the facet will yield new results or not. If a facet yields no results, and it is used in conjunction with facets from another facet group, this can lead to a zero-results situation. Confused? no problem Ok, allot of detail, description, example and analysis is provided in this blog.
  • These issues are identified in the following discussion threads:
  • This blog delivers a comprehensive solution to all issues surrounding facet-counts in hibernate-search. The solution is derived from the information provided here: A java class that delivers the solution is provided. There is also a fully working maven project demonstrating the solution in action.

Continue reading

Understanding Faceted Searching


Tony Russell-Rose describes faceted searching in great detail in these posts:

They’re well worth a read before even contemplating developing a faceted search.

There are many types of faceting techniques available. This blog focuses on a facet-search where the facets and results remain on a single page. Facets dynamically reduce and expand the result-set on the same page. A good comparable might be the faceted people search on This one is also a really good example:

We’re going to describe faceted searching and its oddities through example. The examples proliferate in complexity towards an end result which hopefully will yield an understanding of how faceted searching can (or dare I indulge, should work). Some rules for development/behavior will emerge; these will be emphasized and summarized throughout. At the end there is some rambling and a solution for a hibernate-search implementation but for the first 99% of the blog there is no focus on implementation; the focus is exclusively on the following.

  • What exactly a faceted search really is.
  • The behavior of the result-set in response to applying or removing facet selections.
  • What the numbers beside the facets (facet-counts) really mean (cardinality).
  • The different relationships between facets and result-sets e.g. 1-to-Many V.s. Many-to-Many.

The examples used throughout are simple to understand but they will provoke allot of thought because filtering results by facets is not as straight forward a process as may seem at an initial glance. It can be extremely confusing. Each example is a fully working jsFiddle.

Continue reading