When the RestApi has ResponseEntity<void> of spring has return value it returns ClientProtocolException
12,214
Try as below
@RequestMapping(method = RequestMethod.DELETE)
public ResponseEntity<Void> methodName() {
// your business logic
return ResponseEntity.noContent().build();
}
Related videos on Youtube
Author by
Sunil VP
Updated on June 04, 2022Comments
-
Sunil VP almost 2 years
I have a RestApi exposed which on case returns status ok back to client. The method signature of the method is
ResponseEntity<void> methodName(){}
. This method is a deleteApi.In the return
responseEntity
is created with justStatus OK
and no body or any other header details are appended.Seen in the logs that I get
ClientProtocolException
when the call is made , saw that when the same is executed through the REST client (postman) received correctStatus OK
message in the response.What are the reasons when the
ClientProtocolException
is raised?If the return type is
ResponeEntity<Void>
is it mandatory to send body with it ?How do i avoid getting the above exception?
Code:
@RequestMapping(method = RequestMethod.DELETE) public ResponseEntity<Void> methodName() { // your business logic return new ResponseEntity<Void>(HttpStatus.OK); }