Hello Everyone,
I was trying to create a sling servlet with doPut method override, please find code snippet below
@SlingServlet(paths = {"/bin/mysite/ravi"},
methods = {HttpConstants.METHOD_GET, HttpConstants.METHOD_PUT})
public class MyServlet extends SlingAllMethodsServlet {
@Override
protected void doPut(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws IOException {
response.getWriter().write("My Servlet called");
response.getWriter().close();
}
}
When I tried accessing from Postman, by access below URL, http://localhost:4502/bin/mysite/ravi with PUT method and Basic Auth. But it never calls doPut method from servlet. Any help is appreciated and thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
You might not have your AEM configured to allow PUT methods, because all PUT methods are being filtered. From your local AEM, you need to configure the Apache Sling Referrer Filter.
In OSGI configurations (http://localhost:4502/system/console/configMgr), locate “Apache Sling Referrer Filter”. Remove the PUT method from filters property.
If you would like to test your Servlet via POSTMAN, you can follow this tutorial here -> https://sourcedcode.com/blog/aem/how-to-make-simple-http-post-methods-in-aem-with-a-http-rest-client
Hi @rgravisankar, did you try to use http://localhost:4502/system/console/requests to check what is consuming your PUT request, you are sending from Postman? Could you share the output of recent request - this will be useful to figure out what could be the root cause of the issue. I would assume that your servlet has been successfully registered as an OSGi component, right?
You might not have your AEM configured to allow PUT methods, because all PUT methods are being filtered. From your local AEM, you need to configure the Apache Sling Referrer Filter.
In OSGI configurations (http://localhost:4502/system/console/configMgr), locate “Apache Sling Referrer Filter”. Remove the PUT method from filters property.
If you would like to test your Servlet via POSTMAN, you can follow this tutorial here -> https://sourcedcode.com/blog/aem/how-to-make-simple-http-post-methods-in-aem-with-a-http-rest-client
Views
Like
Replies
Views
Likes
Replies