1

I am trying to expose a custom endpoint which internally calls spring actuator. but i am getting Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out.

    @GetMapping(value = "/${spring.application.name}/actuator/health")
    public ResponseEntity<Object> createUser() {
        ResponseEntity<Map> entity = this.restTemplate.getForEntity("http://localhost:" + this.port
                + "/actuator/health", Map.class);

        return new ResponseEntity<>(entity, HttpStatus.OK);
    }


Is there any way to make it work.

VIJ
  • 1,516
  • 1
  • 18
  • 34
  • 1
    Are you able to call the actuator endpoint from postman? If yes the endpoint is working and I cannot see why you wouldn't be able to call it from within your app. Check the url/port you are calling. Anyway if you need to access health information you can reach to them without calling the endpoint, you can inject HealthEndpoint (https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/actuate/health/HealthEndpoint.html) and access them. – burm87 Jan 28 '21 at 10:18
  • Yes, i am able to call it from postman. – VIJ Jan 28 '21 at 10:28
  • If you don't provide more information it won't be easy to help you. – burm87 Jan 28 '21 at 10:29
  • Yes, i am able to call actuator endpoint from postman. Inspite of that i am not able to call it from controller. url and port is all fine. I get Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out – VIJ Jan 28 '21 at 10:43
  • Actuator port may be different from application port. Where are you getting the port from? – Abhijit Sarkar Jan 28 '21 at 11:01
  • Port is same i am getting from application.properties – VIJ Jan 28 '21 at 11:05

1 Answers1

1

There’s no need to create your own endpoint, just set management.endpoints.web.base-path=${spring.application.name} in application.properties. See https://docs.spring.io/spring-boot/docs/2.1.13.RELEASE/reference/html/production-ready-monitoring.html.

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219