Handling different subresources with JAX-RS subresource locator

1 Introduction In this article I won’t explain what a resource or sub resource is. There are several pages that explain perfectly well its meaning. For example, you can check Oracle tutorial or Jersey documentation. I will focus on implementing a RESTful service with a JAX-RS sub resource locator. This…

Retrieving method annotations with Spring AnnotationUtils

1 Introduction to Spring AnnotationUtils The JDK provides us with several lookup methods that allow us to retrieve annotations from a class, method, field or added to method parameters. The Spring AnnotationUtils is a general utility class for annotations which extends the basic functionalities. In this post I will explain…

Unit testing with PowerMock

In this article I will implement unit testing with PowerMock library. This framework is more powerful than other libraries and allows you to mock static methods, private methods and change field properties among other things. I will use the Mockito extension but it also supports EasyMock. 1   Installation If you…

Communication in Spring Webflow 2

1   Introduction This article tries to complement the reference documentation with examples on variables, scopes and flows in Spring Webflow 2. It shows different ways to share data between controllers and views that form a flow. The article is divided into the following sections: Setting flow variables Setting attribute values…

Centralize validation and exception handling with @ControllerAdvice

1 Introduction The ControllerAdvice annotation introduced by Spring 3.2 allows us to handle several functionalities in a way that can be shared by all controllers (through its handler methods, annotated with @RequestMapping). This annotation is mainly used to define the following methods: @ExceptionHandler: Handles exceptions thrown by handler methods. @InitBinder:…

Accessing Restful services. HTTP Message converters

Registered converters When accessing to Restful services, the Spring class RestTemplate maintains a list of message converters. This list will be used to marshal objects into the request body, or unmarshalling them from the response. When instantiating the RestTemplate class, it automatically fills a list with several converters: ByteArrayHttpMessageConverter StringHttpMessageConverter…

Spring property-placeholder: External properties configuration

The PopertyPlaceholderConfigurer A common way of setting the configuration of the web application is by defining it in a properties file. We can find this file in the classpath. The way of doing this is using the PropertyPlaceholderConfigurer class, or simplifying the configuration, using the context namespace property-placeholder.

That’s…

Create and test REST services with Spring MVC

Introduction The first part of this example shows how to create and test REST services using Spring MVC. The controller contains CRUD operations on warehouses and its products. For this example, the repository is a stub that simulates access to the database. The second part will access these services using…

spring-webflow-logo

Spring Webflow: Embedding a flow in a modal JSF dialog

Introduction The latest version of Spring Webflow (2.3.1) provides us with a new and very interesting functionality that I have really missed in my current project: embedded flows. By default, Webflow applies the POST/REDIRECT/GET pattern every time it enters a view state. The reason to do this is to prevent…

spring-webflow-logo

Testing Spring Webflow 2 with inheritance

This blog entry shows how to test a flow with inheritance in Spring Webflow 2. The flow to be tested consists of a simple navigation which starts with a view state and ends getting to another view state that will depend on the result of the execution of a controller….