Saturday, November 9, 2013

Troubleshooting in Java

This post is just a collection of troubleshooting tips that I've picked up during the years.

Sunday, April 14, 2013

Environment configuration property injection using Java CDI

In Spring Framework, injecting environment properties is made simple using the context:property-placeholder to configure property file locations and the @Value("#{propKey}") annotation to specify the key of the property.

Java CDI does not have an equivalent out-of-the-box, but it's flexible and rolling your own is easy using a single qualifier and a producer method.

Monday, March 18, 2013

How-to: RESTful Web services with JAX-RS and Spring

When providing services in a specific technology (i.e. EJB, JAX-WS, JAX-RS), it's wise to avoid mixing the business logic of your service and the technology that you are using to expose it to the outside world. This separation facilitates easier adoption of newer technologies and makes it easier to maintain and test services.

Tuesday, March 12, 2013

Testing Java classes with field injections

Dependency injection frameworks in Java give us 3 points of injection: constructor, field and setter methods. Many of us prefer field injection because we can skip writing setter methods and keep the number of lines to a minimum. The downside of field injection is that the class no longer can be used or tested without a dependency injection framework, for instance during unit-testing. In this post, I'm going to look at how we can unit-test a class with field injections.

Sunday, February 17, 2013

Sunday, February 10, 2013

Apache Wicket 6.5 vs. JSF 2.0

Having developed several web applications with JSF, and recently with Apache Wicket, I want to share my experience. On the web, Wicket has mostly positive buzz, but JSF seems to be hated by many (See http://ptrthomas.wordpress.com/2009/05/15/jsf-sucks/). I beg to differ.

Before I start, it should be noted that many of the frustrations and limitations of JSF discussed around the web have been have been addressed in version 2.0. And one more thing, the comparison aspects below are in no particular order.

Monday, January 28, 2013

How to become a better programmer?

By three methods we may learn wisdom:
First, by reflection, which is noblest;
Second, by imitation, which is easiest;
and third by experience, which is the bitterest.
- Confucius
These words are on my wall to remind me that there are easier ways of learning and in this post, I want to look at it from a programming perspective.

Sunday, January 20, 2013

Java Web Services – bottom-top-down approach

There are two approaches to developing web services: bottom-up and top-down. In the bottom-up approach, annotated Java classes are created first, and the WSDL is generated from these classes using wsgen tool.
Bottom-up approach.

In the top-down approach, the WSDL is created first, and the Java artifacts are generated using wsimport tool.
Top-down approach.

Sunday, January 13, 2013

JSF 2.0 Maven Archetype

Whenever I need to create a new web application in Java, I use the barebone web application Maven archetype that comes with NetBeans. Then, I proceed to add dependencies to libraries and frameworks that the application requires, followed by configuration files for logging and such. I test the setup by creating a "Hello world!" like structure and deploying it to an application server.

Although most of the time this process takes only a couple of minutes, sometimes I forget how to connect different bits and end up reading documentation for half an hour. To avoid wasting time on things I've done many times, I created a Maven archetype with the following setup: JSF 2.0, CDI, PrimeFaces, SLF4J and Logback. The archetype is deploy-ready, containing "Hello world!" examples of the essentials, and can be pulled from GitHub.