diff --git a/api/src/main/java/jakarta/servlet/SessionCookieConfig.java b/api/src/main/java/jakarta/servlet/SessionCookieConfig.java index 2cf0194c4..26d706a33 100644 --- a/api/src/main/java/jakarta/servlet/SessionCookieConfig.java +++ b/api/src/main/java/jakarta/servlet/SessionCookieConfig.java @@ -108,36 +108,6 @@ public interface SessionCookieConfig { */ String getPath(); - /** - * With the adoption of support for RFC 6265, this method should no longer be used. - *

- * If called, this method has no effect. - * - * @param comment ignore - * - * @throws IllegalStateException if the ServletContext from which this SessionCookieConfig was - * acquired has already been initialized - * - * @see jakarta.servlet.http.Cookie#setComment(String) - * @see jakarta.servlet.http.Cookie#getVersion - * - * @deprecated This is no longer required with RFC 6265 - */ - @Deprecated(since = "Servlet 6.0", forRemoval = true) - void setComment(String comment); - - /** - * With the adoption of support for RFC 6265, this method should no longer be used. - * - * @return Always {@code null} - * - * @see jakarta.servlet.http.Cookie#getComment() - * - * @deprecated This is no longer required with RFC 6265 - */ - @Deprecated(since = "Servlet 6.0", forRemoval = true) - String getComment(); - /** * Marks or unmarks the session tracking cookies created on behalf of the application represented by the * ServletContext from which this SessionCookieConfig was acquired as HttpOnly. diff --git a/api/src/main/java/jakarta/servlet/http/Cookie.java b/api/src/main/java/jakarta/servlet/http/Cookie.java index 695de0384..1220beba0 100644 --- a/api/src/main/java/jakarta/servlet/http/Cookie.java +++ b/api/src/main/java/jakarta/servlet/http/Cookie.java @@ -132,36 +132,6 @@ public Cookie(String name, String value) { this.value = value; } - /** - * With the adoption of support for RFC 6265, this method should no longer be used. - *

- * If called, this method has no effect. - * - * @param purpose This parameter is ignored - * - * @see #getComment - * - * @deprecated This is no longer required with RFC 6265 - */ - @Deprecated(since = "Servlet 6.0", forRemoval = true) - public void setComment(String purpose) { - // NO-OP - } - - /** - * With the adoption of support for RFC 6265, this method should no longer be used. - * - * @return Always {@code null} - * - * @see #setComment - * - * @deprecated This is no longer required with RFC 6265 - */ - @Deprecated(since = "Servlet 6.0", forRemoval = true) - public String getComment() { - return null; - } - /** * * Specifies the domain within which this cookie should be presented. @@ -339,36 +309,6 @@ public String getValue() { return value; } - /** - * With the adoption of support for RFC 6265, this method should no longer be used. - * - * @return Always 0 - * - * @see #setVersion - * - * @deprecated This is no longer required with RFC 6265 - */ - @Deprecated(since = "Servlet 6.0", forRemoval = true) - public int getVersion() { - return 0; - } - - /** - * With the adoption of support for RFC 6265, this method should no longer be used. - *

- * If called, this method has no effect. - * - * @param v This parameter is ignored - * - * @see #getVersion - * - * @deprecated This is no longer required with RFC 6265 - */ - @Deprecated(since = "Servlet 6.0", forRemoval = true) - public void setVersion(int v) { - // NO-OP - } - /* * Tests a string and returns true if the string contains a reserved characters for the Set-Cookie header. * @@ -553,7 +493,6 @@ public boolean equals(Object obj) { Cookie c = (Cookie) obj; return Objects.equals(getName(), c.getName()) && Objects.equals(getValue(), c.getValue()) && - getVersion() == c.getVersion() && Objects.equals(getAttributes(), c.getAttributes()); } return false; diff --git a/api/src/main/java/jakarta/servlet/http/HttpServlet.java b/api/src/main/java/jakarta/servlet/http/HttpServlet.java index e9810381b..f5da1864a 100644 --- a/api/src/main/java/jakarta/servlet/http/HttpServlet.java +++ b/api/src/main/java/jakarta/servlet/http/HttpServlet.java @@ -86,21 +86,9 @@ public abstract class HttpServlet extends GenericServlet { // Add headers in lower case as HTTP headers are case insensitive private static final List SENSITIVE_HTTP_HEADERS = Arrays.asList("authorization", "cookie", "x-forwarded", "forwarded", "proxy-authorization"); - /** - * The parameter obtained {@link ServletConfig#getInitParameter(String)} to determine if legacy processing of - * {@link #doHead(HttpServletRequest, HttpServletResponse)} is provided. - * - * @deprecated may be removed in future releases - * @since Servlet 6.0 - */ - @Deprecated(forRemoval = true, since = "Servlet 6.0") - public static final String LEGACY_DO_HEAD = "jakarta.servlet.http.legacyDoHead"; - private static final String LSTRING_FILE = "jakarta.servlet.http.LocalStrings"; private static final ResourceBundle lStrings = ResourceBundle.getBundle(LSTRING_FILE); - private boolean legacyHeadHandling; - /** * Does nothing, because this is an abstract class. * @@ -112,7 +100,6 @@ public HttpServlet() { @Override public void init(ServletConfig config) throws ServletException { super.init(config); - legacyHeadHandling = Boolean.parseBoolean(config.getInitParameter(LEGACY_DO_HEAD)); } /** @@ -204,10 +191,7 @@ protected long getLastModified(HttpServletRequest req) { * protects itself from being called multiple times for one HTTP HEAD request). * *

- * The default implementation calls {@link #doGet(HttpServletRequest, HttpServletResponse)}. If the - * {@link ServletConfig} init parameter {@link #LEGACY_DO_HEAD} is set to "TRUE", then the response instance is wrapped - * so that the response body is discarded. - * + * The default implementation calls {@link #doGet(HttpServletRequest, HttpServletResponse)}. *

* If the HTTP HEAD request is incorrectly formatted, doHead returns an HTTP "Bad Request" message. * @@ -220,13 +204,7 @@ protected long getLastModified(HttpServletRequest req) { * @throws ServletException if the request for the HEAD could not be handled */ protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - if (legacyHeadHandling) { - NoBodyResponse response = new NoBodyResponse(resp); - doGet(req, response); - response.setContentLength(); - } else { - doGet(req, resp); - } + doGet(req, resp); } /** diff --git a/api/src/main/java/jakarta/servlet/http/HttpServletRequest.java b/api/src/main/java/jakarta/servlet/http/HttpServletRequest.java index 40e436e8d..31b814f5e 100644 --- a/api/src/main/java/jakarta/servlet/http/HttpServletRequest.java +++ b/api/src/main/java/jakarta/servlet/http/HttpServletRequest.java @@ -296,7 +296,7 @@ public String toString() { * * @deprecated In favor of 103 early hints */ - @Deprecated + @Deprecated(forRemoval = true) default PushBuilder newPushBuilder() { return null; } diff --git a/api/src/main/java/jakarta/servlet/http/HttpServletRequestWrapper.java b/api/src/main/java/jakarta/servlet/http/HttpServletRequestWrapper.java index 40e9b1676..0ba399cef 100644 --- a/api/src/main/java/jakarta/servlet/http/HttpServletRequestWrapper.java +++ b/api/src/main/java/jakarta/servlet/http/HttpServletRequestWrapper.java @@ -334,7 +334,7 @@ public T upgrade(Class handlerClass) throws IO * * @deprecated In favor of 103 early hints */ - @Deprecated + @Deprecated(forRemoval = true) @Override public PushBuilder newPushBuilder() { return this._getHttpServletRequest().newPushBuilder(); diff --git a/api/src/main/java/jakarta/servlet/http/PushBuilder.java b/api/src/main/java/jakarta/servlet/http/PushBuilder.java index 022d9da90..ceeae7d35 100644 --- a/api/src/main/java/jakarta/servlet/http/PushBuilder.java +++ b/api/src/main/java/jakarta/servlet/http/PushBuilder.java @@ -86,7 +86,7 @@ * * @deprecated In favor of 103 early hints */ -@Deprecated +@Deprecated(forRemoval = true) public interface PushBuilder { /** *

diff --git a/api/src/test/java/ee/jakarta/servlet/http/CookieTest.java b/api/src/test/java/ee/jakarta/servlet/http/CookieTest.java index 5aa02589b..c99db19c2 100644 --- a/api/src/test/java/ee/jakarta/servlet/http/CookieTest.java +++ b/api/src/test/java/ee/jakarta/servlet/http/CookieTest.java @@ -32,19 +32,16 @@ import org.junit.jupiter.params.provider.ValueSource; public class CookieTest { - @SuppressWarnings("removal") @Test public void testCookie() { Cookie cookie = new Cookie("name", "value"); assertThat(cookie.getName(), is("name")); assertThat(cookie.getValue(), is("value")); - assertThat(cookie.getComment(), nullValue()); assertThat(cookie.getDomain(), nullValue()); assertThat(cookie.getMaxAge(), is(-1)); assertThat(cookie.getPath(), nullValue()); assertThat(cookie.getSecure(), is(false)); assertThat(cookie.isHttpOnly(), is(false)); - assertThat(cookie.getVersion(), is(0)); assertThat(cookie.getAttributes().size(), is(0)); } @@ -60,22 +57,6 @@ public void testBadCookie(String name) { assertThrows(IllegalArgumentException.class, () -> new Cookie(name, "value")); } - @SuppressWarnings("removal") - @Test - public void testComment() { - Cookie cookie = new Cookie("name", "value"); - cookie.setComment("comment"); - assertThat(cookie.getComment(), nullValue()); - assertThat(cookie.getAttributes().size(), is(0)); - cookie.setAttribute("COMMENT", "Comment!"); - assertThat(cookie.getComment(), nullValue()); - assertThat(cookie.getAttributes().keySet(), contains("COMMENT")); - assertThat(cookie.getAttributes().values(), contains("Comment!")); - cookie.setAttribute("COMMENT", null); - assertThat(cookie.getComment(), nullValue()); - assertThat(cookie.getAttributes().size(), is(0)); - } - @Test public void testDomain() { Cookie cookie = new Cookie("name", "value"); @@ -160,19 +141,6 @@ public void testValue() { assertThat(cookie.getValue(), nullValue()); } - @SuppressWarnings("removal") - @Test - public void testVersion() { - Cookie cookie = new Cookie("name", "value"); - assertThat(cookie.getVersion(), is(0)); - cookie.setVersion(1); - assertThat(cookie.getVersion(), is(0)); - assertThat(cookie.getAttributes().size(), is(0)); - cookie.setVersion(Integer.MAX_VALUE); - assertThat(cookie.getVersion(), is(0)); - assertThat(cookie.getAttributes().size(), is(0)); - } - @Test public void testHttpOnly() { Cookie cookie = new Cookie("name", "value"); diff --git a/api/src/test/java/ee/jakarta/servlet/http/HttpServletTest.java b/api/src/test/java/ee/jakarta/servlet/http/HttpServletTest.java index 2657d917a..f71562891 100644 --- a/api/src/test/java/ee/jakarta/servlet/http/HttpServletTest.java +++ b/api/src/test/java/ee/jakarta/servlet/http/HttpServletTest.java @@ -17,9 +17,7 @@ package ee.jakarta.servlet.http; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; import static org.junit.jupiter.api.Assertions.assertNotNull; import ee.jakarta.servlet.MockServletConfig; @@ -32,8 +30,6 @@ import java.io.IOException; import java.util.Collections; import java.util.Enumeration; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -45,59 +41,6 @@ public interface Handler { void handle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException; } - @ParameterizedTest - @MethodSource("headTest") - public void testLegacyHead(String test, Handler doGet, boolean expectedFlushed, long expectedContentLength) - throws ServletException, IOException { - HttpServlet servlet = new HttpServlet() { - private static final long serialVersionUID = 20214996986006168L; - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - doGet.handle(request, response); - } - }; - - MockServletConfig servletConfig = new MockServletConfig(); - servletConfig.setInitParameter("jakarta.servlet.http.legacyDoHead", "true"); - servlet.init(servletConfig); - - MockHttpServletRequest request = new MockHttpServletRequest(servletConfig.getServletContext()) { - @Override - public String getMethod() { - return "HEAD"; - } - }; - - AtomicBoolean committed = new AtomicBoolean(); - AtomicLong contentLength = new AtomicLong(-1); - MockHttpServletResponse response = new MockHttpServletResponse() { - @Override - public void flushBuffer() throws IOException { - committed.set(true); - } - - @Override - public boolean isCommitted() { - return committed.get(); - } - - @Override - public void setContentLengthLong(long len) { - contentLength.set(len); - } - }; - - servlet.service(request, response); - MockServletOutputStream out = response.getMockServletOutputStream(); - String actual = out == null ? null : out.takeOutputAsString(); - - // Check if the output should have already been flushed - assertThat(test, committed.get(), is(expectedFlushed)); - assertThat(test, contentLength.get(), is(expectedContentLength)); - assertThat(test, actual, anyOf(is(""), nullValue())); - } - @ParameterizedTest @MethodSource("traceHeadersTest") public void testTraceHeaders(String testHeader, Handler doTrace) @@ -152,97 +95,6 @@ private static Stream traceHeadersTest() { })); } - private static Stream headTest() { - return Stream.of( - Arguments.of("Nothing output", - (Handler) (request, response) -> { - }, false, 0), - - Arguments.of("Output smaller than buffer", - (Handler) (request, response) -> { - response.setBufferSize(2048); - response.getOutputStream().print("Hello World"); - }, false, 11), - - Arguments.of("Write smaller than buffer", - (Handler) (request, response) -> { - response.setBufferSize(2048); - response.getWriter().print("Hello World"); - }, false, 11), - - Arguments.of("Output bigger than buffer", - (Handler) (request, response) -> { - response.setBufferSize(5); - response.getOutputStream().print("Hello World"); - }, - false, // this is a known deficiency: a GET would commit the response - 11 // this is a known deficiency: a GET would not know the content-length - ), - - Arguments.of("Write bigger than buffer", - (Handler) (request, response) -> { - response.setBufferSize(5); - response.getWriter().print("Hello World"); - }, - false, // this is a known deficiency: a GET would commit the response - 11 // this is a known deficiency: a GET would not know the content-length - ), - - Arguments.of("Outputs with Content-Length smaller than buffer", - (Handler) (request, response) -> { - response.setBufferSize(1024); - response.setContentLength(11); - response.getOutputStream().print("Hello World"); - }, - false, // this is a known deficiency: a GET would commit the response - 11), - - Arguments.of("Write with Content-Length smaller than buffer", - (Handler) (request, response) -> { - response.setBufferSize(1024); - response.setContentLength(11); - response.getWriter().print("Hello World"); - }, - false, // this is a known deficiency: a GET would commit the response - 11), - - Arguments.of("Output with resetBuffer", - (Handler) (request, response) -> { - response.setBufferSize(2048); - response.getOutputStream().print("THIS IS WRONG"); - response.resetBuffer(); - response.getOutputStream().print("Hello World"); - }, false, 11), - - Arguments.of("Write with resetBuffer", - (Handler) (request, response) -> { - response.setBufferSize(2048); - response.getWriter().print("THIS IS WRONG"); - response.resetBuffer(); - response.getWriter().print("Hello World"); - }, - false, - 11), - - Arguments.of("Output with reset", - (Handler) (request, response) -> { - response.setBufferSize(2048); - response.getWriter().print("THIS IS WRONG"); - response.reset(); - response.getOutputStream().print("Hello World"); - }, false, 11), - - Arguments.of("Write with reset", - (Handler) (request, response) -> { - response.setBufferSize(2048); - response.getOutputStream().print("THIS IS WRONG"); - response.reset(); - response.getWriter().print("Hello World"); - }, false, 11) - - ); - } - @Test public void testContainerHead() throws ServletException, IOException { diff --git a/tck/tck-runtime/src/main/java/servlet/tck/api/jakarta_servlet_http/cookie/TestServlet.java b/tck/tck-runtime/src/main/java/servlet/tck/api/jakarta_servlet_http/cookie/TestServlet.java index bf30f00ab..ee51ba005 100644 --- a/tck/tck-runtime/src/main/java/servlet/tck/api/jakarta_servlet_http/cookie/TestServlet.java +++ b/tck/tck-runtime/src/main/java/servlet/tck/api/jakarta_servlet_http/cookie/TestServlet.java @@ -156,49 +156,6 @@ public void constructorIllegalArgumentExceptionTest( } } - @Deprecated - public void getCommentTest(@SuppressWarnings("unused") HttpServletRequest request, - HttpServletResponse response) throws IOException { - - PrintWriter pw = response.getWriter(); - boolean passed = false; - Cookie testCookie = new Cookie("name1", "value1"); - - // set and get - testCookie.setComment("This is a comment"); - String result = testCookie.getComment(); - - response.addCookie(testCookie); - if (result == null) { - passed = true; - } else { - passed = false; - pw.println("getComment() returned an incorrect result"); - pw.println("Expected null value"); - pw.println("Actual = |" + result + "| "); - } - ServletTestUtil.printResult(pw, passed); - } - - @Deprecated - public void getCommentNullTest(@SuppressWarnings("unused") HttpServletRequest request, - HttpServletResponse response) throws IOException { - - PrintWriter pw = response.getWriter(); - boolean passed = false; - Cookie testCookie = new Cookie("name1", "value1"); - String result = testCookie.getComment(); - - if (result != null) { - passed = false; - pw.println("getComment() returned a non-null result"); - pw.println("Actual = |" + result + "|"); - } else { - passed = true; - } - ServletTestUtil.printResult(pw, passed); - } - public void getDomainTest(@SuppressWarnings("unused") HttpServletRequest request, HttpServletResponse response) throws IOException { @@ -377,30 +334,6 @@ private void doGetValueTest(HttpServletRequest request, ServletTestUtil.printResult(pw, passed); } - @Deprecated - public void getVersionTest(@SuppressWarnings("unused") HttpServletRequest request, - HttpServletResponse response) throws IOException { - - // Version should be hard-coded to zero - PrintWriter pw = response.getWriter(); - boolean passed = false; - Cookie testCookie = new Cookie("name1", "value1"); - - int expectedResult = 0; - int result = testCookie.getVersion(); - - response.addCookie(testCookie); - if (result != expectedResult) { - passed = false; - pw.println("getVersion() returned an incorrect result"); - pw.println("Expected = " + expectedResult + " "); - pw.println("Actual = |" + result + "| "); - } else { - passed = true; - } - ServletTestUtil.printResult(pw, passed); - } - public void setDomainTest(@SuppressWarnings("unused") HttpServletRequest request, HttpServletResponse response) throws IOException { @@ -600,57 +533,6 @@ public void setValueTest(@SuppressWarnings("unused") HttpServletRequest request, ServletTestUtil.printResult(pw, passed); } - @Deprecated - public void setVersionVer0Test(@SuppressWarnings("unused") HttpServletRequest request, - HttpServletResponse response) throws IOException { - - // Expected to be hard-coded to zero - PrintWriter pw = response.getWriter(); - boolean passed = false; - Cookie testCookie = new Cookie("name1", "value1"); - int expectedResult = 0; - testCookie.setVersion(expectedResult); - - int result = testCookie.getVersion(); - - response.addCookie(testCookie); - if (result != expectedResult) { - passed = false; - pw.println("setVersion(" + expectedResult - + ") did not set the version properly"); - pw.println("Expected = " + expectedResult + " "); - pw.println("Actual = |" + result + "| "); - } else { - passed = true; - } - ServletTestUtil.printResult(pw, passed); - } - - @Deprecated - public void setVersionVer1Test(@SuppressWarnings("unused") HttpServletRequest request, - HttpServletResponse response) throws IOException { - - PrintWriter pw = response.getWriter(); - boolean passed = false; - Cookie testCookie = new Cookie("name1", "value1"); - int expectedResult = 0; - testCookie.setVersion(1); - - int result = testCookie.getVersion(); - - response.addCookie(testCookie); - if (result != expectedResult) { - passed = false; - pw.println("setVersion(" + expectedResult - + ") did not set the version properly"); - pw.println("Expected = " + expectedResult + " "); - pw.println("Actual = |" + result + "| "); - } else { - passed = true; - } - ServletTestUtil.printResult(pw, passed); - } - public void setAttributeTest(@SuppressWarnings("unused") HttpServletRequest request, HttpServletResponse response) throws IOException { diff --git a/tck/tck-runtime/src/main/java/servlet/tck/api/jakarta_servlet_http/sessioncookieconfig/TestServlet.java b/tck/tck-runtime/src/main/java/servlet/tck/api/jakarta_servlet_http/sessioncookieconfig/TestServlet.java index 7cbafd69e..f99fb1033 100644 --- a/tck/tck-runtime/src/main/java/servlet/tck/api/jakarta_servlet_http/sessioncookieconfig/TestServlet.java +++ b/tck/tck-runtime/src/main/java/servlet/tck/api/jakarta_servlet_http/sessioncookieconfig/TestServlet.java @@ -64,26 +64,6 @@ public void setNameTest(HttpServletRequest request, } } - public void setCommentTest(HttpServletRequest request, - HttpServletResponse response) throws IOException { - String comment = "WHO_SHOULD_NOT_BE_NAMED_HERE"; - boolean pass = true; - PrintWriter pw = response.getWriter(); - HttpSession session = request.getSession(); - - try { - pw.println("calling method setComment"); - getServletContext().getSessionCookieConfig().setComment(comment); - pass = false; - pw.println("Expected IllegalStateException not thrown"); - } catch (IllegalStateException ex) { - pw.println("Expected IllegalStateException thrown"); - } finally { - session.invalidate(); - ServletTestUtil.printResult(pw, pass); - } - } - public void setPathTest(HttpServletRequest request, HttpServletResponse response) throws IOException { String path = "WHO_SHOULD_NOT_BE_NAMED_HERE";