Siva Isukapalli
Siva Isukapalli

Reputation: 49

AEM 6.2 upgrade : Custom servlet paths not working after upgrade

We have custom servlets with registered servlet paths starting with /api/v1/ , /api/v2/. These were working fine on 5.6.1. Just after upgrade to 6.2 ( we skipped 6 and 6.1), these servlets started giving 404.

As per docs if we list these paths in felix console configuration Apache sling servlet/script Resolver and Error handler these servlets should be working. I did and still get a 404.

Also if I use the servlet resolver and see what the path evaluates to, it points to the correct servlet's class.

Any idea what extra configuration is required just for 6.2?

Adding recent request logs:

Request 47301 (GET /bin/offers/list) by admin - RequestProgressTracker Info
      0 TIMER_START{Request Processing}
      0 COMMENT timer_end format is {<elapsed msec>,<timer name>} <optional message>
      0 LOG Method=GET, PathInfo=/bin/offers/list
      0 TIMER_START{ResourceResolution}
      0 TIMER_END{0,ResourceResolution} URI=/bin/offers/list resolves to Resource=ServletResource, servlet=com.xyz.v2.servlets.OffersListServlet, path=/bin/offers/list
      0 LOG Resource Path Info: SlingRequestPathInfo: path='/bin/offers/list', selectorString='null', extension='null', suffix='null'
      0 TIMER_START{ServletResolution}
      0 TIMER_START{resolveServlet(/bin/offers/list)}
      0 TIMER_END{0,resolveServlet(/bin/offers/list)} Using servlet com.xyz.v2.servlets.OffersListServlet
      0 TIMER_END{0,ServletResolution} URI=/bin/offers/list handled by Servlet=com.xyz.v2.servlets.OffersListServlet

/api/v2/user

Request 47279 (GET /api/v2/user) by admin - RequestProgressTracker Info
      0 TIMER_START{Request Processing}
      0 COMMENT timer_end format is {<elapsed msec>,<timer name>} <optional message>
      0 LOG Method=GET, PathInfo=/api/v2/user
      0 TIMER_START{ResourceResolution}
      0 TIMER_END{0,ResourceResolution} URI=/api/v2/user resolves to Resource=ServletResource, servlet=com.xyz.servlets.UserServlet, path=/api/v2/user
      0 LOG Resource Path Info: SlingRequestPathInfo: path='/api/v2/user', selectorString='null', extension='json', suffix='null'
      0 TIMER_START{ServletResolution}
      0 TIMER_START{resolveServlet(/api/v2/user)}
      0 TIMER_END{0,resolveServlet(/api/v2/user)} Using servlet com.xyz.servlets.UserServlet
      0 TIMER_END{0,ServletResolution} URI=/api/v2/user handled by Servlet=com.xyz.servlets.UserServlet
      0 LOG Applying Requestfilters
      0 LOG Calling filter: com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl
      0 LOG Calling filter: org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter
      0 LOG Calling filter: com.adobe.granite.rest.impl.servlet.ApiResourceFilter
      0 LOG Including resource ApiResourceWrapper, type=granite/rest/core/resource, path=/api/v2/user, resource=[ServletResource, servlet=com.xyz.servlets.UserServlet, path=/api/v2/user] (SlingRequestPathInfo: path='/api/v2/user', selectorString='null', extension='json', suffix='null')
      0 TIMER_START{resolveServlet(/api/v2/user)}
      0 TIMER_END{0,resolveServlet(/api/v2/user)} Using servlet com.adobe.granite.rest.impl.servlet.DefaultGETServlet
      0 LOG Applying Forwardfilters

Upvotes: 0

Views: 1617

Answers (2)

mickleroy
mickleroy

Reputation: 1008

As of AEM 6.2, the /api resource is reserved for the Siren+JSON API used to expose content from the JCR.

Try the following URL for yourself: http://localhost:4502/api/content.json

{
    "entities": [
        {
            "links": [
                {
                    "rel": [
                        "self"
                    ],
                    "href": "http://localhost:4502/api/content/sites/geometrixx-outdoors.json"
                },
                {
                    "rel": [
                        "content"
                    ],
                    "href": "http://localhost:4502/content/geometrixx-outdoors.html"
                }
            ],
            "class": [
                "content/page"
            ],
            "properties": {
                "dc:description": "Geometrixx Outdoors - fashion that doesn't sacrifice style for comfort",
                "dc:title": "Geometrixx Outdoors Site",
                "name": "geometrixx-outdoors",
                "redirectTarget": "/content/geometrixx-outdoors/en"
            }
        }
    ],
    "class": [
        "content/page"
    ],
    "properties": {
        "dc:title": "Content Root",
        "name": "content",
        "srn:paging": {
            "total": 13,
            "offset": 0,
            "limit": 20
        }
    }
}

More info: https://github.com/kevinswiber/siren

Upvotes: 0

Ameesh Trikha
Ameesh Trikha

Reputation: 1712

From initial investigation into you resourceResolution I can say that the /api based resources are handled differently in AEM 6.2.

The filter com.adobe.granite.rest.impl.servlet.ApiResourceFilter checks if the resource path starts with /api, this is configured in ApiEndpointResourceProviderFactoryImpl you can check in felix configurations - /system/console/configMgr/com.adobe.granite.rest.impl.ApiEndpointResourceProviderFactoryImpl

This filter then wraps your request resource to as granite/rest/core/resource in ApiResourceWrapper which totally changes the resource resolution for your call, which is no longer a call to a path based servlet but a GET call to an existing resource that gets handled by DefaultGETServlet which doesn't know what to do with this resource and thus gives out 404.

I am not entirely sure what is the purpose of the /api based specific handling as its not something available in documentation, so i would not suggest changing the felix configurations - /system/console/configMgr/com.adobe.granite.rest.impl.ApiEndpointResourceProviderFactoryImpl unless Adobe confirms it. You should reach out DayCare for getting assistance on the issue.

Upvotes: 1

Related Questions