This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-starter-test-services.git


The following commit(s) were added to refs/heads/master by this push:
     new 7f143bf  SLING-13029 Validate new Servlet API 6.1 Features (#19)
7f143bf is described below

commit 7f143bfe093828181c5c76a2ee518d376943c17e
Author: Stefan Seifert <[email protected]>
AuthorDate: Thu Dec 11 10:29:13 2025 +0100

    SLING-13029 Validate new Servlet API 6.1 Features (#19)
---
 .../servlets/Jakarta61RedirectServlet.java         | 59 ++++++++++++++++++++++
 .../testservices/servlets/Jakarta61Servlet.java    | 51 +++++++++++++++++++
 2 files changed, 110 insertions(+)

diff --git 
a/src/main/java/org/apache/sling/starter/testservices/servlets/Jakarta61RedirectServlet.java
 
b/src/main/java/org/apache/sling/starter/testservices/servlets/Jakarta61RedirectServlet.java
new file mode 100644
index 0000000..1a9c2e8
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/starter/testservices/servlets/Jakarta61RedirectServlet.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.starter.testservices.servlets;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import jakarta.servlet.Servlet;
+import jakarta.servlet.http.HttpServletResponse;
+import org.apache.sling.api.SlingJakartaHttpServletRequest;
+import org.apache.sling.api.SlingJakartaHttpServletResponse;
+import org.apache.sling.api.servlets.SlingJakartaSafeMethodsServlet;
+import org.apache.sling.servlets.annotations.SlingServletPathsStrict;
+import org.jetbrains.annotations.NotNull;
+import org.osgi.service.component.annotations.Component;
+
+/**
+ * Jakarta Servlet using new sendRedirect overload and new HTTP status 
constant added in Servlet API 6.1.
+ */
+@Component(service = Servlet.class)
+@SlingServletPathsStrict(paths = "/bin/jakarta-servlet61-redirect", extensions 
= "txt")
+public class Jakarta61RedirectServlet extends SlingJakartaSafeMethodsServlet {
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    protected void doGet(
+            @NotNull SlingJakartaHttpServletRequest request, @NotNull 
SlingJakartaHttpServletResponse response)
+            throws IOException {
+
+        // Prepare a custom body to check clearBuffer behavior
+        response.setContentType("text/plain");
+        response.setCharacterEncoding(StandardCharsets.UTF_8);
+        response.getWriter().write("Custom body before redirect");
+
+        // Use 6.1-only overload (custom status + keep buffer)
+        response.sendRedirect(
+                request.getContextPath() + "/jakarta-servlet61.txt",
+                HttpServletResponse.SC_PERMANENT_REDIRECT, // 308, new in 6.1 
spec
+                false // do NOT clear buffer
+                );
+    }
+}
diff --git 
a/src/main/java/org/apache/sling/starter/testservices/servlets/Jakarta61Servlet.java
 
b/src/main/java/org/apache/sling/starter/testservices/servlets/Jakarta61Servlet.java
new file mode 100644
index 0000000..01a9855
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/starter/testservices/servlets/Jakarta61Servlet.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.starter.testservices.servlets;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import jakarta.servlet.Servlet;
+import org.apache.sling.api.SlingJakartaHttpServletRequest;
+import org.apache.sling.api.SlingJakartaHttpServletResponse;
+import org.apache.sling.api.servlets.SlingJakartaSafeMethodsServlet;
+import org.apache.sling.servlets.annotations.SlingServletPathsStrict;
+import org.jetbrains.annotations.NotNull;
+import org.osgi.service.component.annotations.Component;
+
+/**
+ * Jakarta Servlet using new setCharacterEncoding overload added in Servlet 
API 6.1.
+ */
+@Component(service = Servlet.class)
+@SlingServletPathsStrict(paths = "/bin/jakarta-servlet61", extensions = "txt")
+public class Jakarta61Servlet extends SlingJakartaSafeMethodsServlet {
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    protected void doGet(
+            @NotNull SlingJakartaHttpServletRequest request, @NotNull 
SlingJakartaHttpServletResponse response)
+            throws IOException {
+
+        response.setContentType("text/plain");
+        // setCharacterEncoding overload with Charset added in Servlet API 6.1
+        response.setCharacterEncoding(StandardCharsets.UTF_8);
+        response.getWriter().write("Hello Servlet API 6.1");
+    }
+}

Reply via email to