Skip to content

Conversation

@rombert
Copy link
Contributor

@rombert rombert commented Jan 23, 2026

Implement a fallback for adapting from the legacy javax servlet requerst when adapting from the jakarta request fails.

Adapters are normally expected to be registered for the legacy javax.servlet-based APIs and we need the adaptions to keep working for backwards compatibility.

@rombert
Copy link
Contributor Author

rombert commented Jan 23, 2026

This seems to fix the problem but needs more testing.

At a minimum we will need to implement the same fallback for the response object.

@kwin
Copy link
Member

kwin commented Jan 24, 2026

Shouldn't this kind of fallback rather be implemented in Sling Models (i.e. register the Model for both servlet request types). Having this for all kind of adaptations feels too magic to me.

@rombert
Copy link
Contributor Author

rombert commented Jan 24, 2026 via email

…letRequest cannot be instantiated a Jakarta context

Implement a fallback for adapting from the legacy javax servlet requerst when adapting
from the jakarta request fails.

Adapters are normally expected to be registered for the legacy javax.servlet-based APIs and
we need the adaptions to keep working for backwards compatibility.
@rombert
Copy link
Contributor Author

rombert commented Feb 2, 2026

Shouldn't this kind of fallback rather be implemented in Sling Models (i.e. register the Model for both servlet request types). Having this for all kind of adaptations feels too magic to me.

BTW, this is what apache/sling-org-apache-sling-models-impl#77 aims to do and it is not enough:

  • we need to handle regular adaptables, not only only Sling Models
  • when running in a Jakarta environment, the SlingHttpServletRequest.adaptTo call delegates to the actual impl from the Sling Engine, which is a Jakarta impl, therefore only considering adapter factories that adapt from the SlingJakartaHttpServletRequest, leading to this problem.

One possible alternative would be to add a ServiceListener which registers adapter factories for all adapters from SlingHttpServlet(Request|Response) to match their Jakarta counterparts. I haven't tested it that works but for me it has the same degree of 'magic' and the code would be more complicated. I took this kind of approach in apache/sling-org-apache-sling-servlets-post#33, but only because the existing infrastructure already existed; I don't think we should go that way unless we have strong reasons.

…letRequest cannot be instantiated a Jakarta context

Also support adapting from javax to jakarta request directly.
…letRequest cannot be instantiated a Jakarta context

Document adaption logic and add back the missing return statement for the original adaption result.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 9, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@rombert rombert marked this pull request as ready for review February 11, 2026 17:57
@rombert rombert merged commit c120aeb into master Feb 11, 2026
1 check was pending
@rombert rombert deleted the issue/SLING-13071 branch February 11, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants