Cannot get @SlingServlet from AEM project -DarchetypeVersion=11 | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 23, 2017 2:00 PM UTC

See this article - we cover that here: Creating a Mail List Sign Up Component for the Experience Manager Toy Store Site

The reason why I pointed you to this article is because you wanted to know why @SlingServlet did not work.

An important aspect to notice is the change on how an AEM Servlet is created. There is no longer @Service or @SlingServlet annotations in the org.osgi.service.component.annotations package.

In Maven Archetype 10 project, you defined a servlet like this:

@SlingServlet(paths="/bin/mySearchServlet", methods = "POST", metatype=true)

public class HandleClaim extends org.apache.sling.api.servlets.SlingAllMethodsServlet {

private static final long serialVersionUID = 2598426539166789515L;

However, in a Maven Archetype 11 project., you define an AEM Servlet like this (there is no @SlingServlet annotation):

@Component(service=Servlet.class,

property={

Constants.SERVICE_DESCRIPTION + "=Simple Demo Servlet",

"sling.servlet.methods=" + HttpConstants.METHOD_POST,

"sling.servlet.paths="+ "/bin/myDataSourcePoolServlet"

})

8 replies

baopham1340
New Participant
Oct 24, 2017 1:38 AM UTC

thank you so much!

Translate
smacdonald2008
Level 10
Oct 24, 2017 1:34 AM UTC

We have a FAQ on setting a whitelist for an OSGi that lets you set a service that uses admin creds. See this blog. Scott's Digital Community: Adobe Experience Manager FAQs and other Tips

there is a whitelist setting under Configurations. See the FAQ. Search whitelist in the blog item.

Translate
baopham1340
New Participant
Oct 24, 2017 1:24 AM UTC

Do we have an an article to introduce how to create the whitelist of path?

Translate
Feike_Visser1
Employee
Oct 23, 2017 2:31 PM UTC

You need to whitelist the path, bin is already done.

Should be in the logmessages too

Translate
baopham1340
New Participant
Oct 23, 2017 2:26 PM UTC

Thanks for this article...To resolved the issue above, I change the "/my-demo/servlet" to "bin/my-demo/servlet". But why must we start with "bin" on paths, I continue to research. Thanks all

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 23, 2017 2:00 PM UTC

See this article - we cover that here: Creating a Mail List Sign Up Component for the Experience Manager Toy Store Site

The reason why I pointed you to this article is because you wanted to know why @SlingServlet did not work.

An important aspect to notice is the change on how an AEM Servlet is created. There is no longer @Service or @SlingServlet annotations in the org.osgi.service.component.annotations package.

In Maven Archetype 10 project, you defined a servlet like this:

@SlingServlet(paths="/bin/mySearchServlet", methods = "POST", metatype=true)

public class HandleClaim extends org.apache.sling.api.servlets.SlingAllMethodsServlet {

private static final long serialVersionUID = 2598426539166789515L;

However, in a Maven Archetype 11 project., you define an AEM Servlet like this (there is no @SlingServlet annotation):

@Component(service=Servlet.class,

property={

Constants.SERVICE_DESCRIPTION + "=Simple Demo Servlet",

"sling.servlet.methods=" + HttpConstants.METHOD_POST,

"sling.servlet.paths="+ "/bin/myDataSourcePoolServlet"

})

Translate
baopham1340
New Participant
Oct 23, 2017 1:43 PM UTC

Thanks for your reply. I try to add "/" and the issue still happens. but I add bin/my-demo/servlet, I can get th result. Could you please tell me why put the 'bin' on paths ?

Translate
Feike_Visser1
Employee
Oct 23, 2017 1:35 PM UTC

should you not have: "/my-demo/servlet". to me you are missing the first /

Translate