sling.servlet.paths don't work in Servlet

arturl43391132

05-11-2019

Hello, AEM Community

I have the following issue:

I want to create a servlet which works with the following properties:

@Component(

   immediate = true,
   service = Servlet.class,
   property = {

   "sling.servlet.extensions=json",
   "sling.servlet.extensions=js",
   "sling.servlet.resourceTypes=sling/servlet/default",
   "sling.servlet.methods=GET",
   "sling.servlet.methods=HEAD",
   "sling.servlet.paths=/content/unified"
   }

)

public class UnifiedSettingsJSONServlet extends SlingSafeMethodsServlet {

...

}

But it activates on all paths, not only specified. If I delete "sling.servlet.resourceTypes=sling/servlet/default", it doesn't work at all. So, I think "sling.servlet.paths" is ignored and I don't know why. Do you have any ideas?

Use:

org.osgi.service.component.annotations.Component

AEM 6.3.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Arun_Patidar

MVP

05-11-2019

Hi,

You should not use extension if you are registering servlet by path.

The servlet is working with "sling.servlet.resourceTypes=sling/servlet/default", because you registered as default servlet.

There is a issue with path as well, you need to specify Execution path at http://localhost:4502/system/console/configMgr/org.apache.sling.servlets.resolver.SlingServletResolv...  if you are registering servlet by path

"sling.servlet.paths=/content/unified"

Please check sample servlet aem63app-repo/SimpleGetGroup.java at master · arunpatidar02/aem63app-repo · GitHub