Spring
-
Making queries on demand: MongoDB outbound gateway
Integration, mongoDB, Spring, Spring-Boot ·In order to read data from MongoDb, Spring Integration comes with the MongoDb inbound channel adapter. This adapter uses a poller to continuously retrieve documents from the database. However, sometimes we may need to query the database on demand, based on the result of another endpoint.
Taking advantage of Spring’s extensibility, I implemented a MongoDb outbound gateway. The purpose of...
-
Spring Integration MongoDB adapters with Java DSL
Integration, mongoDB, Spring, Spring-Boot ·This post explains how to save and retrieve entities from a MongoDB database using Spring Integration. In order to accomplish that, we are going to configure inbound and outbound MongoDB channel adapters using the Java DSL configuration extension. As an example, we are going to build an application to allow you to write orders to a MongoDB store, and then...
-
Spring Integration – Polling file creation and modification
Integration, Spring, Spring-Boot ·File support is another of Spring Integration’s endpoints to communicate with external systems. In this case, it provides several components to read, write and transform files. During this post, we are going to write an application which monitors a directory in order to read all files in there. In concrete it does the following:
- When the application starts, it...
-
Data Aggregation Spring Data MongoDB: Nested results
mongoDB, Spring ·In a previous post, we built a basic example of an aggregation pipeline. Maybe you want to take a look at Data aggregation with Spring Data MongoDB and Spring Boot if you need more detail about how to create the project and configure the application. In this post, we will focus on learning a use case where it makes...
-
Data aggregation with Spring Data MongoDB and Spring Boot
mongoDB, Spring, Spring-Boot, Spring-Data ·MongoDB aggregation framework is designed for grouping documents and transforming them into an aggregated result. The aggregation query consists in defining several stages that will be executed in a pipeline. If you are interested in more in-depth details about the framework, then mongodb docs are a good point to start.
The point of this post is to...
-
Understanding Callable and Spring DeferredResult
Spring, Spring MVC, Spring-Boot ·Asynchronous support introduced in Servlet 3.0 offers the possibility to process an HTTP request in another thread. This is specially interesting when you have a long running task, since while another thread processes this request, the container thread is freed and can continue serving other requests.
This topic has been explained many times, but there seems to be a little...
-
Configure a Spring JMS application with Spring Boot and annotation support
Spring, Spring JMS, Spring-Boot ·In previous posts we learned how to configure a project using Spring JMS. If you check the article introduction to messaging with Spring JMS, you will notice that it is configured using XML. This article will take advantage of the improvements introduced in Spring 4.1 version, and configure a Spring JMS application with Spring...
-
Exposing HTTP Restful API with Inbound Adapters. Part 2 (Java DSL)
Integration, Spring ·In the previous part of this tutorial, we implemented an application exposing a Restful API using XML configuration. This part will re-implement this application using Spring Integration Java DSL.
The application is implemented with Java 8, but when Java 8 specific code is used (for example, when using lambdas), I will also show you how to do it...
-
Exposing HTTP Restful API with Inbound Adapters. Part 1 (XML)
Integration, Spring ·The purpose of this post is to implement an HTTP Restful API using Spring Integration HTTP inbound adapters. This tutorial is divided into two parts:
- XML configuration example (this same post).
- Java DSL example. This will be explained in the next part of this tutorial, showing how to configure the application using Spring...
-
Spring Integration 4.0: A complete XML-free example
Integration, mongoDB, Spring, Spring WS ·Spring Integration 4.0 is finally here, and this release comes with very nice features. The one covered in this article is the possibility to configure an integration flow without using XML at all. Those people that don’t like XML will be able to develop an integration application with just using JavaConfig.This... -
Spring Integration – Configure web service client timeout
Integration, Spring, web services ·With the support of Spring Integration, your application can invoke a web service by using an outbound web service gateway. The invocation is handled by this gateway. Hence, you just need to worry about building the request message and handling the response. However, with this approach it is not obvious how to configure additional options like setting timeouts or caching...
-
Thymeleaf integration with Spring (Part 2)
mongoDB, Spring, Spring MVC, Thymeleaf ·This is the second part of the Thymeleaf integration with Spring tutorial. You can read the first part here, where you will learn how to configure this project.
As explained at the beginning of the first part of this tutorial, the web application will send two types of requests:
-
Insert a new guest: Sends a...
-
-
Thymeleaf integration with Spring (Part 1)
mongoDB, Spring, Spring MVC, Thymeleaf ·This article is focused on how Thymeleaf can be integrated with the Spring framework. This will let our MVC web application take advantage of Thymeleaf HTML5 template engine without losing any of the Spring features. The data layer uses Spring Data to interact with a mongoDB database.
The example consists in a Hotel’s single page web application from where we...
-
Migrating Spring MVC RESTful web services to Spring 4
mongoDB, Spring, Spring MVC ·Spring 4 brings several improvements for MVC applications. In this post I will focus on restful web services and try these improvements by performing a migration from Spring MVC 3.2 to Spring 4.0. We will take a project implemented with Spring 3.2 and perform the steps to upgrade it to Spring 4.0. The following points sum up the...
-
Retry web service operations with RequestHandlerRetryAdvice
Integration, mongoDB, Spring ·Sometimes when invoking a web service, we may be interested in retrying the operation in case an error occurs. When using Spring Integration, we can achieve this functionality with RequestHandlerRetryAdvice class. This class will allow us to retry the operation for a specified number of times before giving up and throwing an exception. This post will show...
-
How error handling works in Spring Integration
Integration, Spring ·The target of this post is to show you how error handling works in Spring Integration, using the messaging system. You will see that error handling is different between synchronous and asynchronous messaging. As usual, I’ll skip the chat and proceed with some examples.
You can get the source code at my Github repository
1 The...
-
Spring Integration – Using RMI Channel Adapters
Integration, Spring ·This article explains how to send and receive messages over RMI using Spring Integration RMI channel adapters. It is composed of the following sections:
- Implement the service: The first section focuses on creating and exposing a service.
- Implement the client: Shows how to invoke the service using the MessagingTemplate class.
- Abstracting SI logic: Finally, I’ve added another section explaining...
-
Creating contract-first web services with Spring WS
Spring, Spring WS ·This article explains how to implement and test SOAP web services with Spring WS project. This example uses JAXB2 for (un)marshalling. To develop the service, I’ll use the contract-first approach, which consists in defining the service contract first, and based on this contract implement the service.
The article is divided into the following sections:
2 ... -
Processing messages in transactions with Spring JMS
Integration, Spring, Spring JMS ·This post shows how to process messages in transactions with Spring JMS. We will see how an error in the execution of the consumer during the asynchronous reception of messages with JMS, can lead to the loss of messages. I then will explain how you can solve this problem using local transactions.
You will also see that this solution can...
-
Introduction to messaging with Spring JMS
Integration, Spring, Spring JMS ·In this post I will show you how to configure a standalone application in order to see different ways of sending and receiving messages using Spring JMS. Basically, I will divide the examples into the following sections:
- Point-to-point messaging (queue)
- Synchronous reception
- Asynchronous reception
- Publish-subscribe messaging (topic)
The source code with all the examples shown...
- Point-to-point messaging (queue)
-
Applying aspect oriented programming
AOP, Spring, Spring MVC ·This article explains how to apply aspect oriented programming with Spring AOP. The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns we are referring to generic functionality that is used in several places in our system or application.
These concepts are, among others:
- Logging
- Transaction management
- Error handling ...
-
Retrieving method annotations with Spring AnnotationUtils
Spring ·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 the main features of this class, focusing on retrieving annotations from a method.
<h2…
-
Communication in Spring Webflow 2
Spring, Spring Webflow ·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
- Using additional scopes
- Communication with sub flows
- Communication with other flows ...
-
Centralize validation and exception handling with @ControllerAdvice
Spring, Spring MVC ·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...
-
Accessing Restful services. HTTP Message converters
Spring, Spring MVC ·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
- ResourceHttpMessageConverter
- SourceHttpMessageConverter
- AllEncompassingFormHttpMessageConverter
<span... -
Spring property-placeholder: External properties configuration
Spring ·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.
<context:property-placeholder location="datasource.properties"/>
That’s ok but, what if you need a different configuration...
-
Create and test REST services with Spring MVC
Spring, Spring MVC ·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... -
Spring Webflow: Embedding a flow in a modal JSF dialog
Spring, Spring Webflow ·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 duplicate form submissions, but this also prevents us...
-
Testing Spring Webflow 2 with inheritance
Spring, Spring Webflow ·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. This flow extends another flow which basically contains...
-
Configure Spring Webflow 2 with jsp views
Spring, Spring Webflow ·This tutorial explains how to configure Spring Webflow 2, showing how it integrates with the view layer, in this case, JSP pages. The web application will allow two different types of request, flow executions and requests to Spring Web MVC. When a request comes in, it will try to find a flow. If not successful, it will try...
Spring Webflow
-
Communication in Spring Webflow 2
Spring, Spring Webflow ·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
- Using additional scopes
- Communication with sub flows
- Communication with other flows ...
-
Spring Webflow: Embedding a flow in a modal JSF dialog
Spring, Spring Webflow ·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 duplicate form submissions, but this also prevents us...
-
Testing Spring Webflow 2 with inheritance
Spring, Spring Webflow ·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. This flow extends another flow which basically contains...
-
Configure Spring Webflow 2 with jsp views
Spring, Spring Webflow ·This tutorial explains how to configure Spring Webflow 2, showing how it integrates with the view layer, in this case, JSP pages. The web application will allow two different types of request, flow executions and requests to Spring Web MVC. When a request comes in, it will try to find a flow. If not successful, it will try...
Spring MVC
-
Understanding Callable and Spring DeferredResult
Spring, Spring MVC, Spring-Boot ·Asynchronous support introduced in Servlet 3.0 offers the possibility to process an HTTP request in another thread. This is specially interesting when you have a long running task, since while another thread processes this request, the container thread is freed and can continue serving other requests.
This topic has been explained many times, but there seems to be a little...
-
Thymeleaf integration with Spring (Part 2)
mongoDB, Spring, Spring MVC, Thymeleaf ·This is the second part of the Thymeleaf integration with Spring tutorial. You can read the first part here, where you will learn how to configure this project.
As explained at the beginning of the first part of this tutorial, the web application will send two types of requests:
-
Insert a new guest: Sends a...
-
-
Thymeleaf integration with Spring (Part 1)
mongoDB, Spring, Spring MVC, Thymeleaf ·This article is focused on how Thymeleaf can be integrated with the Spring framework. This will let our MVC web application take advantage of Thymeleaf HTML5 template engine without losing any of the Spring features. The data layer uses Spring Data to interact with a mongoDB database.
The example consists in a Hotel’s single page web application from where we...
-
Migrating Spring MVC RESTful web services to Spring 4
mongoDB, Spring, Spring MVC ·Spring 4 brings several improvements for MVC applications. In this post I will focus on restful web services and try these improvements by performing a migration from Spring MVC 3.2 to Spring 4.0. We will take a project implemented with Spring 3.2 and perform the steps to upgrade it to Spring 4.0. The following points sum up the...
-
Applying aspect oriented programming
AOP, Spring, Spring MVC ·This article explains how to apply aspect oriented programming with Spring AOP. The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns we are referring to generic functionality that is used in several places in our system or application.
These concepts are, among others:
- Logging
- Transaction management
- Error handling ...
-
Centralize validation and exception handling with @ControllerAdvice
Spring, Spring MVC ·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...
-
Accessing Restful services. HTTP Message converters
Spring, Spring MVC ·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
- ResourceHttpMessageConverter
- SourceHttpMessageConverter
- AllEncompassingFormHttpMessageConverter
<span... -
Create and test REST services with Spring MVC
Spring, Spring MVC ·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...
Java
-
Grouping, transforming and reduction with Java 8
Java, Java8 ·In this previous post, I wrote about how we can group collections of objects with streams and grouping. This is useful but does not cover specific use cases. For example, sometimes we do not only need to group things but also transform the result into a more appropriate object.
In this post, we will learn how to...
-
Multi level grouping with streams
Java, Java8 ·With Java 8 streams it is pretty easy to group collections of objects based on different criteria. In this post, we will see how we can make stream grouping, from simple single level groupings to more complex, involving several levels of groupings.
We will use two classes to represent the objects we want to group by: person and pet.
Person.class
…
-
Improving performance: non-blocking processing of streams
Concurrency, Java, Java8 ·Imagine we have an application that needs to access an external web service in order to gather information about clients and then process it. More specifically, we can’t get all this information in a single invocation. If we want to look up different clients, we will need several invocations.
As shown in the graphic below, the example application will retrieve...
-
Java Concurrency Tutorial – Locking: Explicit locks
Concurrency, Java ·In many cases, using implicit locking is enough. Other times, we will need more complex functionalities. In such cases, java.util.concurrent.locks package provides us with lock objects. When it comes to memory synchronization, the internal mechanism of these locks is the same as with implicit locks. The difference is that explicit locks offer additional features.
The main advantages or improvements over...
-
Java Concurrency Tutorial – Locking: Intrinsic locks
Concurrency, Java ·In previous posts we reviewed some of the main risks of sharing data between different threads (like atomicity and visibility). Additionally, we learnt how to design classes in order to be shared safely (thread safe designs). In many situations though, we will need to share mutable data, where some threads will...
-
Java Concurrency Tutorial
Concurrency, Java ·This Java concurrency tutorial consists of several posts that explain the main concepts of concurrency in Java. It starts with the basics with posts about the main concerns or risks of using non synchronised programs.
This tutorial consists on two main areas:
- Basic concepts about how concurrency works
- This section explains different synchronisation mechanisms
Therefore, each section concept...
-
Java Concurrency Tutorial – Thread-safe designs
Concurrency, Java ·After reviewing what the main risks are when dealing with concurrent programs (like atomicity or visibility), we will go through some class designs that will help us prevent the aforementioned bugs. Some of these designs result in the construction of thread-safe concurrency solutions. This will allow us to share objects safely between threads. As...
-
Java Concurrency Tutorial – Visibility between threads
Concurrency, Java ·When sharing an object’s state between different threads, other issues besides atomicity come into play. One of them is visibility between threads.
The key fact is that without synchronization, instructions are not guaranteed to be executed in the order in which they appear in your source code. This won’t affect the result in a single-threaded program but,...
-
Java Concurrency Tutorial – Atomicity and race conditions
Concurrency, Java ·Atomicity and race conditions is one of the key concepts in multi-threaded programs. We say a set of actions is atomic if they all execute as a single operation, in an indivisible manner. Taking for granted that a set of actions in a multi-threaded program will be executed serially may lead to incorrect results. The reason is due to thread...
-
Handling different subresources with JAX-RS subresource locator
Java, REST ·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 locator will decide at runtime what...
-
Unit testing with PowerMock
Java, Test ·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 use Maven, you can add the following...
Test
-
Unit testing with PowerMock
Java, Test ·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 use Maven, you can add the following...
REST
-
Handling different subresources with JAX-RS subresource locator
Java, REST ·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 locator will decide at runtime what...
AOP
-
Applying aspect oriented programming
AOP, Spring, Spring MVC ·This article explains how to apply aspect oriented programming with Spring AOP. The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns we are referring to generic functionality that is used in several places in our system or application.
These concepts are, among others:
- Logging
- Transaction management
- Error handling ...
Integration
-
Making queries on demand: MongoDB outbound gateway
Integration, mongoDB, Spring, Spring-Boot ·In order to read data from MongoDb, Spring Integration comes with the MongoDb inbound channel adapter. This adapter uses a poller to continuously retrieve documents from the database. However, sometimes we may need to query the database on demand, based on the result of another endpoint.
Taking advantage of Spring’s extensibility, I implemented a MongoDb outbound gateway. The purpose of...
-
Spring Integration MongoDB adapters with Java DSL
Integration, mongoDB, Spring, Spring-Boot ·This post explains how to save and retrieve entities from a MongoDB database using Spring Integration. In order to accomplish that, we are going to configure inbound and outbound MongoDB channel adapters using the Java DSL configuration extension. As an example, we are going to build an application to allow you to write orders to a MongoDB store, and then...
-
Spring Integration – Polling file creation and modification
Integration, Spring, Spring-Boot ·File support is another of Spring Integration’s endpoints to communicate with external systems. In this case, it provides several components to read, write and transform files. During this post, we are going to write an application which monitors a directory in order to read all files in there. In concrete it does the following:
- When the application starts, it...
-
Exposing HTTP Restful API with Inbound Adapters. Part 2 (Java DSL)
Integration, Spring ·In the previous part of this tutorial, we implemented an application exposing a Restful API using XML configuration. This part will re-implement this application using Spring Integration Java DSL.
The application is implemented with Java 8, but when Java 8 specific code is used (for example, when using lambdas), I will also show you how to do it...
-
Exposing HTTP Restful API with Inbound Adapters. Part 1 (XML)
Integration, Spring ·The purpose of this post is to implement an HTTP Restful API using Spring Integration HTTP inbound adapters. This tutorial is divided into two parts:
- XML configuration example (this same post).
- Java DSL example. This will be explained in the next part of this tutorial, showing how to configure the application using Spring...
-
Spring Integration 4.0: A complete XML-free example
Integration, mongoDB, Spring, Spring WS ·Spring Integration 4.0 is finally here, and this release comes with very nice features. The one covered in this article is the possibility to configure an integration flow without using XML at all. Those people that don’t like XML will be able to develop an integration application with just using JavaConfig.This... -
Spring Integration – Configure web service client timeout
Integration, Spring, web services ·With the support of Spring Integration, your application can invoke a web service by using an outbound web service gateway. The invocation is handled by this gateway. Hence, you just need to worry about building the request message and handling the response. However, with this approach it is not obvious how to configure additional options like setting timeouts or caching...
-
Retry web service operations with RequestHandlerRetryAdvice
Integration, mongoDB, Spring ·Sometimes when invoking a web service, we may be interested in retrying the operation in case an error occurs. When using Spring Integration, we can achieve this functionality with RequestHandlerRetryAdvice class. This class will allow us to retry the operation for a specified number of times before giving up and throwing an exception. This post will show...
-
How error handling works in Spring Integration
Integration, Spring ·The target of this post is to show you how error handling works in Spring Integration, using the messaging system. You will see that error handling is different between synchronous and asynchronous messaging. As usual, I’ll skip the chat and proceed with some examples.
You can get the source code at my Github repository
1 The...
-
Spring Integration – Using RMI Channel Adapters
Integration, Spring ·This article explains how to send and receive messages over RMI using Spring Integration RMI channel adapters. It is composed of the following sections:
- Implement the service: The first section focuses on creating and exposing a service.
- Implement the client: Shows how to invoke the service using the MessagingTemplate class.
- Abstracting SI logic: Finally, I’ve added another section explaining...
-
Processing messages in transactions with Spring JMS
Integration, Spring, Spring JMS ·This post shows how to process messages in transactions with Spring JMS. We will see how an error in the execution of the consumer during the asynchronous reception of messages with JMS, can lead to the loss of messages. I then will explain how you can solve this problem using local transactions.
You will also see that this solution can...
-
Introduction to messaging with Spring JMS
Integration, Spring, Spring JMS ·In this post I will show you how to configure a standalone application in order to see different ways of sending and receiving messages using Spring JMS. Basically, I will divide the examples into the following sections:
- Point-to-point messaging (queue)
- Synchronous reception
- Asynchronous reception
- Publish-subscribe messaging (topic)
The source code with all the examples shown...
- Point-to-point messaging (queue)
Spring JMS
-
Configure a Spring JMS application with Spring Boot and annotation support
Spring, Spring JMS, Spring-Boot ·In previous posts we learned how to configure a project using Spring JMS. If you check the article introduction to messaging with Spring JMS, you will notice that it is configured using XML. This article will take advantage of the improvements introduced in Spring 4.1 version, and configure a Spring JMS application with Spring...
-
Processing messages in transactions with Spring JMS
Integration, Spring, Spring JMS ·This post shows how to process messages in transactions with Spring JMS. We will see how an error in the execution of the consumer during the asynchronous reception of messages with JMS, can lead to the loss of messages. I then will explain how you can solve this problem using local transactions.
You will also see that this solution can...
-
Introduction to messaging with Spring JMS
Integration, Spring, Spring JMS ·In this post I will show you how to configure a standalone application in order to see different ways of sending and receiving messages using Spring JMS. Basically, I will divide the examples into the following sections:
- Point-to-point messaging (queue)
- Synchronous reception
- Asynchronous reception
- Publish-subscribe messaging (topic)
The source code with all the examples shown...
- Point-to-point messaging (queue)
Spring WS
-
Spring Integration 4.0: A complete XML-free example
Integration, mongoDB, Spring, Spring WS ·Spring Integration 4.0 is finally here, and this release comes with very nice features. The one covered in this article is the possibility to configure an integration flow without using XML at all. Those people that don’t like XML will be able to develop an integration application with just using JavaConfig.This... -
Creating contract-first web services with Spring WS
Spring, Spring WS ·This article explains how to implement and test SOAP web services with Spring WS project. This example uses JAXB2 for (un)marshalling. To develop the service, I’ll use the contract-first approach, which consists in defining the service contract first, and based on this contract implement the service.
The article is divided into the following sections:
2 ...
mongoDB
-
Making queries on demand: MongoDB outbound gateway
Integration, mongoDB, Spring, Spring-Boot ·In order to read data from MongoDb, Spring Integration comes with the MongoDb inbound channel adapter. This adapter uses a poller to continuously retrieve documents from the database. However, sometimes we may need to query the database on demand, based on the result of another endpoint.
Taking advantage of Spring’s extensibility, I implemented a MongoDb outbound gateway. The purpose of...
-
Spring Integration MongoDB adapters with Java DSL
Integration, mongoDB, Spring, Spring-Boot ·This post explains how to save and retrieve entities from a MongoDB database using Spring Integration. In order to accomplish that, we are going to configure inbound and outbound MongoDB channel adapters using the Java DSL configuration extension. As an example, we are going to build an application to allow you to write orders to a MongoDB store, and then...
-
Data Aggregation Spring Data MongoDB: Nested results
mongoDB, Spring ·In a previous post, we built a basic example of an aggregation pipeline. Maybe you want to take a look at Data aggregation with Spring Data MongoDB and Spring Boot if you need more detail about how to create the project and configure the application. In this post, we will focus on learning a use case where it makes...
-
Data aggregation with Spring Data MongoDB and Spring Boot
mongoDB, Spring, Spring-Boot, Spring-Data ·MongoDB aggregation framework is designed for grouping documents and transforming them into an aggregated result. The aggregation query consists in defining several stages that will be executed in a pipeline. If you are interested in more in-depth details about the framework, then mongodb docs are a good point to start.
The point of this post is to...
-
Spring Integration 4.0: A complete XML-free example
Integration, mongoDB, Spring, Spring WS ·Spring Integration 4.0 is finally here, and this release comes with very nice features. The one covered in this article is the possibility to configure an integration flow without using XML at all. Those people that don’t like XML will be able to develop an integration application with just using JavaConfig.This... -
Thymeleaf integration with Spring (Part 2)
mongoDB, Spring, Spring MVC, Thymeleaf ·This is the second part of the Thymeleaf integration with Spring tutorial. You can read the first part here, where you will learn how to configure this project.
As explained at the beginning of the first part of this tutorial, the web application will send two types of requests:
-
Insert a new guest: Sends a...
-
-
Thymeleaf integration with Spring (Part 1)
mongoDB, Spring, Spring MVC, Thymeleaf ·This article is focused on how Thymeleaf can be integrated with the Spring framework. This will let our MVC web application take advantage of Thymeleaf HTML5 template engine without losing any of the Spring features. The data layer uses Spring Data to interact with a mongoDB database.
The example consists in a Hotel’s single page web application from where we...
-
Migrating Spring MVC RESTful web services to Spring 4
mongoDB, Spring, Spring MVC ·Spring 4 brings several improvements for MVC applications. In this post I will focus on restful web services and try these improvements by performing a migration from Spring MVC 3.2 to Spring 4.0. We will take a project implemented with Spring 3.2 and perform the steps to upgrade it to Spring 4.0. The following points sum up the...
-
Retry web service operations with RequestHandlerRetryAdvice
Integration, mongoDB, Spring ·Sometimes when invoking a web service, we may be interested in retrying the operation in case an error occurs. When using Spring Integration, we can achieve this functionality with RequestHandlerRetryAdvice class. This class will allow us to retry the operation for a specified number of times before giving up and throwing an exception. This post will show...
Thymeleaf
-
Thymeleaf integration with Spring (Part 2)
mongoDB, Spring, Spring MVC, Thymeleaf ·This is the second part of the Thymeleaf integration with Spring tutorial. You can read the first part here, where you will learn how to configure this project.
As explained at the beginning of the first part of this tutorial, the web application will send two types of requests:
-
Insert a new guest: Sends a...
-
-
Thymeleaf integration with Spring (Part 1)
mongoDB, Spring, Spring MVC, Thymeleaf ·This article is focused on how Thymeleaf can be integrated with the Spring framework. This will let our MVC web application take advantage of Thymeleaf HTML5 template engine without losing any of the Spring features. The data layer uses Spring Data to interact with a mongoDB database.
The example consists in a Hotel’s single page web application from where we...
web services
-
Spring Integration – Configure web service client timeout
Integration, Spring, web services ·With the support of Spring Integration, your application can invoke a web service by using an outbound web service gateway. The invocation is handled by this gateway. Hence, you just need to worry about building the request message and handling the response. However, with this approach it is not obvious how to configure additional options like setting timeouts or caching...
Concurrency
-
Improving performance: non-blocking processing of streams
Concurrency, Java, Java8 ·Imagine we have an application that needs to access an external web service in order to gather information about clients and then process it. More specifically, we can’t get all this information in a single invocation. If we want to look up different clients, we will need several invocations.
As shown in the graphic below, the example application will retrieve...
-
Java Concurrency Tutorial – Locking: Explicit locks
Concurrency, Java ·In many cases, using implicit locking is enough. Other times, we will need more complex functionalities. In such cases, java.util.concurrent.locks package provides us with lock objects. When it comes to memory synchronization, the internal mechanism of these locks is the same as with implicit locks. The difference is that explicit locks offer additional features.
The main advantages or improvements over...
-
Java Concurrency Tutorial – Locking: Intrinsic locks
Concurrency, Java ·In previous posts we reviewed some of the main risks of sharing data between different threads (like atomicity and visibility). Additionally, we learnt how to design classes in order to be shared safely (thread safe designs). In many situations though, we will need to share mutable data, where some threads will...
-
Java Concurrency Tutorial
Concurrency, Java ·This Java concurrency tutorial consists of several posts that explain the main concepts of concurrency in Java. It starts with the basics with posts about the main concerns or risks of using non synchronised programs.
This tutorial consists on two main areas:
- Basic concepts about how concurrency works
- This section explains different synchronisation mechanisms
Therefore, each section concept...
-
Java Concurrency Tutorial – Thread-safe designs
Concurrency, Java ·After reviewing what the main risks are when dealing with concurrent programs (like atomicity or visibility), we will go through some class designs that will help us prevent the aforementioned bugs. Some of these designs result in the construction of thread-safe concurrency solutions. This will allow us to share objects safely between threads. As...
-
Java Concurrency Tutorial – Visibility between threads
Concurrency, Java ·When sharing an object’s state between different threads, other issues besides atomicity come into play. One of them is visibility between threads.
The key fact is that without synchronization, instructions are not guaranteed to be executed in the order in which they appear in your source code. This won’t affect the result in a single-threaded program but,...
-
Java Concurrency Tutorial – Atomicity and race conditions
Concurrency, Java ·Atomicity and race conditions is one of the key concepts in multi-threaded programs. We say a set of actions is atomic if they all execute as a single operation, in an indivisible manner. Taking for granted that a set of actions in a multi-threaded program will be executed serially may lead to incorrect results. The reason is due to thread...
Java8
-
Grouping, transforming and reduction with Java 8
Java, Java8 ·In this previous post, I wrote about how we can group collections of objects with streams and grouping. This is useful but does not cover specific use cases. For example, sometimes we do not only need to group things but also transform the result into a more appropriate object.
In this post, we will learn how to...
-
Multi level grouping with streams
Java, Java8 ·With Java 8 streams it is pretty easy to group collections of objects based on different criteria. In this post, we will see how we can make stream grouping, from simple single level groupings to more complex, involving several levels of groupings.
We will use two classes to represent the objects we want to group by: person and pet.
Person.class
…
-
Improving performance: non-blocking processing of streams
Concurrency, Java, Java8 ·Imagine we have an application that needs to access an external web service in order to gather information about clients and then process it. More specifically, we can’t get all this information in a single invocation. If we want to look up different clients, we will need several invocations.
As shown in the graphic below, the example application will retrieve...
Spring-Boot
-
Making queries on demand: MongoDB outbound gateway
Integration, mongoDB, Spring, Spring-Boot ·In order to read data from MongoDb, Spring Integration comes with the MongoDb inbound channel adapter. This adapter uses a poller to continuously retrieve documents from the database. However, sometimes we may need to query the database on demand, based on the result of another endpoint.
Taking advantage of Spring’s extensibility, I implemented a MongoDb outbound gateway. The purpose of...
-
Spring Integration MongoDB adapters with Java DSL
Integration, mongoDB, Spring, Spring-Boot ·This post explains how to save and retrieve entities from a MongoDB database using Spring Integration. In order to accomplish that, we are going to configure inbound and outbound MongoDB channel adapters using the Java DSL configuration extension. As an example, we are going to build an application to allow you to write orders to a MongoDB store, and then...
-
Spring Integration – Polling file creation and modification
Integration, Spring, Spring-Boot ·File support is another of Spring Integration’s endpoints to communicate with external systems. In this case, it provides several components to read, write and transform files. During this post, we are going to write an application which monitors a directory in order to read all files in there. In concrete it does the following:
- When the application starts, it...
-
Data aggregation with Spring Data MongoDB and Spring Boot
mongoDB, Spring, Spring-Boot, Spring-Data ·MongoDB aggregation framework is designed for grouping documents and transforming them into an aggregated result. The aggregation query consists in defining several stages that will be executed in a pipeline. If you are interested in more in-depth details about the framework, then mongodb docs are a good point to start.
The point of this post is to...
-
Understanding Callable and Spring DeferredResult
Spring, Spring MVC, Spring-Boot ·Asynchronous support introduced in Servlet 3.0 offers the possibility to process an HTTP request in another thread. This is specially interesting when you have a long running task, since while another thread processes this request, the container thread is freed and can continue serving other requests.
This topic has been explained many times, but there seems to be a little...
-
Configure a Spring JMS application with Spring Boot and annotation support
Spring, Spring JMS, Spring-Boot ·In previous posts we learned how to configure a project using Spring JMS. If you check the article introduction to messaging with Spring JMS, you will notice that it is configured using XML. This article will take advantage of the improvements introduced in Spring 4.1 version, and configure a Spring JMS application with Spring...
Spring-Data
-
Data aggregation with Spring Data MongoDB and Spring Boot
mongoDB, Spring, Spring-Boot, Spring-Data ·MongoDB aggregation framework is designed for grouping documents and transforming them into an aggregated result. The aggregation query consists in defining several stages that will be executed in a pipeline. If you are interested in more in-depth details about the framework, then mongodb docs are a good point to start.
The point of this post is to...