My Perception of the System

SM is a very adaptive system. You can configure it how to handle a message. The message should be handled by settings applied to each message sender.

It allows you to plugin a new module to process the message.

It always does a set of operations regardless which message senders’s message it’s processing.

This gives me a mix feelings of having a template method to give a skeleton how to process a message. Then for each abstract method you may apply a chain of responsibility and strategy patterns.

Another important problem is we want to separate an execution (one component execute) from a presentation (one component gives a result). So, we’re going to look at a command pattern.

A Problem Domain

From now we call an incoming message to our system, a SM message. Each SM message is a command.

(Facts: it can be commands inside a command, we don’t know yet if the SM message has this characteristic. And, if it has we may need to look at a chain of responsibility pattern.)

Commons’ Chain Of Responsibility

Below is a list of the five keys interfaces using in the Chain Of Responsibility package

  • Context – a stateful object representing the current state of an application
  • Command
  • Chain.Chain
  • Filter
  • Catalog

Thought Note

I feel it went well at work today.

I am still behind my plan, slow at writing codes.

But I have good understanding of what I did today, I learned something new, I had good discussions with my team, I learned a junior colleague and at the same time learned myself how to work and help others.

When something goes well, I want to continue. I feel fun and like what happened.

When I get stuck, I still want to continue and want to beat the problems.

I sat with a project manager today, I don’t think I want to have her job.

Is it because what I’m doing is considered to be a strategic product and innovation at my department? I feel important and am doing something important.

Is it activities? I lead development, provide architecture, practice agile activities.

Is it atmosphere at work? Now, I have a team, work with others, have freedom to choose technology and working sets.

Last thought

Can everyone be a teacher?

It would be cool if I can teach junior developers to built a system.


I get stuck on writing a unit test for a Camel route for 2 days now.

Before I shut down my computer today, I got a green light on my unit test but it doesn’t feel I’m thorough with the subject.

Unit testing a Camel route should not be difficult but I hardly find a good solution/example to my problem.

There are too many ways to unit test the Camel route which requires more time to read and understand the subject.

What I learned on August 6th,

Add Camel and ActiveMQ to a Spring Boot application


From version 2.22.0 Camel supports Spring Boot 2.0.x. With a camel-spring-boot-starter dependency, when you write a route, it allows you to annotate your class with a @Component annotation. Spring will auto scan and instantiate the route and add it to a CamelContext.


Add Camel’s features for ActiveMQ to your Camel project. activemq-broker.jar is excluded since we’re going to connect to a standalone ActiveMQ broker.

	<!-- version>5.14.0</version -->

Add Spring’s supports and infrastructure to connect to ActiveMQ broker.


activemq-broker.jar is provided at runtime when connecting to a standalone ActiveMQ broker.


Create a Camel route

public class MyCamelRoute extends RouteBuilder {
	public void configure() throws Exception {
			.setBody(constant("Hello from Camel"))

Now you’re good to run the application.

Secure Restful Web Services

What do we want to solve?

We are going to impleument a bunch of RESTful web services. Some services are consumed internally and some are consumed by Internet users.

For internal clients, we want to use HTTP basic authentication to keep implementation simple. For Internet users, we want to use Swedish BankID, Google or Facebook account as a means to authenticate the users.


Study Spring Security, how to implement the requirements above.


Write a Unit Test for Spring Boot REST Web Services

Note: A purpose of this post is to repeat knowledge on how to unit test Restful web services in a Spring Boot applications.

What do you need to know when making a REST web request

A GET request

  • username and password or a token for authentication
  • a service URL
  • request parameters
  • some required HTTP headers

What do you need when running a test

From a list of what you need to know to be able to make a request, it defines how you gonna write your unit test

In our unit test, we want to test a @RestController component. The controller uses a @Service component which we want to ignore. Therefore, we mock the @Service component.

Below is what we need to do to create a unit test

Load a test context

Since it is a Spring Boot application, we are going to use test support functionality provided by Spring Boot and Spring Test framework

@RunWith (SpringRunner.class)

Launch the controller under test

@WebMvcTest (value = StudentController.class, secure = false)

Mock components that are not under test

The StudentController uses the service StudentService but we’re not going to test the StudentService. Therefore, we mock it.

@MockBean StudentService studentService;

@MockBean will inject a StudentService instance into an ApplicationContext.

Mockito.when(studentService.retrieveCourse(Mockito.anyString(), Mockito.anyString())).thenReturn(mockCourse);

Build a request

Use MockMvcRequestBuilders

RequestBuilder rb = MockMvcRequestBuilders.get("/students/Student1/courses/Course1").accept(MediaType.APPLICATION_JSON);

Build an expected response

String expected = "{id:Course1,name:Spring,description:\"10 Steps\"}";

Make a call

@Autowired private MockMvc mockMvc;
MvcResult result = mockMvc.perform(rb).andReturn();

Verify the result


JSONAssert.assertEquals(expected, result.getResponse().getContentAsString(), false);

In-memory Database: H2

You’re never too old to learn

I use H2 as a database when I refresh my knowledge about JPA (Java Persistence API). Therefore, I think to write a little bit about H2 database and how to use H2 as a database in your Spring Boot application.

Note: A purpose of this post is to help me review what I have learned. As I am old and start to have bad memories.

What is H2?

H2 is a relational database management system written in Java.

Enable H2 database in Spring Boot application


Enable H2 console

Configure the following properties in at src/main/resources

# H2

Persistent, embedded database

Configure the following properties in

# Datasource