Hi,
I have requirement to send to Json Raw data to the post sling Servlet .
Anyone know what will be the recommended way to achieve this.
Regards,
Sanjay
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
we are doing this but we are consuming within same application so for us there are no issues using POST sling servlet.
But if you are exposing json over post you have to care of a lot of security like enable filter to allow post
example https://sourcedcode.com/blog/aem/in-aem-what-is-the-apache-sling-referrer-filter-osgi-configuration
@Sanjay_Bangar can you share some more details such as
how is the Json data generated? is it dynamically generated or json stored in AEM?
Are you trying to call the servlet upon any form submission?
you can try making ajax calls to the servlet and pass json data to the servlet post method.
Hi,
we are doing this but we are consuming within same application so for us there are no issues using POST sling servlet.
But if you are exposing json over post you have to care of a lot of security like enable filter to allow post
example https://sourcedcode.com/blog/aem/in-aem-what-is-the-apache-sling-referrer-filter-osgi-configuration
When doing a ajax call use something like below
var square = {};
square.length = 10;
square.width = 10;
$.ajax(
url: url,
data: JSON.stringify(square),
dataType: “json”
contentType: “application/json”,
Type: “POST”
);
while reading in servlet you can use like below:
String requestBody = request.getReader().lines().collect(Collectirs.joining());
you can use any Utils class to convert from string to json or java bean.
Thanks!
Views
Likes
Replies
Views
Likes
Replies