May 12, 2020
Estimated Post Reading Time ~

Apache Sling + Interview Questions

AEM is built using Sling, a Web application framework based on REST principles that provides easy development of content-oriented applications. Sling uses a JCR repository, such as Apache Jackrabbit, or in the case of AEM, the CRX Content Repository, as its data store.

Apache Sling in five bullets points.

  • REST based web framework.
  • Content-driven, using a JCR content repository.
  • Powered by OSGi
  • Scripting inside, multiple languages (JSP, server-side javascript, Scala, etc.)
  • Apache Open Source project
For more information click here

Interview Questions

Note: To build an application using Apache Sling watch this video

1. What is REST principle?
REST (Representational State Transfer) architectural style describes six constraints applied to architecture:
  • Uniform Interface – Individual resources are identified using URLS. The resources (database) are themselves different from the representation (XML, JSON, HTML) sent to the client. The client can manipulate the resource through the representations provided they have the permissions. Each message sent between the client and the server is self-descriptive and includes enough information to describe how it is to be processed. The hypermedia that is hyperlinks and hypertext act as the engine for state transfer.
  • Stateless Interactions – none of the clients context is to be stored on the server side between the request. All of the information necessary to service the request is contained in the URL, query parameters, body or headers.
  • Cacheable – Clients can cache the responses. The responses must define themselves as cacheable or not to prevent the client from sending the inappropriate data in response to further requests.
  • Client-Server – The clients and the server are separated from each other thus the client is not concerned with the data storage thus the portability of the client code is improved while on the server side the server is not concerned with the client interference thus the server is simpler and easy to scale..
  • Layered System – At any time client cannot tell if it is connected to the end server or to an intermediate. The intermediate layer helps to enforce the security policies and improve the system scalability by enabling load-balancing.
  • Code on Demand – an optional constraint where the server temporarily extends the functionality of a client by the transfer of executable code.
2. Difference between REST and SOAP.

3. What is sling resolution?
The following diagram explains Sling script resolution: it shows how to get from HTTP request to content node, from content node to resource type, from resource type to script and what scripting variables are available.

For more information watch this video

4. What is sling model?
A Sling Model is implemented as an OSGi bundle. A Java class located in the OSGi bundle is annotated with @Model and the adaptable class (for example, @Model(adaptables = Resource.class). The data members (Fields) use @Inject annotations. These data members map to node properties.Example of sling model :

package org.abhi.poc.sling.models;
  import javax.inject.Inject;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.models.annotations.Model;
 @Model(adaptables = Resource.class)
   public class UserInfo {
   @Inject
   private String firstName;
  @Inject
    private String lastName;
  @Inject
  private String technology;
  public String getFirstName() {
    return firstName;
  }
public String getLastName() {
return lastName;
}
public String getTechnology() {
return technology;
}
}


For more information https://sling.apache.org/documentation/bundles/models.html

For more information
https://helpx.adobe.com/experience-manager/using/sling_models.html

For more information watch this video

5. How to customize pages shown by the error handler?
https://docs.adobe.com/docs/en/cq/5-6-1/developing/customizing_error_handler_pages.html

6. What is resource mapping?
https://docs.adobe.com/docs/en/cq/5-6-1/deploying/resource_mapping.html

7. Is sling is content centric. Explain
Sling is content-centric. This means that processing is focused on the content as each (HTTP) request is mapped onto content in the form of a JCR resource (a repository node):
the first target is the resource (JCR node) holding the content
secondly, the representation, or script, is located from the resource properties in combination with certain parts of the request (e.g. selectors and/or the extension)

8. Explain restful sling.
Due to the content-centric philosophy, Sling implements a REST-oriented server and thus features a new concept in web application frameworks. The advantages are:
very RESTful, not just on the surface; resources and representations are correctly modelled inside the server
removes one or more data models
previously the following were needed: URL structure, business objects, DB schema;
his is now reduced to: URL = resource = JCR structure

9. What are the sling APIs you have used?
These are the api and classes frequently used in AEM
  • ValueMap - The ValueMap is an easy way to access properties of a resource.
  • ResourceResolver - The ResourceResolver defines the service API which may be used to resolve Resource objects.
  • ResourceProvider - API for providers of resources.
  • Resource - Resources are pieces of content on which Sling acts The Resource is also an Adaptable to get adapters to other types.
  • ResourceWrapper - The ResourceWrapper is a wrapper for any Resource delegating all method calls to the wrapped resource by default.
  • ResourceUtil - The ResourceUtil class provides helper methods dealing with resources.
For more information click here

10. Which provider service scans the CRX repository for artifacts and provides them to the OSGi installer?
Sling JCR Installer scans the CRX repository for artifacts and provides them to the OSGi installer


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.