Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Call an OOTB Sling Servlet from a workflow process

Avatar

Level 4

Hi All,

 

I have a usecase where I need to call an OOTB AEM Sling Servlet from a workflow step process and store the response from the servlet in asset metadata. Is there a way to call the sling servlet running in the same AEM instance without using the Apache HTTP api? I have already tried calling the servlet using the Apache HTTP api with basic authentication, and it works but, I have to hardcode the url to something like "http://localhost:4502/.... (in my local instance). Is there a better way to do this than using the http api? I don't like to hardcode (or use configs) the host:port to build the url and the credentials. And, i feel it defeats the purpose since I am trying to call the servlet from within the same AEM instance from a bundle.

 

I would greatly appreciate any help or helpful pointers you can provide.

-SKM

11 Replies

Avatar

Community Advisor

@skmAem I am trying to understand your issue here. As per definition, a servlet is written when you have to request a response from a server over a network. 

 

Keeping aside the servlet , if we see in your case, you are trying to access a class , which is available in the same bundle in the same console. If so, wouldn't it be better if you register it as a service and try to access the Service rather than trying to hit it as a servlet. I don't think that would be a right approach to do here. 

 

Thanks

Veena ✌

Avatar

Employee Advisor

Hi,

 

I think that you rather need to access the logic stored in that servlet. And the fact, that you need to do a request is just an implementation detail, because that logic is not available in a different way.

 

I would recommend to rethink your approach. If you refactor your servlet and move the core logic into a dedicated service, it's much easier to call this logic, without using a request.

Avatar

Level 2

Hi @kautuk_sahni, You marked @Jörg_Hoh 's response as an accepted but that truly does not answer my question/query. I agree with what he is saying but this is an OOTB AEM product servlet and I can not extract out the code and create a separate sling service. It also appears that this OOTB servlet has too much logic in itself and it would benefit from extract that logic in a service as per Jörg's another comment.

 

I am still open for other suggestions.

 

Thanks,

SKM

Avatar

Level 4

Thanks @Jörg_Hoh and @VeenaVikraman for your suggestions. The issue is I am trying to call AEM OOTB servlet and not our custom servlet. Let me give you more detail. The Assets UI calls the servlet "com.day.cq.dam.s7dam.common.servlets.S7damEmbedCodeServlet" to get the Dynamic Media/Scene7 URL for video assets and shows it when you click on the URL button in UI. In our use case I need to store this URL in the asset's metadata. I have a workflow step process that I am developing where I am thinking about adding the logic.

 

Thanks again for your response and let me know if you can think of any other solution.

 

-SKM

Avatar

Community Advisor

@skmAem It again comes to the same thing, even though the logic is available in the servlet , it is not the right way to do in a WF process. You have to find the logic implemented in the servlet , and redo that as a service and then access it in your WF. That's the best way I think. Every component has its own purpose. Servlets should not be called the way you are intending to do right now.

Avatar

Level 4

Hi @VeenaVikraman, Thanks for your reply. As mentioned earlier this is an AEM product code and  not our custom. I do not have access to the servlet code to extract out the logic and create a service. And I whole heartedly agree that the approach you are suggesting is the right approach but unfortunately may not help me in this case.

 

Thanks,

SKM

Avatar

Employee Advisor

 

That servlet seems to be an example of the servlet-design I described in my previous post (containing too much logic)

 

Can you raise a feature request with Adobe support and ask for an existing API which can provide this information?

Avatar

Level 4

Hello @Jörg_Hoh, Thanks for your reply. I can certainly do the feature request and ask for an API that would return that URL but I would think it would take a considerable amount of time for the Adobe engineers to implement it and our needs are for near future. Can you think of any other approach that may work for us?

 

-SKM

Avatar

Community Advisor

@skmAem Perhaps we (or some help from Adobe) can try to figure if there is an available @service that can be utilized that is called in the ootb servlet.
Or try to look in that direction if you can figure the available ootb service. 

What part of the output of the servlet are you looking to utilize?

can you add an example say for eg localhost:4502/bin/pathtoembedcodeservlet.json is the the, {details: detailsinfo} is the response. 

 

Avatar

Level 4

Hello @Shubham_borole, Thanks for your response. It would be tremendously helpful if there is a @service available that we can call to get back the Dynamic Media URL. I can see that Assets UI sends the following request to get the DM URL back: 

http://localhost:4502/conf/global/settings/dam/dm/presets/viewer/Video.embedcode.copy.text/content/dam/skm-local-video/face-roboarmB.mp4

The servlet that handles this request is: 

com.day.cq.dam.s7dam.common.servlets.S7damEmbedCodeServlet

And the test/plain response we get back is: 

https://XXXind.scene7.com/s7viewers/html5/VideoViewer.html?videoserverurl=https://XXXind.scene7.com/is/content/&emailurl=https://XXXind.scene7.com/s7/emailFriend&serverUrl=https://XXXind.scene7.com/is/image/&config=Scene7SharedAssets/Universal%5FHTML5%5FVideo%5Fsocial&contenturl=https://XXXind.scene7.com/skins/&asset=XXXindstage/face%2DroboarmB%2DAVS

 

-SKM