Skip to content

Logging in ATG: how to send error reports to Elasticsearch and display them with Kibana

 

Oracle ATG logging: sending reports to Elasticsearch, displaying errors with KibanaIn this article, I’m going to share my experience with Oracle ATG logging system and such great tools like Elasticsearch and Kibana. Imagine that we have a big ATG-based project and our task is to store and list all the users who met (explicitly or not) errors. To solve this task we will add a new event listener to filter errors, will face a problem with resolving users’ profile from the listener, will send an error report to an Elasticsearch server and finally display the data with Kibana.

Although this article describes creating ATG-specific logging feature, it will be quite easy to adjust this tutorial for using with Slf4j or whatever you want.

Elasticsearch and Kibana are part of so-called ELK stack. Letter “L” stands for Logstash, which is a great tool that crawls data from multiple sources, transforms it and sends to a target (e.g. file or Elasticsearch). However, I decided not to use Logstash here, because Elasticsearch provides a good API which is enough for this task.

So, let’s get started.

Read More →

Using one DateFormat instance per thread with ThreadLocal

DateFormat with ThreadLocal

Here is a quick tip how to use DateFormat inside a ThreadLocal field.
Why do we need that? The reason is the DateFormat class is not thread-safe but creating its instances is an expensive operation. So, this is kind of a workaround that creates only one instance of DateFormat per thread.

package com.imsavva.test;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Savva Kodeikin
 */
public class ThreadLocalDateFormatTest   {

    private static ThreadLocal<SimpleDateFormat> dateFormat = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat("dd/MM/yyyy");
        }
    };

    public String formatDate(Date date) {
        return dateFormat.get().format(date);
    }
}

UnhandledExceptionHandler in Java: how to catch uncaught exceptions

UncaughtExceptionHandler in Java

In this short tutorial, I’m going to describe how to handle uncaught exceptions in threads. This can be done by:

  • Using threadInstance.setUncaughtExceptionHandler() ─ for a specific thread
  • Overriding ThreadGroup’s uncaughtException() method ─ for a thread group
  • Using Thread.setDefaultUncaughtExceptionHandler() ─ for all threads

If you’re interested in how to implement this, press “read more”, I’ve prepared an example.

Read More →

How to lookup a user profile from a global-scoped ATG component

How to access current user from a global scoped component in ATG

This article describes how to look up a session-scoped user profile component from a global scope component that has no access to a DynamoHttpServletRequest object. To achieve this functionality, we will use a ThreadLocal field an ATG feature called Insertable Servlet. When a request object is created, it goes through a pipeline of Insertable Servlets. We are going to create our own implementation of Insertable Servlet by extending atg.servlet.pipeline.InsertableServletImpl which will store current request to a ThreadLocal variable via a helper class (e.g. RequestContainer). Then, we’re going to inject this RequestContainer in every component that needs to look up the profile (or other components).

Here is the code.

Read More →

Azure Window collapses in Malta

Three days ago a natural arch called Azure Window collapsed in Gozo, Malta. This arch was included on Malta’s tentative list of UNESCO World Heritage Sites. It was used as background in some well-known movies such as the Game of Thrones and the Count of Monte-Cristo. It was also a famous place for tourists, so thousands of photos were taken there.

Game of Thrones - Azure Window Malta

I also have a pic standing in front of it ☺️

Read More →

Parsing a date string to ISO8601 with Joda Time

Recently, I faced a date conversion task: convert a string date “yyyy-MM-ddZ” (i.e. “1983-09-15+03:00”) to the ISO8601 standard “yyyy-MM-dd’T’HH:mm:ss.SSSZ” (i.e. “1983-09-15T03:00:00.000+03:00”).

I used Apache Joda time to convert date. First, add a Maven dependency in pom.xml

<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.9.4</version>
</dependency>

Read More →