Call servlet dopost programmatically | Community
Skip to main content
Level 3
June 11, 2018

Call servlet dopost programmatically

  • June 11, 2018
  • 2 replies
  • 2153 views

Hi,

I am trying to play around with acs common feature Querypackager .

Querypackager servlet is registered with resourcetype and have selector and extension.

I would like to programmatically call this servlet from my workflow.

I am getting 500 response. I am having following queries :

  • I am getting an exception in error log ,

        illegalargumentexception: cannot create a node on synthetic resource and ModifiableNode exception.

     I have googled and ended up finding none to resolve the issue.

  • I have referred the following link calling a servlet.

          Adobe Experience Manager Help | Invoking Adobe Experience Manager Sling Servlets using Apache HTTP APIs

     I have followed the same ay for calling he doos bt ith resorcetye.

     My resource type is resolving in resource resolver and i am calling with _jcr_content.package.json

     i didnt find any other way how to implement.

     Is there any other way to implement the servlets registered with resourcetype.

  • The page where the servlet is triggered is located in /etc/acs-commons.

     I have the user with admin permissions, do i need to pass the csrf token programmatically set in the headers of the http post method?

  • What are all the headers and parms need to set to call a post servlet

Please provide any references and solutions to above.

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

2 replies

smacdonald2008
Level 10
June 12, 2018

Is this Servlet registered by Resource type? If so - will be hard to invoke from a WOrkflow. If reg by resource type, you need:

The resource type(s) supported by the servlet. The property value must either be a single String, an array of Strings or a Vector of Strings. Either this property or the sling.servlet.paths property must be set, or the servlet is ignored. If both are set, the servlet is registered using both ways.

See this doc for an explanation -- Apache Sling :: Servlets and Scripts

smacdonald2008
Level 10
June 12, 2018

If you want to call an AEM Service from a Workflow, create a custom AEM Service that contains QueryBuilder logic to do what you want. Write a custom AEM workflow step that invokes the custom service using @Reference annotation. That will invoke your service.  

joerghoh
Adobe Employee
Adobe Employee
June 13, 2018

In your case I would re-implement the logic of the QueryServlet in your own code. A lot of code of this servlet is validating things and rerouting paramters to do some API calls. And instead of creating a wrapper around this wrapper servlet, study the code and use the QueryHelper services (and some others) to do that what you want.

Jörg