Sunday, April 16, 2017

All about cq:editConfig

All about cq:editConfig


cq:editConfig is the node with the type cq:editConfig and name cq:editConfig that is defined under the component node. There are different configuration/properties those can be configured with cq:editConfig in order to render the dialog in required way. 

  • cq:layout specifies how the component is edited in classic UI. The possible values are rollover, editbar, auto.
  • cq:dialogMode specifies how the dialog is opened in classic UI. The possible values are floating, rollover and auto.
  • cq:emptyText specifies the text to be displayed when the component is empty.
  • cq:inherit specifies if the values should be inherited from the parent in case they are missing. This can be true or false. 
  • cq:actions specifies the comma separated list of actions those can be performed on the component. This also allow a user to set the label of dialog. These actions are - insert, edit, delete, - , text:value, copymove. All of these should be configued as string array.
cq:editConfig has following child nodes those define the extra behavior configuration for the component. All of these are of the type nt:unstructured except cq:inplaceEditing and cq:listeners which has the type cq:inplaceEditingConfig and cq:editListnersConfig respectively.
  • cq:dropTargets specifies the list of drop targets from the asset finder that can be draged. It should have the child node of cq:dropTargetConfig which has properties - accept, groups and propertyName defined. 
  • cq:actionsConfigs specifies the custom actions that can be defined and listed in cq:actions property of cq:editConfig. For each custom action there should be a new node created under this of type nt:unstructured. This node should have properties like handler and text that defines the action to be performed. handler property can have the ExtJs function.
  • cq:formParameters defines the addtional parameters those are added to the dialog.
  • cq:inplaceEditing defines the inplace editing for the component. The properties those can be configured for this are - active, configPath and editorType. Where in editorType can be text, plaintext, title, begins.
  • cq:listeners specifies the actions those should be taken when the component is changed. The events those are captured by listeners are - beforedelete, beforeedit, beforecopy, beforemove, beforeinsert, beforechildinsert, afterdelete, afteredit, aftercopy, aftermove, afterinsert, afterchildinsert.

AEM 6 Dispatcher Configuration Simplified

AEM 6 Dispatcher configuration


There are two main usage of dispatcher.

1. Load balancing
2. Cache management


Following are the main AEM 6 dispatcher configurations required for cache management that one must have in mind while configuring dispatcher.any file. 

First thing is /name which specifies the name of configuration. Once can select whichever name makes most sense according to the environment in which this is configured.

After /name there should be /farms defined. All the other dispatcher related configurations go inside this one as follows.

