what can be defined as path for a sling servlet | Community
Skip to main content
Nitiks25
Level 2
May 31, 2018 6:29 AM UTC
Solved

what can be defined as path for a sling servlet

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Techaspect_Solu
Techaspect_SoluAccepted solution
Level 7
May 31, 2018 9:28 AM UTC

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

3 replies

smacdonald2008
Level 10
May 31, 2018 2:33 PM UTC

Excellent response!

Translate
Techaspect_Solu
Techaspect_SoluAccepted solution
Level 7
May 31, 2018 9:28 AM UTC

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

Translate
Level 2
May 31, 2018 8:06 AM UTC

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 .

Translate