Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When the RestApi has ResponseEntity<void> of spring has return value it returns ClientProtocolException

Tags:

java

rest

spring

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);
}
like image 266
Sunil VP Avatar asked Dec 11 '22 15:12

Sunil VP


1 Answers

Try as below

@RequestMapping(method = RequestMethod.DELETE)
public ResponseEntity<Void> methodName() { 
    // your business logic 
    return ResponseEntity.noContent().build();
}
like image 148
Sanal Nair Avatar answered Dec 13 '22 06:12

Sanal Nair