Skip to content

Commit

Permalink
Add logging, /status and more configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ndwinton committed Feb 22, 2023
1 parent 0b4f853 commit 6a32007
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ jobs:
run: |
# GITHUB_ENV file is sourced by subsequent steps
echo "VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
# ENV is 'beta' if it's a pre-release or contains 'beta' in name
if [[ "${{ github.event.release.prerelease }}" == "true" || "${{ github.event.release.tag_name }}" =~ .*beta.* ]]
then
echo "ENV=beta" >> $GITHUB_ENV
else
echo "ENV=prod" >> $GITHUB_ENV
fi
- name: Install JDK
uses: actions/setup-java@v3
with:
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ Boot, so start-up times are very small.

It provides the following endpoints:

* `/` - just responds with `OK`
* `/hello` - responds with a canned greeting message, which
can be over-ridden using the `GREETING_MESSAGE` environment
variable.
* `/env` - responds with a JSON map of current environment variable settings
* `/` - just responds with `OK`, but can be over-ridden using
the `OK_MESSAGE` environment variable.
* `/echo` - a GET to this with a query-parameter of `message`
echoes back the supplied message
* `/echo` - a POST to this echoes back the body contents
* `/actuator` - exposes the full range of actuator endpoints
* `/env` - responds with a JSON map of current environment variable settings
* `/hello` - responds with a canned greeting message, which
can be over-ridden using the `HELLO_MESSAGE` environment
variable.
* `/status/<CODE>` - response with a status of the given code
value, and matching message.

The liveness and readiness endpoints are also exposed on
`/livez` and `/readyz`, respectively.
In addition:

* `/actuator` - exposes the full range of actuator endpoints
* Liveness and readiness endpoints are also exposed on `/livez`
and `/readyz`, respectively.
24 changes: 21 additions & 3 deletions src/main/java/com/vmware/tanzu/simplewebapp/SimpleController.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,53 @@
package com.vmware.tanzu.simplewebapp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SimpleController {

Logger logger = LoggerFactory.getLogger(SimpleController.class);

@GetMapping("/")
public String ok() {
return "OK";
public String ok(@Value("${ok.message:OK}") String message) {
logger.info("Requested / requested");
return message;
}

@GetMapping("/hello")
public String hello(@Value("${greeting.message:Hello from the Simple Web App!}") String message) {
public String hello(@Value("${hello.message:Hello from the Simple Web App!}") String message) {
logger.info("Requested /hello");
return message;
}

@GetMapping("/env")
public Map<String,String> env() {
logger.info("Requested /env");
return System.getenv();
}

@GetMapping("/echo")
public String echoParam(@RequestParam String message) {
logger.info("Requested /echo via GET");
return message;
}

@PostMapping("/echo")
public String echoBody(@RequestBody String body) {
logger.info("Requested /echo via POST");
return body;
}

@GetMapping("/status/{code}")
public ResponseEntity<String> status(@PathVariable Integer code) {
logger.info("Requested /status/" + code);
return new ResponseEntity<>(HttpStatus.valueOf(code).getReasonPhrase(), HttpStatusCode.valueOf(code));
}
}

0 comments on commit 6a32007

Please sign in to comment.