Servlet custom path gives error 406 Not Acceptable | Community
Skip to main content
Level 2
August 7, 2023
Solved

Servlet custom path gives error 406 Not Acceptable

  • August 7, 2023
  • 2 replies
  • 2110 views

Here is my servlet code,

@8220494(service = { Servlet.class }) @SlingServletPaths(value = "/api/assets/eshop") @ServiceDescription("Get Filtered Assets based on properties and custom response.") public class AssetFilter extends SlingAllMethodsServlet {

 

and I have also made the entry in Script Resolver

 any help what am I missing here.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by lukasz-m

Hi @anuj31005349h74z,

The problem is caused by the fact that you are using endpoint that matches AEM OOTB REST api. In general everything starting with /api/* is part of AEM Core Service and will be handheld by com.adobe.granite.rest.impl.servlet.ApiResourceFilter. You can see all available main endpoints under /api.json

You can observe under /system/console/requests, how /api/* requests are handled:

If you have to use /api prefix, avoid paths like: /api/assets, /api/screens, /api/screens-dcc, /api/content.

Your custom servlet will not be correctly handled by OOTB mechanism, this is why you are getting 406 status.

To solve the problem you can change change your path from /api/assets/eshop to /api/asset/eshop, or use different pattern for the path starting with api except path listed above. However using /bin would be the best idea, as it will not require changes under Servlet/Script resolver.

2 replies

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
August 7, 2023

Hi,

Firstly, the "@component" annotation is incorrect; it should be capitalized as follows: "@Component." I would assume this is a typographical error and not the primary reason for your issue.

In addition, could you please verify whether this servlet is being resolved by accessing http://localhost:4502/system/console/servletresolver? If not, there is an issue with your code deployment

 

Also, could you compare your code with this example and identify any differences?: https://sourcedcode.com/blog/aem/slingservletpaths-example-code-in-aem

Esteban Bustamante
lukasz-m
Community Advisor
lukasz-mCommunity AdvisorAccepted solution
Community Advisor
August 7, 2023

Hi @anuj31005349h74z,

The problem is caused by the fact that you are using endpoint that matches AEM OOTB REST api. In general everything starting with /api/* is part of AEM Core Service and will be handheld by com.adobe.granite.rest.impl.servlet.ApiResourceFilter. You can see all available main endpoints under /api.json

You can observe under /system/console/requests, how /api/* requests are handled:

If you have to use /api prefix, avoid paths like: /api/assets, /api/screens, /api/screens-dcc, /api/content.

Your custom servlet will not be correctly handled by OOTB mechanism, this is why you are getting 406 status.

To solve the problem you can change change your path from /api/assets/eshop to /api/asset/eshop, or use different pattern for the path starting with api except path listed above. However using /bin would be the best idea, as it will not require changes under Servlet/Script resolver.

Level 2
August 8, 2023

Thanks. It was really helpful. And I was wondering why every other url works, but this.