Expand my Community achievements bar.

Call servlet dopost programmatically

Avatar

Level 3

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 A...

     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.

5 Replies

Avatar

Level 10

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

Avatar

Level 10

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.  

Avatar

Level 3

Hi scott,

I have implemented using bundles .... it worked.

But i want to know the real difficulty in calling the servlet  registered by resource type through http post.

Avatar

Level 10

It won;t work through a POST. That is because a Servlet registered via a resource type and is fired when that resource type is accessed- not in response to an event - like when we click a button - such as a submit button on a component.

See this doc for more information -- Scott's Digital Community: Binding Adobe Experience Manager Servlets to ResourceTypes

Avatar

Employee Advisor

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