Sling In AEM
AEM is built using Sling, a Web application framework based on REST principles that provide 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 bullet 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
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 client's 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 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 security policies and improve 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.
SOAP | REST |
---|---|
SOAP is a protocol | REST is an architectural style |
SOAP stands for Simple Object Access Protocol. | REST stands for Representational State Transfer. |
SOAP uses service interfaces to expose the business logic. | REST uses URI to expose business logic. |
SOAP defines its own security. | RESTful web services inherit security measures from the underlying transport. |
SOAP permits XML data format only. | REST permits different data formats such as Plain text, HTML, XML, JSON, etc. |
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
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 details please go through the link.
https://experienceleague.adobe.com/docs/experience-manager-release-information/aem-release-updates/previous-updates/aem-previous-versions.html
Resource Mapping in AEM is a feature that enables AEM to define redirect, virtual host, or Vanity URLs. It is used to create desired beautified URL Patterns which are clean and user-friendly in order to help make your website user-friendly and URLs, easy to remember.
For more information please go through the link.
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)
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 modeled inside the server
- removes one or more data models:
1. previously the following was needed: URL structure, business objects, and DB schema.
2. his is now reduced to: URL = resource = JCR structure
These are the API and classes frequently used in AEM
- ValueMap - The ValueMap is an easy way to access the 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 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
Sling JCR Installer scans the CRX repository for artifacts and provides them to the OSGi installer.
Leave a Reply