diff --git a/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoConfiguration.java b/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoConfiguration.java new file mode 100644 index 00000000000..2dc386d48db --- /dev/null +++ b/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoConfiguration.java @@ -0,0 +1,39 @@ +/* + * Copyright 2014-2023 the original author or authors. + * + * Licensed 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 + * + * https://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 de.codecentric.boot.admin.sample.echo; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author Cosimo Damiano Prete + * @since 17/06/2026 + **/ +@Configuration(proxyBeanMethods = false) +public class EchoConfiguration { + + @Bean + public EchoRepository echoRepository() { + return new EchoRepository(); + } + + @Bean + public EchoHealthIndicator echoHealthIndicator(EchoRepository echoRepository) { + return new EchoHealthIndicator(echoRepository); + } + +} diff --git a/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoController.java b/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoController.java new file mode 100644 index 00000000000..189901cee52 --- /dev/null +++ b/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoController.java @@ -0,0 +1,64 @@ +/* + * Copyright 2014-2023 the original author or authors. + * + * Licensed 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 + * + * https://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 de.codecentric.boot.admin.sample.echo; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.util.StringUtils.hasText; + +/** + * This controller exposes REST resources under '/echo'. + * + * @author Cosimo Damiano Prete + * @since 17/06/2026 + **/ +@RestController +@RequestMapping("/echo") +public class EchoController { + + private final EchoRepository repository; + + public EchoController(EchoRepository repository) { + this.repository = repository; + } + + /** + * Allows to get the latest recorded echo value or to set a new one and return it if a + * value for {@code status} or {@code details} is provided. + *
+ * While this endpoint breaks quite some principles (SRP, invalid REST resource and so
+ * on), it has been designed in this way so that it can be called by just typing it in
+ * the browser address bar without the need of any other additional or external tools
+ * (e.g.: Postman, cURL and so on).
+ * @param status the new status to set. For example: UP, DOWN, OUT_OF_SERVICE,
+ * UNKNOWN.
+ * @param details the new details to set. For example: "Database is down", "Disk space
+ * is low" and so on.
+ * @return the latest recorded echo value or the new one if a value for {@code status}
+ * or {@code details} is provided.
+ */
+ @GetMapping(produces = APPLICATION_JSON_VALUE)
+ public EchoEntity echo(@RequestParam(required = false) String status,
+ @RequestParam(required = false) String details) {
+ return (hasText(status) || hasText(details)) ? repository.save(status, details) : repository.get();
+ }
+
+}
diff --git a/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoEntity.java b/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoEntity.java
new file mode 100644
index 00000000000..f658c2a6458
--- /dev/null
+++ b/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoEntity.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2014-2023 the original author or authors.
+ *
+ * Licensed 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
+ *
+ * https://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 de.codecentric.boot.admin.sample.echo;
+
+import org.jspecify.annotations.NonNull;
+
+/**
+ * @author Cosimo Damiano Prete
+ * @since 17/06/2026
+ **/
+public record EchoEntity(@NonNull String status, String details) {
+ public EchoEntity(@NonNull String status) {
+ this(status, null);
+ }
+
+ public EchoEntity withDetails(String details) {
+ return new EchoEntity(status, details);
+ }
+}
diff --git a/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoHealthIndicator.java b/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoHealthIndicator.java
new file mode 100644
index 00000000000..be47878651f
--- /dev/null
+++ b/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoHealthIndicator.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2014-2023 the original author or authors.
+ *
+ * Licensed 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
+ *
+ * https://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 de.codecentric.boot.admin.sample.echo;
+
+import org.jspecify.annotations.Nullable;
+import org.springframework.boot.health.contributor.Health;
+import org.springframework.boot.health.contributor.HealthIndicator;
+
+import static org.springframework.util.StringUtils.hasText;
+
+/**
+ * @author Cosimo Damiano Prete
+ * @since 17/06/2026
+ **/
+public class EchoHealthIndicator implements HealthIndicator {
+
+ private final EchoRepository repository;
+
+ public EchoHealthIndicator(EchoRepository repository) {
+ this.repository = repository;
+ }
+
+ @Override
+ public @Nullable Health health() {
+ EchoEntity entity = repository.get();
+
+ Health.Builder builder = new Health.Builder().status(entity.status());
+ if (hasText(entity.details())) {
+ builder.withDetail("details", entity.details());
+ }
+
+ return builder.build();
+ }
+
+}
diff --git a/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoRepository.java b/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoRepository.java
new file mode 100644
index 00000000000..b7c2b9fb51c
--- /dev/null
+++ b/spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/sample/echo/EchoRepository.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2014-2023 the original author or authors.
+ *
+ * Licensed 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
+ *
+ * https://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 de.codecentric.boot.admin.sample.echo;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.springframework.util.StringUtils.hasText;
+
+/**
+ * @author Cosimo Damiano Prete
+ * @since 17/06/2026
+ **/
+public class EchoRepository {
+
+ private static final EchoEntity DEFAULT = new EchoEntity("UP");
+
+ private final AtomicReference