Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

SlingHttpServletRequest

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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();

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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();