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

How to find out an resourceType in aem

Avatar

Level 3

I have a servlet that has resource type = sling/servlet/default. How can I find a resource inside my project or how can i create a resource/component with this resourcetype

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@vineetham123 ,

In this case, replace the value of the CommonConstants.SLING_SERVLET_DEFAULT with the resource type of the page you create. You can find the resource type of any page by going into http://localhost:4502/crx/de/index.jsp and search with the page path you created. Copy the value of "sling:resourceType" property of the page you created and update your Servlet with that value.

Hope this helps!

 

 

View solution in original post

6 Replies

Avatar

Community Advisor

Hi @vineetham123 
Could you please explain use case in details?



Arun Patidar

Avatar

Community Advisor

Hello @vineetham123 

 

Please refer to this documentation https://sling.apache.org/documentation/the-sling-engine/servlets.html

 

A default Servlet is selected if no servlet (or script) for the current resource type can be found. To make the provisioning of a default Servlet as versatile as provisioning per resource type Servlets (or scripts), the default Servlet is selected with just a special resource type sling/servlet/default.

 

As you would notice, its not a real resource type but a fallback. A way to define a Default Servlet. So, we don't create components using this resource type. It is just used to create Default Servlets

 


Aanchal Sikka

Avatar

Level 3

Thanks for the response @aanchal-sikka . See the below code

@Component(service = {Servlet.class})
@SlingServletResourceTypes(
resourceTypes = {
CommonConstants.SLING_SERVLET_DEFAULT},
methods = HttpConstants.METHOD_GET,
selectors = {"destination"},
extensions = "json")
@SlingServletName(servletName = "Sample Vegetable Shop Servlet")
@ServiceDescription("Santhosh Vegetables - Veggie Servlet")
public class DestinationServlet extends SlingSafeMethodsServlet {
}

 

How can I access this in debug mode, (suppose that I know how to debug in aem) ,and suppose that I dont have enough packages in my local machine. I need to create some pages and fire a url that will eventually hit this servlet 

Avatar

Correct answer by
Community Advisor

@vineetham123 ,

In this case, replace the value of the CommonConstants.SLING_SERVLET_DEFAULT with the resource type of the page you create. You can find the resource type of any page by going into http://localhost:4502/crx/de/index.jsp and search with the page path you created. Copy the value of "sling:resourceType" property of the page you created and update your Servlet with that value.

Hope this helps!

 

 

Avatar

Community Advisor

@vineetham123 

 

This is very frequently used with assets. Example:

http://localhost:4502/content/dam/wknd/en/site/not-found.jpg.destination.json

 

Even this would work

http://localhost:4502/content/wknd/language-master.destination.json will call your servlet, due to selector and extension

http://localhost:4502/content/wknd/language-masters.model.json will return results from OOTB Page model

 

In a way, the servlet is no longer bound to a resource type... Rather becomes available for generic use


Aanchal Sikka

Avatar

Administrator

@vineetham123 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni