Vous êtes sur la page 1sur 7

Agenda Day 3:

• Sling API Principal – with REST


• Sling Resource Resolution in AEM
• Use Cases in AEM

1. SLING API – REST based Principal


REST Overview:
Flow of Web-Application of JAVA:
1. Request – Web Server – Response (HTML)

2. If data is expected in XML/JSON format, it can be done via Servlet using do Get/do Post
methods, request/response properties and it is done. Easy replacement is REST API.

create object at server side and return the object values (state) in form of JSON/XML.

Svsoft solutions - An Online Training


Instituteinfo@svsoftsolutions.com
Author: Mr. Vipin Kumar
Converting object to format (XML/JSON) is state || State of object can be send either using
XML/JSON.
Representation State Transfer (REST) – To transfer the State of an object over the web.
Implementation of REST – Jersey | Spring
Example:
http://www.sprint.com/questions?mode=java
http://www.sprint.com/question/java
When HIT any page, we are actually requesting a resource.

REST is Stateless :
http://www.test.com/abc.html - State 1
http://www.test.com/abc/xyz.html - State 1

Svsoft solutions - An Online Training


Instituteinfo@svsoftsolutions.com
Author: Mr. Vipin Kumar
Sling API Overview:

• REST based web framework.


• Content-driven, using a JCR content repository.
• Powered by OSGi
• Apache Open Source project

Use Case: URL mapping to content and result display.

Hit URL: http://localhost:4506/content/geometrixx-outdoors/en/men.html

• Above URL handles by Apache Jetty (Default Servlet Engine)


• Servlet Engine maps the request to Default Sling Servlet.
• The servlet checks the request's extension and uses the corresponding renderer if it's
enabled.

Note:
https://sling.apache.org/documentation/bundles/rendering-content-default-get-
servlets.html

https://github.com/apache/sling-old-svn-
mirror/blob/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/i
mpl/DefaultGetServlet.java

• Go to http://localhost:4506/system/config/configMgr
• Search for Get Servlet, open the below service.

• You can configure the above service to block the XML/JSON representation as well .
http://localhost:4506/content/geometrixx-outdoors/en/men.json
http://localhost:4506/content/geometrixx-outdoors/en/men.1.json
http://localhost:4506/content/geometrixx-outdoors/en/men.xml

Svsoft solutions - An Online Training


Instituteinfo@svsoftsolutions.com
Author: Mr. Vipin Kumar
Note: The DefaultGetServlet is invoked on all GET requests. The servlet checks the request's extension
and uses the corresponding renderer if it's enabled. HTML renderer, JSON renderer and XML renderer.

Apache Sling Script Resolution

In Apache Sling each (http) request is mapped onto a JCR resource, i.e. a repository node.

Svsoft solutions - An Online Training


Instituteinfo@svsoftsolutions.com
Author: Mr. Vipin Kumar
Use Cases :
http://localhost:4506/content/ideawebsite.html

/ - Root in content node

/content/ideawebsite – path

.html – extension

Open CRXDE, Sling framework maps the request to path

Picks the “sling:ResourceType” i.e /apps/idea/components/page/ideapage

Note: Goto the path, if relative path, Checks in apps then libs. [Apache Sling Resource Resolver Factory –
Check in http://localhost:4506/system/console/conifigMgr ]

Traverse to the path in repository : /apps/idea/components/page/ideapage

Best Matches Rules for Script :

1. Selector + Extension .jsp ->


2. Selector .jsp
3. Extension .jsp
4. Node name .jsp
5. Node name .html
6. Get .jsp | Post .jsp

Svsoft solutions - An Online Training


Instituteinfo@svsoftsolutions.com
Author: Mr. Vipin Kumar
Create following files under /apps/idea/components/page/ideapage

• ideapage.html
• ideapage.jsp
• html.jsp
• idea.jsp
• idea.html.jsp
• GET.jsp

Example 1 URL : http://localhost:4506/content/ideawebsite.idea.html

Srcipt : idea.html.jsp (Rule – 1)

Now delete idea.html.jsp

Hit Again

Script : idea.jsp (Rule – 2)

Example 2 : URL : http://localhost:4506/content/ideawebsite.html

Script : html.jsp (Rule – 3)

Now delete html.jsp

Hit Again

Script : ideapage.jsp (Rule – 4)

Now delete ideapage.jsp

Hit Again

Script : ideapage.html (Rule – 5)

Now delete ideapage.html

Hit Again

Script : GET.jsp (Rule – 6)

Svsoft solutions - An Online Training


Instituteinfo@svsoftsolutions.com
Author: Mr. Vipin Kumar
Request URL Type :

http://localhost:4506/content/ideawebsite.idea.html/testing/additon?a=10&b=30

Selector : idea (some more information about the page) (server side :
request.getServerInfo().getSelector()) - Cached

Extension : html

Suffix : /testing/addition (request.getSuffix)

Query parameter : a=10&b=30 (request.getParameter)

Svsoft solutions - An Online Training


Instituteinfo@svsoftsolutions.com
Author: Mr. Vipin Kumar

Vous aimerez peut-être aussi