CDI (Context and dependency injection) is a great specification introduced in the JEE6 that offers a lot of resources. One of them is the Producer methods, and we’ll be talking about it in this post.
CDI Producer can be used in some scenarios, such as:
- Making Non-CDI beans eligible to be injected into other CDI beans. You may be using some library that doesn’t expose their beans via CDI but you want to inject them in your CDI beans by convenience.
- You have a bean that requires a constructor with some argument.
Continue reading “CDI Producer” →
I have recently published a course called “Build an application from scratch: JEE 7, Java 8 and Wildfly” on Udemy. This course is all about using a lot of recent and important Java technologies and best practices of software development in order to create a complete enterprise application. Some of the technologies and tools covered are:
- Java EE 7: JPA 2.1, Bean Validation 1.1, JMS 2.0, EJB 3.2, CDI 1.1, JAX-RS 2.0, security.
- Java 8: Lambda expressions, Date and Time API, streams and more.
- Libraries such as Gson, JUnit, Mockito and Hamcrest.
- Arquillian for integration tests.
- Wildfly 8 (former JBoss) as Application Server.
- PostgreSQL for production and HSQLDB/H2 for unit and integration tests.
- Eclipse IDE (this is a Maven project, so you can use other IDE).
- Postman Chrome extension to test all our REST endpoints.
If you are interested and want to know more details, you can check the course by clicking here. In this page, you can find more details about the course, watch some free videos.
If you have any questions, just let me know.
In this post we will see a brief introduction about the Spock test framework and how to integrate it with Maven and Eclipse.
Spock is a framework used to write tests using the Groovy language and its adoption has been increasing lately. Although Groovy is the language you must use to write your tests with Spcok, it can be used for both Groovy and Java applications and is compatible with most of the Java IDEs, including Eclipse.
The idea of writing the tests using Groovy can be seen as an obstacle for some Java developers that are not familiar with Groovy. However, the knowledge required in Groovy is quite basic and the Spock documentation itself is very helpful with this question. I myself, right now, know very little about Groovy and this hasn’t been an issue to write tests with Spock.
Continue reading “Integrating Spock with Maven/Eclipse” →
Continuing with the subject presented in the first part of this article, let’s talk a little more about asynchronous processing with ExecutorServices. In this second part, let’s approach the following use case.
Our software will receive and process a batch of transactions. After processing this batch, the system must create a “summary” of the processing, pointing individually the number of processed transactions successfully and with error. This summary could be sent to some other system, for example, that could then analyze the success rate of this transactions batch or something like that.
Continue reading “Asynchronous processing with ExecutorServices – Part 2” →
With state-of-the-art machines with a lot of processors, it’s essential that you be able to build software that can get the most out of these resources. What’s the purpose of having a super computer with 16 processors if your software is executed sequentially in a single-thread? Messaging systems, like JMS and AMQP, can be really useful to distribute your processing. However, in some scenarios, these technologies may be overkill, once besides bringing some overhead related to adding a message broker to the architecture, we may just want to efficiently use all the processors of the machine, splitting a task that would be executed in a single-thread in a set of smaller tasks that can be executed in parallel by multiple threads. Prior to Java 5, we had to create/manage manually the Threads, which wasn’t a pleasant task. But with Java 5, things got easier with the new Executor Services.
Continue reading “Asynchronous processing with ExecutorServices – Part 1” →
This post is related to a presentation I gave (in Portuguese) for a Brazilian tech event called TDC (The Developer’s Conference) in 2012. The topic of this presentation was how to use AMQP in a Java application, using the RabbitMQ messaging system and Spring.
You can check the code in the GitHub.
In this post we’ll be talking about a subject that is little explored by most of the developers: Transaction attributes. When we’re creating a service (EJB, Spring..), we can either control the transaction manually (BMT – Bean Managed Transaction) or delegate this responsibility to the container (CMT – Container Managed Transaction). CMT is used in most of the cases and with declarative configuration and it’s for this type of configuration that the transaction attributes exist. They define, for example, if your method must or must not be invoked from within a transactional scope.
Just to make things easier and clearer, the term client in this post means the caller, that can be a standalone application, an EJB, a Spring Service, etc.
Continue reading “Understanding transaction attributes” →
Creating automated tests for JEE applications has always been a challenge, once it requires a running container to provide all the services the application needs to work properly and that the tests need to be executed.
The Arquillian framework was born to make this job a lot easier to be executed. Your main goal is to provide a powerful test platform responsible of taking care of many aspects while testing JEE applications, such as start a container, deploy an application in the container, run the tests and stop the container. It also allows that your test classes can be enriched with annotations like @Inject, @EJB and @Resource, among others. This way, one can easily create real integration tests. Arquillian also allows users to choose either JUnit or TestNG to create and execute the tests, besides allowing the same test cases to be executed in different containers, such as JBoss, Glassfish and Tomcat.
This post’s goal is not to discuss the benefits in writing automated tests -TDD or not- but, instead, focus on how to use Arquillian through a practical example.
Continue reading “Testing JEE6 applications with Arquillian” →
This post will show how to configure a JMS queue on JBoss 7.1.1-Final and how to make use of it through a JEE 6 application. Besides, some aspects regarding transactional session and JMS queue’s number of consumers will also be presented.
This post does not aim to depict JMS in details, but it will give an overview about it.
JMS is part of the Java EE specification and can be considered a MOM (Message Oriented Middleware) which allows clients to exchange asynchronous messages among them.
There are basically two models to exchange messages:
- Queue: It’s a point-to-point on which one side (producer) pushes a message and places it in a JMS queue and the other side (consumer) pulls the message from the queue. This post will be using this model throughout its example.
- Topic: Adopts the publish-subscribe model on which one side (publisher) pushes as message on a JSM topic and, for this topic, there can be 0 or more subscribers that receive all the published messages.
More details can be found on the JEE 6 Tutorial.
Continue reading “JMS queues with JEE6 and JBoss 7” →
This post will describe the steps necessary to configure a JDBC DataSource in JBoss 7. MySQL database and JBoss 7.1.0-Final will be used as example.
Configuring MySQL JDBC driver module
The first big change on JBoss 7 compared to the previous versions is that the libraries to be deployed are no longer considered “libs”, in the sense that all the required work was to copy the .jar files to a specific folder and start using the services provided by that .jar. Any lib is now considered a JBoss module, like the server’s internal services, such as messaging. The following steps are required to configure the MySQL JDBC driver:
Continue reading “Configuring a data source on JBoss 7” →