-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(language-web): add health check endpoint
- Loading branch information
Showing
4 changed files
with
46 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
subprojects/language-web/src/main/java/tools/refinery/language/web/HealthCheckServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package tools.refinery.language.web;/* | ||
* SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/> | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import jakarta.servlet.http.HttpServlet; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.Serial; | ||
|
||
public class HealthCheckServlet extends HttpServlet { | ||
@Serial | ||
private static final long serialVersionUID = 5512947261931111041L; | ||
|
||
private final transient Logger log = LoggerFactory.getLogger(getClass()); | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) { | ||
resp.setStatus(HttpServletResponse.SC_OK); | ||
resp.setContentType("application/json"); | ||
try (var writer = resp.getWriter()) { | ||
writer.println("{\"status\": \"up\"}"); | ||
writer.flush(); | ||
} catch (IOException e) { | ||
log.error("Failed to write response", e); | ||
if (!resp.isCommitted()) { | ||
resp.reset(); | ||
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters