How alter SlingHttpServletRequest with different Resource? | Community
Skip to main content
Level 3
Jan 19, 2018 9:01 AM UTC

How alter SlingHttpServletRequest with different Resource?

I am struggling with some generic piece of code:

Resource resource = dynamicallyFindNeededResource(res);

Class<?> someModel = pickUpSomeSlingModelClass();

return resource.adaptTo(someModel);

The problem is I want to expand this type of adapting to request as well:


Adaptable adaptable = checkIfModelAdaptableByRequest(someModel) ? changeRequestResourceToCurrentOne(request, resource) : resource;

return adaptable.adaptTo(someModel);

What comes to my mind is the changeRequestResourceToCurrentOne method has to use SlingRequestWrapper which would be kind of lame solution. Any other ides how to alter that request with resource without wrapping it with new resoruce? Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

7 replies

edubey
Level 10
Jan 19, 2018 10:25 AM UTC

I am just trying to understand why would you need to adapt to another resource?
You can always read any resource with resource resolver.

Translate
Peter_Puzanovs
New Participant
Jan 19, 2018 10:38 AM UTC

Hi,

Via your request SlingHttpServletRequest (Apache Sling (Builder) 6 API) get request dispatcher SlingHttpServletRequest (Apache Sling (Builder) 6 API) then use standard API to forward your request to a new place.

Agree with the previous answer, why not direct the request to the correct location in the first place or adapt existing request to desired location?

Regards,

Peter

Translate
puradawidAuthor
Level 3
Jan 21, 2018 7:36 PM UTC

So the point is there is a mechanism that is looking for another resource in a content tree (nearest sibling with resource type) to generate this one, i.e. "configuration".

There is no way to forward this request nor include neither.

Translate