I'm reading a ResponseEntity from a webService using the Java (Spring 2.0) code below:
public ResponseEntity<?> getTemplate() {
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<?> myResponse= restTemplate.postForEntity(
myUrl,
myRequestObj,
MyResponseObj.class);
return myResponse;
}
However, if the myUrl webservice returns HttpStatus.BAD_REQUEST (400) , this is not assigned to myResponse and an error is thrown, so there is no ResponseBody and I need to wrap the request in a try catch block. Is this correct or is there a way round this? Also, does this mean that the myUrl webservice should never intentionally (programatically) set the HttpStatus of myResponseObj to HttpStatus.BAD_REQUEST? So,even if myRequestObj contains bad data the myUrl webService should still set the response status to something in the 200's ie HttpStatus.NO_CONTENT. Any comments welcome on how to do this correctly.