/farms
 {
   /website 
     {  
     /clientheaders
       {
       }
     /virtualhosts
       {
       }
     /sessionmanagement 
       {
       }
     /renders
       {
       }
     /filter
       {
       }
     /vanity-urls
       {
       }
     /cache
       {
       /rules
         {
         }
       /invalidate
         {
         }
       }
     /statistics
       {
       /categories
         {
         }
       }
     /stickyConnectionsFor
     /health_check
       {
       }
     /retryDelay
     /numberOfRetries
     /unavailablePenalty
     /failover
     }
}
  • Here /website can be any label like /mysite /abcxyz. This just defines the block of configuration that will be applied on a site.
  • Inside /clientheaders one can define the pages headers those should be allowed to be accessed.
  • Inside /virtualhosts one can define for which all virtual hosts the dispatcher can render the pages.
  • Inside /sessionmanagement has sub sections like /directory which specifies where the session management details should be stored. /encode that defines how to encode the details. /header is the cookie/header that contains the authorization details and /timeout that specifies the session timeout.
  • /renders specifies which ip/host and port should be used for rendering the pages. i.e. publish ip/host and port number. There can be multiple entries defined here.
  • /filter specifies which kind of requests/pages should be filtered for rendering. This also uses details like /url, /protocol, /method, /extension, /path, /selectors, /suffix as more configuration options.
  • /vanity_urls can be configured to allow access to vanity urls. Here /file specifies the file where dispatcher keeps the list of vanity urls.
  • /cache is the main configuration that has information on how the cache will be handled by dispatcher. It has 11 subsections. /docroot, /statfile, /statfileslevel, /rules, /invalidate, /allowAuthorized, /serverStaleOnError, /invalidateHandlers, /allowClients, /ignoreURLParams, /headers. 
    • /docroot specifies where the cache files will be stored. 
    • /statfile specifies the name of stat file to be used. 
    • /statfileslevel spefies the level of content hierarchy until which the statfile should be created. /rules specifies which files should be cached. 
    • /invalidate specifies which files should be eligible for the automatic invalidation. 
    • /allowAuthorized specifies if pages authorization headers should be cached. 
    • /serverStaleOnError says if the dispatcher should return stale pages when the server returns error.
    •  /invalidateHandlers allows to configure script that can be used when dispatcher invalidation is called.
    • /allowClients specifies which clients are allowed to flush the cache.
    • /ignoreUrlParams specifies which url parameters should be ignored which caching the pages. 
    • /headers allows you to define pages with which all headers should be cached by dispatcher.
  • /statistics allows you to define categories to be used for rendering the pages along with their statistics created by dispatcher. This allows only first 8 categories to be considered by dispatcher while rendering the pages from categories. Categories can be anything from html pages to scripts.
  • /stickyConnectionsFor is used to define for which pages sticky connections should be used. Sticky connections are the connections those require the requests to be served by the same publish instance for the same user. For example customer accounts page.
  • /health_check specifies the page that should be accessed while a 500 error occurs. If the specifies page also returns 500 error, then the configurable time penalty is applied before retrying.
  • /retryDelay specifies the time in seconds before there is retry for the server access.
  • /numberOfRetries number of retry performed by dispatcher for the renders.
  • /unavailablePenalty specifies the time delay before a retry is attempted by dispatcher.
  • /failOver this enables the dispatcher to divert the request to another server in case the number of retries fails for one.


Saturday, April 15, 2017

AEM 6 Advanced Interview Questions Part 1

AEM 6 Advanced Interview Questions Part 3


Here, I will try to list down some of the advanced AEM interview questions I have come across. Please correct my answers if required in the comments and I will do the changes accordingly.

1. Difference between service and component
A :
Service :
  • A service is an OSGI component that can be looked up from other OSGI components.
  • Any java object is eligible to be a service
  • All the services in OSGI are components
  • Services are maintained in service registry from which they can be looked up
Component :
  • A component is a java object whose life cycle is handled by the OSGI container.
  • Any java object is eligible to be a component
  • A component is not necessarily an OSGI service, however, to make it callable by other components it has to be declared as service.
2. How a class is made available to OSGI container?
A : By providing @component at the top of the class declaration

3. Do you always need @service and @component annotations for a class in OSGI?
A : No, a component may not be declared as an OSGI service. However, there is a requirement to consume/look up for the component in another component it has to be declared as @component.

4. How to debug a situation where a component is not configurable on ConfigMgr?
A : Following steps should be taken in order to ensure component is configurable

  • The attribute-value metadata=true of @component annotation is responsible to making the component configurable on ConfigMgr. That should be verified first.
  • If the component is using @reference to other service, they should be available to the component and should have been initialized
  • There should be configurable properties associated with the component using - @property or @properties 
5. What is the difference between Live Copy and Language Copy?
A : A Live Copy is the copy of blueprint/source with its live relation with the blueprint/source which means the changes in live copy and source are tracked. Source can be attached or detached or reattached or sync to the Live Copy. While a Language Copy is a static copy of some or all the pages of the source.

6. How Live Copy is connected to blueprint?
A : Using Rollout configuration the Live Copy can be configured to be updated automatically when a update in blueprint occurs.

7. MSM configuration.
Please refer - https://docs.adobe.com/docs/en/aem/6-0/administer/sites/multi-site-manager/msm-blueprints.html

