-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logging, /status and more configuration
- Loading branch information
Showing
3 changed files
with
34 additions
and
18 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
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
24 changes: 21 additions & 3 deletions
24
src/main/java/com/vmware/tanzu/simplewebapp/SimpleController.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 |
---|---|---|
@@ -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)); | ||
} | ||
} |