Posts

Showing posts from May, 2020

AEM Scheduler

Image
AEM Scheduler is a service which is used to schedule jobs in AEM Application. We can write a scheduler service in AEM by two different ways. 1:- Using Scheduler API 2:- Using Whiteboard Pattern We can create our scheduler class using SCR Annotaions or using New OSGi R6 Annotaions. From AEM 6.2 SCR Annotations are deprecated now.So we will only use OSGi Annotaions to create our scheduler. Writing scheduler class using Whiteboard Pattern:- In this case we will use the normal Java thread API to schedule a job. In example below we are scheduling a job for every 2 seconds. We have given cron expression as */2 * * * * ?. We can take help of  http://www.cronmaker.com/  to create your cron expression easily. package com.adobe.aem.saurabhaem.core.schedulers; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.metatype.annotations.AttributeDefinition; import org.osgi.ser

Event Handling in AEM

There are multiple ways of handling events in AEM. All the methods have their own pros &cons. 1:- JCR Level Event Handling Using Event Listener 2:- Sling Level using Event Handlers 3:  Workflows & Launchers 4:- Using Scheduler Service Handling  JCR Level Event u sing Event Listener:- This is the lowest level event handling which listens to below JCR level events When a node was added When a node was moved When a node was deleted When a property was added to a node When a property was changed When a property was deleted We can write a custom  handler to handle these  events by implementing  javax.jcr.observation. EventListener   interface & registering an event using ObservationManager object. ObservationManager allows for the registration and deregistration of event listeners.It has methods like :- 1:- addEventListener(EventListener listener, int eventTypes, java.lang.String absPath, boolean isDeep, java.lang.String[] uuid, java.lang.String[] node

AEM Sling Servlet

Image
We can register our servlet as an OSGI service in AEM. There are two types of Servlet supported in AEM. 1:- Sling Safe Methods Servlet (GET, HEAD):-    Servlet implementation that responds to “Safe” HTTP Requests. It is a Read only Implementation & only supports GET &Head method. java.lang.Object javax.servlet.GenericServlet org.apache.sling.api.servlets.SlingSafeMethodsServlet public class DemoServlet extends SlingSafeMethodsServlet 2:- Sling All Methods Servlet (GET, HEAD, POST, PUT, DELETE):-  Servlet implementation that responds to all HTTP methods. Primarily used for POST Requests. java.lang.Object javax.servlet.GenericServlet org.apache.sling.api.servlets.SlingSafeMethodsServlet org.apache.sling.api.servlets.SlingAllMethodsServlet public class DemoServlet extends SlingAllMethodsServlet How to declare Sling Servlet in AEM:- There are couple of ways to declare sling servlet in AEM. 1:- Old way of declaring Sli