How can we hit the servlet which is registered based on path from an OSGI EventHandler | Community
Skip to main content
November 30, 2023
Solved

How can we hit the servlet which is registered based on path from an OSGI EventHandler

  • November 30, 2023
  • 1 reply
  • 627 views

Hi Team,

 

We have a requirement where we have to call a servlet by setting some request parameters from the EventHandler when the user Publish the page from Touch UI to clear the Dispatcher And CDN Cache for the published page (or) Asset (We already have a logic in the servlet to clear Dispatcher And CDN Cache).

 

So to achieve this we were trying to call the servlet from the Existing EventHandler (Which is to convert HTML page to PDF file when ever user change some content in the and page and publish it) by annotating SlingHttpServletRequest And SlingHttpServletResponse with @3214626 OSGI annotation, but we are getting these 2 objects as NULL in the EventHandler.

 

Please suggest some other approach to call the servlet from the EventHandler without using SlingHttpServletRequest And SlingHttpServletResponse objects (or) Any other way is also fine for us.

 

Regards,

Surendra k  

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi,

I would recommend to extract the logic from Servlet and put in a common service(which generate PDF) and then use this common service in Servlet and EventHandler.

 

technically it is possible to create request from EventListener but not the best design

https://github.com/arunpatidar02/aemaacs-aemlab/blob/f96ce5316dfa4798c72d2e87d3a0b41fc49791a4/core/src/main/java/com/community/aemlab/core/models/sample/ServletModel.java#L66 

1 reply

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
November 30, 2023

Hi,

I would recommend to extract the logic from Servlet and put in a common service(which generate PDF) and then use this common service in Servlet and EventHandler.

 

technically it is possible to create request from EventListener but not the best design

https://github.com/arunpatidar02/aemaacs-aemlab/blob/f96ce5316dfa4798c72d2e87d3a0b41fc49791a4/core/src/main/java/com/community/aemlab/core/models/sample/ServletModel.java#L66 

Arun Patidar
December 1, 2023

Thank you Arun, we just moved the cache clear logic from servlet to service and resolve the issue.