I am deploying a Sling Servlet to AEM and would like to use resourceTypes, selectors, and extensions, but they're not working. Paths on the other hand, do work. Any idea what the issue is?
This works:
@SlingServlet(paths = {"/services/powerproxy/groups"}) public class GroupServlet extends SlingAllMethodsServlet {...}
localhost:4502/services/powerproxy/groups result in a HTTP 200
This doesn't:
@SlingServlet(methods = {"GET"}, metatype = true, resourceTypes = {"services/powerproxy"}, selectors = {"groups"}) public class GroupServlet extends SlingAllMethodsServlet {...}
localhost:4502/services/powerproxy/groups results in a HTTP 404
Solved! Go to Solution.
Runal.Trivedi answer works nicely. I tested it out and got:
20.04.2015 13:16:54.081 *INFO* [0:0:0:0:0:0:0:1 [1429550214075] GET /content/geometrixx/en/servletpage.groups.html HTTP/1.1] com.adobe.cq.sling.HandleClaim ---> THIS IS THE GET METHOD OF slingSevletApp/components/page/slingTemplate
Of course my servlet simply printed this line to the log file.
WHen you want to bind a servlet to a page - use ResouceType binding.
However - when you want to post values from a CQ page to a servlet (ie - using AJAX):
[img]Client.png[/img]
bind you servlet to a path - which is a supported way:
https://sling.apache.org/documentation/the-sling-engine/servlets.html
For those reading this and want to use AJAX to post form values to a Sling Servlet (that uses Path binding) - see:
https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html
Here is the AEM article that talks about binding a servlet using ResourceType - including how to invoke it:
https://helpx.adobe.com/experience-manager/using/resourcetypes.html
You may need to change how you are accessing the servlet, Please see this - https://sling.apache.org/documentation/the-sling-engine/servlets.html#example-registration-by-resour...
Views
Replies
Total Likes
Basically you POST/GET to a node of your repository which has sling:resourceType property same as declared in your Servlets annotation.
You can further let your Servlet get invoked if your post/get path contains selectors, which in your case is "groups".
Now coming to your example:
Hope it clarifies your doubts.
- Runal
I've read that several times. I don't understand what you mean by "change how you are accessing the servlet". Can you elaborate?
Views
Replies
Total Likes
Runal.Trivedi answer works nicely. I tested it out and got:
20.04.2015 13:16:54.081 *INFO* [0:0:0:0:0:0:0:1 [1429550214075] GET /content/geometrixx/en/servletpage.groups.html HTTP/1.1] com.adobe.cq.sling.HandleClaim ---> THIS IS THE GET METHOD OF slingSevletApp/components/page/slingTemplate
Of course my servlet simply printed this line to the log file.
WHen you want to bind a servlet to a page - use ResouceType binding.
However - when you want to post values from a CQ page to a servlet (ie - using AJAX):
[img]Client.png[/img]
bind you servlet to a path - which is a supported way:
https://sling.apache.org/documentation/the-sling-engine/servlets.html
For those reading this and want to use AJAX to post form values to a Sling Servlet (that uses Path binding) - see:
https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html
Here is the AEM article that talks about binding a servlet using ResourceType - including how to invoke it:
https://helpx.adobe.com/experience-manager/using/resourcetypes.html
Hi,
you can use the binding on the resource type irrespective of the HTTP method you want to use. Of course it makes the creation of the javascript a bit easier, if you can hardcode a path for the POST request, but on the server side this doesn't matter.
kind regards,
Jörg
Views
Replies
Total Likes
the correct way to access the servlet registered by resourceTypes would be something like the following-
localhost:4502/<path-to-a-resource-with-resourcetype-services-powerproxy>.groups
the following code in powerproxy.jsp should call the servlet-
<form name="frm" method="post" action="<c:out value="${resource.path}" />.group"> //form stuff // <input type="submit" /> </form>
Views
Replies
Total Likes
This needs to be captured in a community article. If this works, we will get this use case in an AEM community article. We have one for path.
Views
Replies
Total Likes
here is a code sample-
servlet registration: https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/ad...
servlet call: https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/content/src/main/content/jc... (line 44)
Views
Replies
Total Likes
Hi,
I am new to AEM technology . Can someone tell me what is services/powerproxy resourceType Exactly mean?? When and Where it is used for
Views
Replies
Total Likes
really helpful....this is wat the way i can invoke my servlet (which has been regeistered by using resourceType instead of path).
just need to hit the page(obviously having the same resoruceType for which i made my servlet ) with the extension mentioned in servlet.
is that correct ?
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies