SlingHttpServletRequest | Community
Skip to main content
Keerthi0555
Level 5
April 27, 2023
Solved

SlingHttpServletRequest

  • April 27, 2023
  • 1 reply
  • 1564 views

what SlingHttpServletRequest exactly is we can get resource from request how we are getting resource from request?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by lukasz-m

Hi @keerthi0555,

AEM has been build using multiple layers and technologies. One of the key framework that is used as part of AEM architecture is Apache Sling which is RESTful web-applications based framework.

SlingHttpServletRequest is a Apache Sling extension of HttpServletRequest java class. The extension provides some additional methods that are specific for Apache Sling framework e.g. getResource(), getResourceResolver() etc. Please explore below documentation for all the details:

In terms of getting resource from SlingHttpServletRequest object it can be done via getResource() method or using adaptTo. The main difference is that getResource() is null safe, and getting resource via adaptTo can return null so your code should handle this.

SlingHttpServletRequest request; // getting resource via adaptTo Resource resource = request.adaptTo(Resource.class); // getting resourec via getResource Resource resource = request.getResource();

 

1 reply

lukasz-m
Community Advisor
lukasz-mCommunity AdvisorAccepted solution
Community Advisor
April 29, 2023

Hi @keerthi0555,

AEM has been build using multiple layers and technologies. One of the key framework that is used as part of AEM architecture is Apache Sling which is RESTful web-applications based framework.

SlingHttpServletRequest is a Apache Sling extension of HttpServletRequest java class. The extension provides some additional methods that are specific for Apache Sling framework e.g. getResource(), getResourceResolver() etc. Please explore below documentation for all the details:

In terms of getting resource from SlingHttpServletRequest object it can be done via getResource() method or using adaptTo. The main difference is that getResource() is null safe, and getting resource via adaptTo can return null so your code should handle this.

SlingHttpServletRequest request; // getting resource via adaptTo Resource resource = request.adaptTo(Resource.class); // getting resourec via getResource Resource resource = request.getResource();