Posts

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

Diff between jcr:primaryType and jcr:mixinTypes

Image
There are two categories of node types, primary and mixin. Every node has a primary node type assigned to it upon creation. In addition, a mixin node type may be added to a node later in its lifecycle. The primary node type of a node usually defines node structure (i.e., allowed and required child nodes and properties) & Mixin node types usually specify additional properties or child nodes related to a capability being added to the node. These capabilities may include generic repository-level functions as in the case of the built-in mixins mix:versionable and mix:lockable, for example, or domain-level capabilities such as a (hypothetical) myapp:Emailable mixin type that adds the property myapp:emailAddress to a node. Below are some noticeable differences in both. 1:- Mixin Types are similar to interfaces, one node could have multiple mixin types.You can think of it as interfaces in Object Oriented world since a node can have multiple ones and they aim to add aditionnal pro

Sling Models

Image
Introduction: Sling models are released as part of aem 6.0. Sling Models are simple POJO classes which are mapped automatically with Sling Objects (resource, request objects.) and allow us to access jcr node property values directly into java classes. Features of Sling Models: - Pure POJO classes.   Entirely annotation driven (Need to write less code).   Can adapt multiple objects –  – minimal required Resource and SlingHttpServletRequest   OOTB, support resource properties (via ValueMap), SlingBindings, OSGi services, request attributes Support both classes and interfaces. Work with existing Sling infrastructure (i.e. not require changes to other bundles). Using Sling Models, you can do more with less code so you can reduce your coding efforts. Your code is more maintainable using Sling Modes. There are lot of ways to accomplish the component backend logic like JSP,Server Side Javascript,WCMuse,WCMUsePOJO. However, with the release of AEM 6.3 and AEM Core WCM Co