Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!

Invoking an AEM servlet from outside the domain

Avatar

Level 5

Ok so based on earlier discussion with Adobe folks, we wrote a servlet on the AEM platform in cloud that executes some functions based on our post. Now the challenge is protecting the URL and be able to post.

 

For example, our serlvet path is /bin/wcm/myproject/manageusers

Since the path is virtual, how do we assign rights by creating a user who can invoke that servlet? Where would we do that. Secondly, do we have an example of an Ajax call that can invoke that servlet by passing a username/pwd?

2 Replies

Avatar

Employee Advisor

You should bind your servlet with a resourceType and use that resource type in a custom page component and a template. You can then create a page with that template and define permissions or ACLs on the page node for defining the access control. Whenever you hit the URL of the page the AEM will call the servlet (if the permissions of the user are allowed) as the resourceType of the page will point to the servlet. 

[1] https://cqdump.wordpress.com/2015/03/23/aem-coding-best-practice-servlets/

[2] http://labs.6dglobal.com/blog/2013-01-31/servlets-sling-case-disappearing-servlet-path/

Example code for calling AEM url with user name /password-

$.ajax ({ type: "GET", url: "/content/sites/test.html", dataType: 'json', async: false, headers: { "Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD) }, data: '{ "test" }', success: function (){ alert('success!'); } });

Avatar

Level 5

Kunal,

Is that the standard way for AJAX call with parameters?

what's btoa in the headers? is that a standard jquery function? Are there other examples of similar ajax calls?