What is the purpose of resourceResolver.adaptTo (Session.class) in Apache Sling?

I am new to Apache Sling, CQ5 etc.

In our code base, we have a piece of code similar to this:

void perform(SlingHttpServletRequest request, SlingHttpServletResponse response) { ResourceResolver resourceResolver = request.getResourceResolver(); Session session = resourceResolver.adaptTo(Session.class); PageManager pageManager = resourceResolver.adaptTo(PageManager.class); } 

What do adapTo do here?

There is also a good documentation / user guide that I can read to get started with Sling, CQ5, etc.

+6
source share
1 answer

The adaptTo () method, found in many lines, allows you to "transform" objects. Sling might decide to add the resolver.getSession () method, but that would not be very flexible. The good thing about adaptation is that it is dynamic. You can create adapters to convert between different types (they are OSGi services). Sling and CQ5 also include a default adapter group . There are some adapters docs in the sling wiki .

On how to get started with Sling and CQ5, sling is a good place to start.

+6
source

All Articles