Posts tagged java

JMS basics

I’m currently integrating JMS (Java Messaging Service) into a project. Being a true enterprise component it has a very complex nomenclature and consists itself of many modules to cover all kinds of topologies. To aid other newcomers here is an overview of what I’ve learned so far.

(more…)

Accessing bundled resources in Java packages

This is sort of a continuation of a previous post about how to integrate your own Java classes into the Maven build lifecycle. This entry described how to generate files for inclusion in the final project artifact (ie. .jar, .war etc.). It took me some time to figure out how to access these files using Java’s resource mechanism so this post will summarize my findings.

(more…)

Calling Java classes from the Maven build lifecycle

I love Maven for its flexibility, but this flexibility at times makes it hard to figure out how to achieve certain tasks. In my case I wanted to execute a certain Java class that is included in the project at some point during the build lifecycle. While I can see many uses in my case the class itself compiles a SQL dump out of several source files so it can be included in the final artifact.

(more…)

Spring Security authentication with a Neo4j backend

I am currently working on a Spring-based Neo4j (a graph database) application and needed to add user authentication. Since Spring Security allows integrating custom authentication providers it felt only natural to implement a provider based on Neo4j. A data structure to support users and groups is already provided in the Neo4j Wiki. I used it as the basis for my implementation with some wrapping so it could be integrated with Spring Security and provides administrative methods.

(more…)

Iterating over nested objects in a Spring form

Spring 3 allows for wonderfully simply forms and automatic binding of form values back to the command object. However if your command object has further nested objects that you want to make editable from the form as well things get a little tricky. In that case you can’t just use a standard JSTL forEach loop as this will not allow you to build the path to the nested object correctly. The trick is to use the varStatus attribute to keep track of the index.

(more…)

Unit Testing a Spring @Controller

Thanks to Spring’s new MVC Annotations (@Controller, @RequestMapping, @RequestParam etc.) unit testing a Spring controller is now easier than ever before. Still, I had a hard time figuring out how to do this since most of your controller methods will not take a ServletRequest as input. Instead they use a form-backing / command object, a BindingResult and maybe a ModelMap. In a web environment Spring takes care of filling the command object and validation results however in a unit test you will have to do this yourself.

Following is the basic outline for writing such a test.

(more…)

Go to Top