From 31544bae381652155c511e81a850e94ec253102e Mon Sep 17 00:00:00 2001
From: Lars Johansson <lars.johansson@ess.eu>
Date: Thu, 24 Feb 2022 13:40:19 +0100
Subject: [PATCH] Added REST API endpoint for healthcheck

---
 .../controller/HealthcheckController.java     | 62 +++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 src/main/java/org/openepics/names/rest/controller/HealthcheckController.java

diff --git a/src/main/java/org/openepics/names/rest/controller/HealthcheckController.java b/src/main/java/org/openepics/names/rest/controller/HealthcheckController.java
new file mode 100644
index 0000000..d34ab94
--- /dev/null
+++ b/src/main/java/org/openepics/names/rest/controller/HealthcheckController.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2021 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+package org.openepics.names.rest.controller;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * This part of REST API provides healthcheck for Naming application.
+ *
+ * @author Lars Johansson
+ */
+@RestController
+@RequestMapping("/healthcheck")
+@EnableAutoConfiguration
+public class HealthcheckController {
+
+    // note
+    //     global exception handler available
+
+    /*
+       Methods
+           read      GET /healthcheck - readHealthcheck()
+     */
+
+    /**
+     * Perform healthcheck for Naming application in general and healtcheck endpoint in particular.
+     * To be used mainly for checking HTTP response code, in particular HTTP STATUS OK - 200.
+     *
+     * @return server timestamp
+     */
+    @GetMapping
+    public String readHealthcheck() {
+        // return healthcheck as server timestamp
+        //     datetime - dateStyle, timeStyle - full
+
+        return SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date());
+    }
+
+}
-- 
GitLab