Created
June 18, 2020 17:03
-
-
Save iamvickyav/497c33d0dd64cf57e00ac313a39537a3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @GetMapping(value = "/mockService/{serviceName}") | |
| ResponseEntity fetchMockValue(@PathVariable("serviceName") String serviceName) throws IOException { | |
| LOGGER.info("fetchMockValue called for serviceName={}", serviceName); | |
| ResponseEntity responseEntity; | |
| File mockServiceJsonFile = getFile(serviceName); | |
| if(mockServiceJsonFile.exists()) { | |
| String timeoutValue = environment.getProperty(serviceName + ".delay"); | |
| String ttValue = (timeoutValue != null) ? timeoutValue : System.getenv(serviceName + ".delay"); | |
| if(ttValue != null) { | |
| long timeout = Long.parseLong(ttValue); | |
| try { | |
| Thread.sleep(timeout); | |
| } catch (InterruptedException e) { | |
| LOGGER.error("Mock Data Sleep Interrupted"); | |
| } | |
| } | |
| LOGGER.info("Mock Data Exist for serviceName={}", serviceName); | |
| JsonNode jsonNode = objectMapper.readValue(mockServiceJsonFile, JsonNode.class); | |
| responseEntity = new ResponseEntity(jsonNode, HttpStatus.OK); | |
| } | |
| else { | |
| LOGGER.info("Mock Data not available for serviceName={}", serviceName); | |
| Map responseMap = new HashMap(); | |
| responseMap.put(MESSAGE, "Mock data not available for " + serviceName); | |
| responseEntity = new ResponseEntity(responseMap, HttpStatus.NOT_FOUND); | |
| } | |
| return responseEntity; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment