Niveau 1
Niveau 2
Se connecter à la communauté
Connectez-vous pour voir tous les badges
Résolu ! Accéder à la solution.
Vues
Réponses
Nombre de J’aime
And just as a general statement: AEM making requests to itself is in general considered a code smell. There should always be a direct way (using API) to achieve the same.
(And it case it is not, there should be one... please raise a feature request for it.)
Hi @kjj ,
Yes, the com.day.cq.contentsync.handler.util.RequestResponseFactory
class is deprecated in AEM. The recommended substitute for this class is to use the org.apache.sling.api.request.RequestResponseFactory
interface instead. To obtain an instance of the RequestResponseFactory
interface, you can use the org.apache.sling.api.SlingHttpServletRequest
object.
Vues
Réponses
Nombre de J’aime
Hey @MayurSatav can you just recheck or tell me how you found the api, i cannot find it, giving a snap from IDE, share me also the java-doc link for the same (org.apache.sling.api.request.RequestResponseFactor)
Vues
Réponses
Nombre de J’aime
@Jörg_Hoh could you please help this user?
Vues
Réponses
Nombre de J’aime
Hi @MayurSatav
Such an
org.apache.sling.api.request.RequestResponseFactory
interface does not exist. Can you please confirm the right replacement?
Hi @kjj
What is the reason you are using "RequestResponseFactory" API, I suggest if it is just to create request , you can get it directly from SlingHttpServletRequest.
Let me know if you have any other specific reason?
my reason for using it is to get the generated html for my component,
the above person Mayur say use SlingHttpServletRequest request to get the RequestResponseFactory, how can that be done? i cant find any method in SlingHttpServletRequest that return the RequestResponseFactory
Vues
Réponses
Nombre de J’aime
Check https://sling.apache.org/documentation/bundles/servlet-helpers.html, it explains the tools Sling provides for this.
https://sling.apache.org/documentation/bundles/servlet-helpers.html#internalrequest-helpers is not production safe instead use SlingRequestProcessor.
....
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.request.builder.Builders;
import org.apache.sling.api.request.builder.SlingHttpServletResponseResult;
import org.apache.sling.engine.SlingRequestProcessor;
....
/** The sling processor. */
@Reference
private SlingRequestProcessor slingProcessor;
.....
SlingHttpServletRequest slingRequest = Builders.newRequestBuilder(targetResource)
.withExtension("html")
.withSelectors("test")
.withParameter("wcmmode", "disabled")
.withRequestMethod("GET").build();
SlingHttpServletResponseResult responseResult = Builders.newResponseBuilder().build();
// Process the request
slingProcessor.processRequest(slingRequest, responseResult, resolver);
String res = responseResult.getOutputAsString();
And just as a general statement: AEM making requests to itself is in general considered a code smell. There should always be a direct way (using API) to achieve the same.
(And it case it is not, there should be one... please raise a feature request for it.)
Vues
Likes
Réponses
Vues
Likes
Réponses
Vues
Likes
Réponses
Vues
Likes
Réponses