I have the following servlet that works great
@component(
service=Servlet.class,
property= {
"sling.servlet.resourceTypes="+"mysite/components/structure/page",
"sling.servlet.selectors="+"testselector",
"sling.servlet.extensions="+"json",
ServletResolverConstants.SLING_SERVLET_METHODS + "=GET"
}
)
public class TestServlet extends SlingSafeMethodsServlet
I can call it using jquery ajax on a page like this
$.ajax({
type:"GET",
url: "/_jcr_content.testselector.json",
success: function(data){
console.log("success!")
}
});
I can also put the full address to the servlet in my browser (if i'm logged into my local aem instance) and get a valid response.
But if I create a second servlet that is almost identical like this:
@component(
service=Servlet.class,
property= {
"sling.servlet.resourceTypes="+"mysite/components/structure/page",
"sling.servlet.selectors="+"testselectortwo",
"sling.servlet.extensions="+"json",
ServletResolverConstants.SLING_SERVLET_METHODS + "=GET"
}
)
public class TestServletTwo extends SlingSafeMethodsServlet
then any calls to TestServletTwo return 400 Bad Request and in the browser, shows the error "Invalid recursion selector value testselectortwo".
Why isn't the second one working?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @mpalme1,
I tried to reproduce your scenario in my local and it works fine with two selectors. Given the trials/observations you have shared so far, could see that the issue is not specific to any selector value in particular.
Instead it is either
Servlet OSGI component Status :
Can you navigate to OSGI components section -> look for servlet and confirm if it is in active state(not in satisfied or unsatisfied reference)
If it is active, click on that component and check if all the properties are intact (per the Servlet file - In particular, resourceTypes, extension and selector)
The way we call the servlet :
Can you share the exact path you are using to test the servlet resolution in Sling -> Sling Servlet Resolver.
Outside this issue, if you are looking to associate multiple selectors to a single servlet, use the respective property as many times needed. (for any multiple value property for that matter)
Example:
@Component(service=Servlet.class,
property={
ServletResolverConstants.SLING_SERVLET_METHODS+"=GET",
ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES+"=weretail/components/structure/page",
ServletResolverConstants.SLING_SERVLET_SELECTORS+"=testselector",
ServletResolverConstants.SLING_SERVLET_SELECTORS+"=testselectortwo",
ServletResolverConstants.SLING_SERVLET_EXTENSIONS+"=json"
})
Please confirm if you're trying the second servlet on the same resource as first servlet and it also returns a valid json response? (may be you can just try second servlet with exact same logic as first one).
Also check if the servlet component (TestServletTwo) & the bundle are in active state and servlet is registered Sling-> Sling Servlet Resolver.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Your error says that the issue is with the selector value "testselectortwo". Try changing it and check if it works.
Also, In addition to the below steps mentioned by @shelly-goel, can you please share the log entries once you hit the second servlet?
Thanks,
Kiran Vedantam.
Views
Replies
Total Likes
Views
Replies
Total Likes
Hi @mpalme1,
I tried to reproduce your scenario in my local and it works fine with two selectors. Given the trials/observations you have shared so far, could see that the issue is not specific to any selector value in particular.
Instead it is either
Servlet OSGI component Status :
Can you navigate to OSGI components section -> look for servlet and confirm if it is in active state(not in satisfied or unsatisfied reference)
If it is active, click on that component and check if all the properties are intact (per the Servlet file - In particular, resourceTypes, extension and selector)
The way we call the servlet :
Can you share the exact path you are using to test the servlet resolution in Sling -> Sling Servlet Resolver.
Outside this issue, if you are looking to associate multiple selectors to a single servlet, use the respective property as many times needed. (for any multiple value property for that matter)
Example:
@Component(service=Servlet.class,
property={
ServletResolverConstants.SLING_SERVLET_METHODS+"=GET",
ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES+"=weretail/components/structure/page",
ServletResolverConstants.SLING_SERVLET_SELECTORS+"=testselector",
ServletResolverConstants.SLING_SERVLET_SELECTORS+"=testselectortwo",
ServletResolverConstants.SLING_SERVLET_EXTENSIONS+"=json"
})
Views
Replies
Total Likes
Views
Likes
Replies