Expand my Community achievements bar.

SOLVED

Servlet custom path gives error 406 Not Acceptable

Avatar

Level 2

Here is my servlet code,

@component(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

Screenshot 2023-08-07 at 19.33.42.png

 any help what am I missing here.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

core-services-api.png

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

recent-request-api.jpg

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.

View solution in original post

3 Replies

Avatar

Community Advisor

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

Avatar

Correct answer by
Community Advisor

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

core-services-api.png

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

recent-request-api.jpg

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.

Avatar

Level 2

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