Posts

Showing posts from 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

Useful tips...Part1

Image
How to save credentials in Git? When we pull or push in repository using git bash or command line it asks us for user name & password every time.This seems very irritating to input it every time. To avoid this we can save our credentials in Git using below steps. 1: Give  below command $ git config credential.helper store 2: Now use command git pull 3: You will see that Git will ask you for entering user name & password. Provide username & password. Same user name & password will be saved inside git. 4: Again try git pull & you will notice that it will not prompt you for user name & password. It will use the credentials which we have saved in step 3. 5: Git stores credentials in text file named  .git-credentials  inside C:\Users\your-window-user How to rebuild client Libraries in AEM? In some scenarios when we have problem while building the client libraries,we may need to rebuild our client libraries manually. One such scenario is th

AEM Run Modes

Image
Run modes play an important role in aem. Run modes maps to an AEM instance. They are useful in case we want to provide diff configurations & logic based on the environments. Refer below link to learn about run modes in details. https://helpx.adobe.com/in/experience-manager/6-4/sites/deploying/using/configure-runmodes.html How to check the run mode of an AEM Server. Go to Felix Console . Go to Status tab in Navigation and click on sling settings option . Here you can see the Run Modes Direct link for accessing the same is http://localhost:4502/system/console/status-slingsettings To access AEM run modes in Sightly(HTL):- There is a way to read run modes in sightly which can be further used to write your logic based on  environments. Suppose there is a use-case where you want to display some warnings/messages based on the environment then you can easily do it in sightly without writing any logic in sling models or wcmusepojo. Here we are using