Apache Sling API

Clone this repo:
  1. 518de69 SLING-12643 : Support Jakarta ServletAPI in Scripting by Carsten Ziegeler · 10 days ago master
  2. bd53489 SLING-12643 : Support Jakarta ServletAPI in Scripting by Carsten Ziegeler · 2 weeks ago
  3. 009ebd6 SLING-12757 : AbstractResource.getName() can throw exceptions (#58) by Carsten Ziegeler · 4 weeks ago
  4. 13ac9b0 SLING-12643 : Support Jakarta ServletAPI in Scripting by Carsten Ziegeler · 4 weeks ago
  5. 65b234e SLING-12761 : Use default method for deprecated method in ResourceDecorator by Carsten Ziegeler · 7 weeks ago

Apache Sling

Build Status Test Status Coverage Sonarcloud Status JavaDoc Maven Central License

Apache Sling API

This module is part of the Apache Sling project.

The Sling API defines an extension to the Jakarta Serlvet API 6.0 to provide access to content and unified access to request parameters hiding the differences between the different methods of transferring parameters from client to server. Note that the Sling API bundle does not include the Servlet API but instead requires the API to be provided by the Servlet container in which the Sling framework is running or by another bundle.

Updating to Sling API 3

Sling API 3 adds support for Jakarta Servlet API. Updating to the latest API version should just be a drop-in replacement. However, there are some points to considers.

Dependency to Jakarta Servlet API

As the API references the Jakarta Servlet API in several signatures, it is very likely that you need to add the Jakarta Servlet API to the dependency list of your project. And that is in addition to the already existing dependency to the Javax Servlet API.

Add a dependency like jakarta.servlet:jakarta.servlet-api:6.1.0 to your project.

At runtime, you need a container implementing the Jakarta Servlet API. For example, you can use Apache Felix Http Jetty 12.

Minimum Java Runtime

As the Jakarta Servlet API requires Java 17, the Sling API now requires Java 17 as a minimum Java version at runtime as well.

Source Code Incompatibilties

For some methods where a Javax Servlet Type is used in the signature, an alternative method has been added with the same name but different signature. This can lead to compilation errors due to disambigutie if the actual argument is null. However, all of these methods do not allow null as an argument, therefore this should not create a problem in reality.

If such compilation error occurs nevertheless, a quick (but wrong) fix is to cast null to the Jakarta Servlet API type. However, the correct fix is to not call this method with a null argument at all and change the code accordingly.

Migrating from Servlet API 3 to Jakarta Servlet API 6

With the release of Sling API Version 3, the Jakarta Servlet API is used as the base. Previous releases are based on the Javax Servlet API 3. While the API based on Servlet 3 is still available and functional, it is mainly there for compatiblity. All new code should leverage Jakarta Servelt API and it is advised to migrate existing code.

In most cases, the migration is as simply as a series of search and replace operations. For Sling API based on Servlet 3 there is an alternative with the same functionality based on Jakarta Servlet API. However, for API that has been deprecated already, there is no alternative. Therefore, all usage of deprecated Sling API needs to be replaced first.

The following table lists the replacements:

FeatureServlet API 3Jakarta Servlet API 6
Package Prefixjavax.servletjakarta.servlet
Request InterfaceSlingHttpServletRequestSlingJakartaHttpServletRequest
Response InterfaceSlingHttpServletResponseSlingJakartaHttpServletResponse
Event InterfaceSlingRequestEventSlingJakartaRequestEvent
Event ListenerSlingRequestListenerSlingJakartaRequestListener
BuildersSlingHttpServletRequestBuilder.build()SlingHttpServletRequestBuilder.buildJakartaRequest()
BuildersSlingHttpServletResponseBuilder.build()SlingHttpServletResponseBuilder.buildJakartaResponse()
BuildersSlingHttpServletResponseResultSlingJakartaHttpServletResponseResult
Media RangeMediaRangeListJakartaMediaRangeList
ScriptingSlingBindingsNew methods for request and response
ScriptingSlingScriptHelperNew mthods for request and response
Error HandlingErrorHandlerJakartaErrorHandler
ScriptingOptingServletJakartaOptinServlet
ScriptingSlingAllMethodsServletSlingJakartaAllMethodsServlet
ScriptingSlingSafeMethodsServletSlingJakartaSafeMethodsServlet
WrapperSlingHttpServletRequestWrapperSlingJakartaHttpServletRequestWrapper
WrapperSlingHttpServletResponseWrapperSlingJakartaHttpServletResponseWrapper