8. How to configure run modes?
A : Run modes are configured in following ways.
  • Provide the run mode as name of AEM jar file e.g. cq6_publish_p4503.jar. Where publish is the run mode.
  • Provide property - sling.run.modes in sling.properties file
  • Provide run mode with java argument for example -Dsling.run.modes=publish
  • Provide -r <run mode> which starting the jar file using batch file
9. How is the configuration of AEM instance done according to run modes?
A : You can define a config (nt:folder) node inside your project folder - /apps/projectA and define configuration of a service/component by creating a node sling:OsgiConfig under it having the full qualifying name like org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl. The configuration should be provided as the property of this node.



When you specify the run mode along with config separated by a dot, it becomes the configuration of a specific run mode and is used when that particular run mode is initialized. For example config.author will define configurations for author run mode.




10. What is the advantages of using Sightly?
A : Following are the advantages of using Sightly over JSP.
  • Easy and no requirement of knowing JAVA to use Sightly.
  • Protection against cross scripting.
  • Uses sightly context to output data in correct format.
  • Clear separation of client side and back end logic. No scriptlets.
  • Strong connection to Sling.
  • Has two ways of handling backend logic. WCM Use Java API and WCM Use Javascript API.
11. What is HTML (display) context in Sightly?
A : The display context of a content refers to its location where it is used in the page. HTL is capable of identifying the context of the output except in case of CSS and JS where in if required explicit context can be passed. This context is used to prevent XSS security problem. XSS is cross site scripting attack on the website, in which attacker can inject the custom script and attack the site. HTL gives protection from this by introducing display context. HTL is capable of identifying the context in link, text and title properties. There are several display contexts those can be used when required. Which are listed below.
  • text
  • html
  • attribute
  • uri
  • number
  • scriptToken
  • scriptString
  • scriptComment
  • styleToken
  •  styleString
  • styleComment
  • unsafe
  • attributeName
  • elementName
12. Why designs are different from clientlibs and why should clientlibs be defined outside designs?
A : Designs contain the details of site level configurations of the components along with it it can contain the clientlibs. However, when a clientlibs are configured in designs, it will be combined into one main.js/main.css and will be loaded each time a page is called. However, there are cases when not all the scripts/css are needed to be loaded on page as they are not used by the components. In such cases, the clientlibs can be defined along with the component and imported according to the requirement on the page. This will ensure only those client libs are called which are required by the page/components on the page and they are easy to maintain due to their clear separation according to the page.

13. What does clientlibs contain and what is embed, dependencies and categories?
A: Clientlibs contain js.txt, css.txt and the sources of javascript and css.
  • Categories specify the clientslibs required by the page
  • Dependencies specify the clientlibs those are required to run the clientlibs defined in categories and it means there will be an extra call made to load these clientlibs.
  • Embed specifies aggregating the clientlibs along with the defined in categories, this means they will be attached to the main clientlibs.

14. Difference between CRX2.0 and OAK (CRX3.0).
A:
  • CRX2.0 is the implementation of Jackrabbit while OAK is the implementation of Jackrabbit OAK
  • Since CRX2.0 is implementation of Jackrabbit, it uses JCR completely, while OAK uses JCR just as facades.
  • CRX2.0 has persistence manager (PM) which writes data as blob however, OAK has microkernel which writes data as per underlying DB.
  • CRX2.0 uses Lucene while OAK uses Solr.
  • CRX2.0 doesn't support clustering (i.e. distributed database across the servers) while OAK uses MongoDB like database which use clustering.


15. Difference between CQ5.6 and AEM6.1?
A:
  • Since AEM6.0 the touch UI is introduced which was not there in CQ5.6
  • AEM6.1 uses OAK which 5.6 uses CRX2.0 which is adobe's implementation of JCR.
  • Since AEM6.0 sightly is introduced as new markup language to facilitate the front end developers with page definitions which reduces the requirement of having developers with knowledge of java.
  • CQSE servlet engine has been replaced by Eclipse Jetty 

16. Do you always require @activate and @deactivate?
A : No. They indicate the methods required for pre or post processing of the components/services.

