Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

what can be defined as path for a sling servlet

Avatar

Level 3

Is there any limitation as to what can be set as the path for a sling servlet?

I need a custom sling servlet hosted at a path named "healthcheck" i.e. if I hit <domain port>/ healthcheck it should call that servlet but when I tried this It didn't work.

Tried few other words too but still the same issue. Are single word paths not allowed?

If I prefix the path with another word (e.g /services/...) then it works.

Anybody have any inputs on this behavior?

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi,

You can add custom execution paths such as "healthcheck" in your case by following the steps below:

1) Go to http://localhost:4502/system/console/configMgr

2) Search for Apache Sling Servlet/Script Resolver and Error Handler

3) Click on "+" symbol under Execution paths and add your custom execution path. For e.g. /healthcheck/

NOTE: The Execution paths are the paths under which executable scripts will be searched. If a configured value ends with a slash, the whole sub tree is allowed. Without a slash an exact matching script is allowed.

If you hit http://localhost:4502/healthcheck without registering the execution path, you will see the following error:

Error: Requested Path /healthcheck.servlet is not in available search paths

However, though you register the execution path (/healthcheck/) and hit http://localhost:4502/healthcheck , you will still see the following error:

Error: Resource /healthcheck not found

This is because, /healthcheck is a execution search path, where as it is not a resource.

NOTE: sling.servlet.paths are the list of absolute paths under which the servlet is accessible as a resource.

For example, if you register your servlet path in the following way,

"sling.servlet.paths=/healthcheck/healthcheckServlet", it searchs for resource (healthcheckServlet) under execution path (/healthcheck/) and the servlet will be hit as expected without errors.

For more information on how sling servlet works, please refer:

Apache Sling :: Servlets and Scripts

Hope this helps!

Regards,

TechAspect Solutions

View solution in original post

3 Replies

Avatar

Level 2

Hi,

You need to make a entry in "Apache Sling Servlet/Script Resolver and Error Handler" for /healthcheck, and now you can register your servlet with /healthcheck .

Screenshot from 2018-05-31 13-29-00.png

Avatar

Correct answer by
Level 7

Hi,

You can add custom execution paths such as "healthcheck" in your case by following the steps below:

1) Go to http://localhost:4502/system/console/configMgr

2) Search for Apache Sling Servlet/Script Resolver and Error Handler

3) Click on "+" symbol under Execution paths and add your custom execution path. For e.g. /healthcheck/

NOTE: The Execution paths are the paths under which executable scripts will be searched. If a configured value ends with a slash, the whole sub tree is allowed. Without a slash an exact matching script is allowed.

If you hit http://localhost:4502/healthcheck without registering the execution path, you will see the following error:

Error: Requested Path /healthcheck.servlet is not in available search paths

However, though you register the execution path (/healthcheck/) and hit http://localhost:4502/healthcheck , you will still see the following error:

Error: Resource /healthcheck not found

This is because, /healthcheck is a execution search path, where as it is not a resource.

NOTE: sling.servlet.paths are the list of absolute paths under which the servlet is accessible as a resource.

For example, if you register your servlet path in the following way,

"sling.servlet.paths=/healthcheck/healthcheckServlet", it searchs for resource (healthcheckServlet) under execution path (/healthcheck/) and the servlet will be hit as expected without errors.

For more information on how sling servlet works, please refer:

Apache Sling :: Servlets and Scripts

Hope this helps!

Regards,

TechAspect Solutions