I have a springboot api. Call to one of the endpoint from swagger throws 500 error but nothing is getting logged. When I tried debugging, I can see that the responseEntity is populated just before returning from the controller. Hence I feel the code worked fine. Even then I see 500 in swagger. Lack of logs is making is difficult to debug. Did anyone face similar issue? How did you resolve it?
endpoint looks like this: I have added the log statements for reference
@RequestMapping(value = "/details/id/{id}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
public @ResponseBody
ResponseEntity<Details> getDetailsById(@PathVariable(name="id") @ApiParam(value ="id", example = "1234", required = true) String id) {
inputValidation.validateInputAndThrowErrorIfNecessary(id);
if(isBlank(id)) throw new IllegalArgumentException();
Details details = detailsService.getDetailsById(id);
if(details == null){
logger.debug("Not found response..................");
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
logger.debug("Just before posting the response for : {}", id);
ResponseEntity<Details> responseEntity = new ResponseEntity<>(details, HttpStatus.OK);
logger.debug("JSON--->\n"+responseEntity.toString()); // i see <200 OK OK,class Details { blah blah } at this point in logs
return responseEntity;
}
When I run the curl, response is as below :
curl -v GET "http://host:port/api/details/id/111" -H "accept: application/json;charset=UTF-8"
* Rebuilt URL to: GET/
* Could not resolve host: GET
* Closing connection 0
curl: (6) Could not resolve host: GET
* Trying host...
* TCP_NODELAY set
* Connected to host (host) port port (#1)
> GET /api/details/id/111 HTTP/1.1
> Host: host:port
> User-Agent: curl/7.55.1
> accept: application/json;charset=UTF-8
>
< HTTP/1.1 500
< Content-Type: text/html;charset=utf-8
< Content-Language: en
< Content-Length: 455
< Date: Wed, 27 May 2020 00:49:11 GMT
< Connection: close
<
<!doctype html><html lang="en"><head><title>HTTP Status 500 ÔÇô Internal Server Error</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 ÔÇô Internal Server Error</h1></body></html>* Closing connection 1
curl -v http://localhost:8080/foo
– AdlaiResponseEntity<Details>
and the return type ofresponseEntity
isResponseEntity<FullDetails>
, however I would have thought that would fail compilation if that's an issue. Clearly there's something weird going on, I would have thought there would be logging from Spring Boot with an exception, however if there isn't you can use something like this to force logging: #33745375 – Adlai