How to read servlet response in Sling Model
I've a servlet written in AEM using Sling ResourceTypes which returns some response.
And the path http://localhostL4502/content/example/testpage.productsjson.html is giving the servlet response when I hit through browser. Now I would like to read the same json response in sling Model. How can I call the servlet in sling model. Any example code snippet will be helpful.
sample servlet:
@Component(service=Servlet.class,
property={
Constants.SERVICE_DESCRIPTION + "=Simple Demo Servlet",
"sling.servlet.methods=" + HttpConstants.METHOD_GET,
"sling.servlet.resourceTypes="+ "exampe/components/structure/page",
"sling.servlet.extensions=" + "productsjson",
})
public class SampleServlet extends SlingSafeMethodsServlet {
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)throws IOException
{
response.getWriter().write("Welcome to the Products Servlet!");
}
}