17. How do you use a service in a component?
A : The simplest way is to use @reference annotation and use the name of the service.
If the service needs to be used inside a jsp, you can use following syntax of code in scriptlet.

com.adobe.cq.KeyService keyService = sling.getService(com.adobe.cq.KeyService.class);

18. Explain dispatcher configurations (especially /filter)
A : Please refer - Dispatcher Configurations

19. Explain @reference annotation.
A: This annotation is used for injecting an OSGI service in OSGI component/service. Following are the different attributes used along with the annotation.

name : in case name of the service is different from the declared variable reference
interfaceName : interface name for the service.
policy : It can be one of ReferencePolicy.STATIC or ReferencePolicy.DYNAMIC. Where in dynamic means, if the reference service goes off, it is bound to the calling component/service when it is on again dynamically without the requirement of resetting the calling component/service. By default this value is always static, which means the calling component/service will not be up until the reference is resolved.
target : to select the referenced service.
strategy : one of event or lookup. This value defines how the reference will be resolved.

20. How sling does resource resolution?
A : There are three basic steps.

  • URL decomposition : The URL is decomposed in protocol, path, extension, selector, suffix and parameters.
  • ResourceType identification : Using the path sling decided at which location in content repository the page resource should be looked for. From there, the sling:resouceType of the page is extracted. In case sling:resouceType is not available, sling:superResourceType is looked for. Once the resourceType is determined say /apps/project/components/pages/componentA, the script is located inside the component definition in apps folder.
  • Script resolution : Here the priorities to the scripts are given as per the name, extension, method and type, which is as follows.
    • selector + extension + jsp/html
    • selector + jsp/html
    • extension + jsp
    • node name + jsp/html
    • method + jsp/html first GET/HEAD and then POST, DELETE etc. These names has to be in capitals.
21. Why a webservice consumer in AEM should be implemented at server side instead of client side?
A : One should be evaluating the output of webservice in order to decide if the consumer should be implemented at service side or client side. For example a webservice giving response in JSON can be better be consumed on the client side while a webservice giving response in XML format can be better consumed on the server side. Also, while implementing the consumer client side, one should consider the size of the response returned by the webservice. Large sized responses should be handled by the server side consumer.

22. Analytics integration.
A : Please refer - SiteCatalyst

23. Sling Dynamic Includes in AEM.
A : This is a separate project created to handle the situation when there is a page with most of the static components and a dynamic component. This enables the dispatcher to cache the static components of the page and load the dynamic components from the publish instance. This is done using a servlet filter that intercepts the request of a component with given resourceType.

Implementation and configuration details can be found at - SDI

24. How to provide different configuration of the same service dynamically?
A : This is done by adding configurationFactory=true as one of the attributes in @component annotation as given in following example.

@component(label = "test component", immediate = true, enabled = true,
metatype = true,
description = "Testing configuration factory",
policy = ConfigurationPolicy.REQUIRE, configurationFactory = true)

This will allow multiple configuration of the component/service by providing + sign at right side on the configMgr.

25. Why an out of the box component should not be altered?
A: The out of the box components are prone to change when a new service pack is installed or when a version upgrade is done or when a new update is provided to the AEM. This will remove the existing configurations done in the component in libs folder. The other reason is the component might have been used inside another project/component which may bring inconsistent behavior in the component that is using the altered component.

26. How to create an overlay component?
A :An overlay component is created by copy pasting the component from \libs to \apps with exact path of the component and doing required changes.

27. How to create an overriden component?
A : A component can be overriden by creating a new component and providing sling:resourseSuperType property.

28. How to create a custom event handler?
A : Define a class that extends EventListner and implement the required method activate method which takes ComponentContext as the argument.

Using session, you can fetch the observation manager like

session.getWorkSpace().getObservationManager()

Using this observation manager you can add event listener with arguments like path, type, event (Node added,  node removed, node moved, persist, property added, property changed, property removed)


Some more AEM 6 Interview Questions for Architects

 Some more AEM 6 Interview Questions for Architects 1. Consider you have a workflow with two steps. One step is to transfer the asset from s...