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 just Status 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 correct Status 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);
}
Try as below
@RequestMapping(method = RequestMethod.DELETE)
public ResponseEntity<Void> methodName() {
// your business logic
return ResponseEntity.noContent().build();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With