I'm developing a custom servlet to prevent users not logged into our site from downloading certain content in the DAM. I can see my servlet active in components but I don't see it resolving in the Servlet Resolver Test (system/console/servletresolver) Thanks for any advice.
(service = Servlet.class, immediate = true,
property = {
ServletResolverConstants.SLING_SERVLET_PATHS + "=/content/dam/advisor/*",
ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=pdf,jpg,jpeg",
ServletResolverConstants.SLING_SERVLET_SELECTORS + "=download",
ServletResolverConstants.SLING_SERVLET_METHODS + "=GET",
"service.ranking:Integer=100"
}
)
public class AnonymousAccessServlet extends SlingAllMethodsServlet {
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @stiegjo22
You can't register a servlet with path pattern, it has to be a absolute path
ServletResolverConstants.SLING_SERVLET_PATHS + "=/content/dam/advisor/*",
https://sling.apache.org/documentation/the-sling-engine/servlets.html#servlet-registration-1
You should register by resourcetype, example
Hi @stiegjo22 , did you check these things?
1. Visit system/console/components to see if your servlet is successfully registered.
2. Visit system/console/bundles to check your OSGI Bundle containing the servlet is active.
3. Use debugging statements to check the error in logs.
4. Use a debugger to see up to which point is your servlet is working.
5. Make sure you are testing a correct path with correct selectors and extensions. Double-check that the resource paths you're testing with actually exist in the DAM and are accessible to the servlet.
6. If multiple servlets could handle the same requests, change the service.ranking property to ensure your servlet takes precedence.
7. If your servlet is registered as a component, ensure the component is correctly defined and activated.
8. Check your code is correct.
9. Try restarting your instance.
Hi @stiegjo22
Please check the extensions declaration
ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=pdf,jpg,jpeg",
it should be
ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=pdf",
ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=jpg",
ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=jpeg",
Hi @stiegjo22
Try changing the servlet extensions declaration as array of items as mentioned below.
sling.servlet.extensions = ["html", "txt", "json"]
Hope this helps.
I updated the extensions declaration in the Component section to:
ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=pdf",
ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=jpg",
ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=jpeg"
However now I see this message when I check a valid pdf resource in the Servlet Resolver Test:
The resource given by path ' /content/dam/advisor/market-intelligence' does not exist. Therefore no resource type could be determined!
Candidate servlets and scripts in order of preference for method GET:
com.day.cq.commons.servlets.NonExistingDispatcherServlet (OptingServlet)
org.apache.sling.servlets.get.impl.DefaultGetServlet
org.apache.sling.jcr.webdav.impl.servlets.SlingWebDavServlet
Hi @stiegjo22
You can't register a servlet with path pattern, it has to be a absolute path
ServletResolverConstants.SLING_SERVLET_PATHS + "=/content/dam/advisor/*",
https://sling.apache.org/documentation/the-sling-engine/servlets.html#servlet-registration-1
You should register by resourcetype, example
Thanks Arun.