7 Exercises

7.1 Differentiate Between a Domain and Technical Log

In section 3.4, we used a producer method to introduce a logger. In practice, it’s not unusual for developers to create two or more different loggers. We might, for example, create one for operational messages (e.g. Campaign added) and one for technical messages (e.g. Database not accessible).

To implement this for an application, proceed as follows:

  1. Create two qualifiers called DomainLog and TecLog in the package press.turngeek.mycampaign.util.
  2. Replace the producer method for the logger with one producer method annotated with @DomainLog and another annotated with @TecLog. To differentiate between the loggers, add two different prefixes to the String parameter of the getLogger method: once, String “DomainLog:” and once, “TecLog:”.
  3. Annotate the logger of the DonateMoneyController bean with @DomainLog.
  4. Inject a logger in the CampaignServiceBean and annotate it with @TecLog. Use this logger to issue a message in the method getAllCampaigns.

7.2 Add a Message for the Updating of a Campaign

In chapter 4, we learned how to send application-wide messages. Currently, messages are sent whenever a campaign is added or deleted. We might also need a message to be sent when a campaign is updated.

To help us achieve a better understanding of CDI events, we can try sending this message now as practise. Proceed as follows:

  1. Modify the class Events by adding the qualifier Updated.
  2. Send the message at the appropriate place in the EditCampaignController.
  3. Create an observer method onCampaignUpdated in the CampaignListProducer. Since this method cannot yet be fully implemented, it should be used solely to issue a message via a logger.


Use the message board below to give the authors your feedback or to discuss this page’s topic with other readers (in English please!). Please don’t expect the authors to answer directly, but they might update the content of this site according to your feedback.