Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

where ware the "new" annotations for servlets?

Avatar

Avatar
Validate 10
Level 4
TB3dock
Level 4

Likes

23 likes

Total Posts

172 posts

Correct Reply

4 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Validate 10
Level 4
TB3dock
Level 4

Likes

23 likes

Total Posts

172 posts

Correct Reply

4 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 1
View profile
TB3dock
Level 4

18-04-2021

This page: https://sling.apache.org/documentation/the-sling-engine/servlets.html has an embeded presentation which has servlet declarations like this:

 

@SlingServiceResourceTypes(resourceTypes="xx/yy/zz") etc.

 

However, all the examples and AEM docs seem to only support this older format:

 

@component(service = Servlet.class, property = { Constants.SERVICE_DESCRIPTION + "=something",

"sling.servlet.methods=" + HttpConstants.METHOD_GET, "sling.servlet.paths=" + "/bin/api/mypath" })

 

Is this new format available in the latest cloud SDK, and are there any examples of it does anyone know?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Affirm 100
Level 10
asutosh_jena
Level 10

Likes

373 likes

Total Posts

480 posts

Correct Reply

133 solutions
Top badges earned
Affirm 100
Ignite 1
Establish
Give Back 50
Give Back 5
View profile

Avatar
Affirm 100
Level 10
asutosh_jena
Level 10

Likes

373 likes

Total Posts

480 posts

Correct Reply

133 solutions
Top badges earned
Affirm 100
Ignite 1
Establish
Give Back 50
Give Back 5
View profile
asutosh_jena
Level 10

18-04-2021

Hi @TB3dock 

 

OSGi DS 1.4 (R7) component property type annotations for Sling Servlets (recommended) is supported from bnd-maven-plugin 4.1.0+ and maven-bundle-plugin 4.1.0+ and this is the recommended approach to write the Servlet. I personally am using this on my AEM 6.5.5.0 instance and it's not specific to AEM as Cloud SDK.

 

@Component(service = {Servlet.class})
@SlingServletResourceTypes(
resourceTypes = "/apps/my/type",
methods = "GET",
extensions = "html",
selectors = "hello")
public class MyServlet extends SlingSafeMethodsServlet {

@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
...
}
}

 

Simple OSGi DS 1.2 annotations were used earlier and also can be used now only if we cannot use the above approach which I believe will never be a case 🙂

All the articles that are written so far are before DS 1.4 was released and it's never updated. But we should always refer the Sling document for updates.

 

@Component(service = {Servlet.class},
property = {
ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES + "=/apps/my/type"
ServletResolverConstants.SLING_SERVLET_METHODS + "=GET",
ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=html",
ServletResolverConstants.SLING_SERVLET_SELECTORS + "=hello",
}
)
public class MyServlet extends SlingSafeMethodsServlet {

@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
...
}
}

 

I will suggest that you should go with DS 1.4 version.

 

Hope this helps!

Thanks

Answers (0)