jerryshao commented on code in PR #10840: URL: https://github.com/apache/gravitino/pull/10840#discussion_r3122647524
########## server/src/main/java/org/apache/gravitino/server/web/HealthAliasServlet.java: ########## @@ -0,0 +1,56 @@ +/* + * 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.gravitino.server.web; + +import java.io.IOException; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Serves root-level health check paths ({@code /health}, {@code /health.html}) by forwarding to the + * canonical {@code /api/health} endpoint. + * + * <p>These aliases exist for compatibility with enterprise global traffic managers that require + * probes at well-known root paths. The canonical implementation remains at {@code /api/health}; + * these servlets are a thin compatibility layer. + */ +public class HealthAliasServlet extends HttpServlet { + + private static final String CANONICAL_HEALTH_PATH = "/api/health"; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + RequestDispatcher dispatcher = req.getRequestDispatcher(CANONICAL_HEALTH_PATH); + if (dispatcher == null) { + resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "health dispatcher unavailable"); + return; + } + dispatcher.forward(req, resp); + } + + @Override + protected void doHead(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doGet(req, resp); + } Review Comment: Fixed. Removed the `doHead` override entirely. `HttpServlet.doHead()` calls `doGet()` internally with a body-suppressing response wrapper, which is the correct behaviour here. ########## server/src/main/java/org/apache/gravitino/server/web/HealthAliasServlet.java: ########## @@ -0,0 +1,56 @@ +/* + * 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.gravitino.server.web; + +import java.io.IOException; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Serves root-level health check paths ({@code /health}, {@code /health.html}) by forwarding to the + * canonical {@code /api/health} endpoint. + * + * <p>These aliases exist for compatibility with enterprise global traffic managers that require + * probes at well-known root paths. The canonical implementation remains at {@code /api/health}; + * these servlets are a thin compatibility layer. + */ +public class HealthAliasServlet extends HttpServlet { + + private static final String CANONICAL_HEALTH_PATH = "/api/health"; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + RequestDispatcher dispatcher = req.getRequestDispatcher(CANONICAL_HEALTH_PATH); + if (dispatcher == null) { + resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "health dispatcher unavailable"); + return; + } + dispatcher.forward(req, resp); + } Review Comment: Fixed. Added `TestHealthAliasServlet` covering two cases: (1) forward success — verifies `RequestDispatcher.forward()` is called with the correct request/response; (2) null dispatcher — verifies `SC_SERVICE_UNAVAILABLE` is returned when `getRequestDispatcher` returns null. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
