Hello All,
I am trying to read Sling model values into servlet class. My sling model is having:
@ValueMapValue
public String recaptchaSecretKey;
and I am reading it in servlet as below:
ReadForm model = request.adaptTo(ReadForm.class);
String keys = model.recaptchaSecretKey;
But this is getting null. Is there any other way to achieve this.
Solved! Go to Solution.
Views
Replies
Total Likes
Hello @supriya-hande
option-1: You should take the reCaptcha out of this component into a separate OSGi service.
Anything reusable should not be part of a component.
option-2: You can read configs of different service via Configuration Admin
https://techrevel.blog/2020/09/20/configurationadmin-access-osgi-configuration-of-other-services/
So, servlet can read the config from Model ( if its configurable from OSGI)
Also, I might be wrong, but I guess a Sling HTTP request cannot be adapted to a Model.
Lets wait if someone can guide or confirm
Views
Replies
Total Likes
Hi @supriya-hande
Could you please share what is the use case? and what are the Model and Servlet classes.
How does the flow works?
hi @arunpatidar
There is a task to integrate google reCaptcha module in AEM component. I have created a custom HTML form component and authoring reCaptcha secret and site key in this component. On submit action it invokes reCaptcha execute method and gives token.
Hello @supriya-hande
option-1: You should take the reCaptcha out of this component into a separate OSGi service.
Anything reusable should not be part of a component.
option-2: You can read configs of different service via Configuration Admin
https://techrevel.blog/2020/09/20/configurationadmin-access-osgi-configuration-of-other-services/
So, servlet can read the config from Model ( if its configurable from OSGI)
Also, I might be wrong, but I guess a Sling HTTP request cannot be adapted to a Model.
Lets wait if someone can guide or confirm
Views
Replies
Total Likes
@aanchal-sikka I think 1st option we should use in such cases. I created separate OSGI service to read reCaptcha secret keys and am able to get success response from google server.
Thanks for your help
@arunpatidar I am able to resolve this. Thanks
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies