UnderstandingAEM mapping request to resource

Locate content resource

Resource path is used to locate content resource

  1. Sling checks weather a node exists at the location specified in the request(e.g. /content/articles/category-name/article-name.print.a4.html)
  2. If no node is found ,the the extension is dropped and search repeated (e.g. /content/articles/category-name/article-name.print.a4)
  3. If no node is found then return 404 http code

Locate scripts once content resource is located

  • The sling:resourceType is used to locate script to be used for rendering the content.
  • Scripts are located in /apps or /libs.
  • If certain rest method(GET, POST) is required, it should be specified in upercase within script name(e,g. a4.POST.jsp).
  • If multiple scripts apply for a given request

The script with the best match is selected. The more specific a match is ,the better it is; in other word, the more selector matched the better, regardless of any request extension or method name match.

Rules:

  1. Folder(e.g. nodes of tyope nt:folder) takes precedence over jsp file names when resolving using selectors, at least the first selector.
  2. Only one selector in a file name has effect, any file name contains two selectors don’t ever get selected, but name of folder can be used to match the selector in the request.
  3. Scripts with HTTP method names(e.g. GET.jsp) is selected as a last resort even after the default script(examples.jsp)
  4. The precedence of same name files are html > jsp > esp. E.g. if examples.html and examples .jsp both exist,then the examples.html will be shown.

For example: http://www.aemtreasury.com/content/resolution.print.a4.html/a/b?name=Dale of type sling:resourceType=”dale/example”

Assuming scripts structure as diagram below:

jcr_resolution

The order of preference should be as shown:

  1. /apps/dale/example/print/a4.html.jsp
  2. /apps/dale/example/print/a4/html.jsp
  3. /apps/dale/example/print/a4.jsp
  4. /apps/dale/example/print.html.jsp
  5. /apps/dale/example/print.jsp
  6. /apps/dale/example/html.jsp
  7. /apps/dale/example/example.jsp
  8. /apps/dale/example/GET.jsp

I prefer to make the script name is the same with fold name which is easy to remember, in this case is /dale/example/example.jsp

Note

Leave a comment