Class Name: org.test.ClassName
Method Name: method1
Actual Return Type: ResponseEntity<Task>
Expected response: Task ie. {“id”: “test”}
- My requirement is to intercept the response and modify its response to the expected response given above. I tried to modify the return object in the return statement, but byteman is throwing an error that return type cannot be changed. How to achieve this? Tried below, but didnt work
RULE a
CLASS org.test.ClassName
METHOD method1
AT EXIT
IF true
DO
return new Task();
ENDRULE
- Other requirement is to change the actual return type’s property itself ie. Response of the method is ResponseEntity<>(new Task, HttpStatus.OK), i want to change the return property to ResponseEntity<>(new Task, HttpStatus.FORBIDDEN). How to achieve this? Tried below, but didnt work
RULE a
CLASS com.vmware.mangle.services.controller.TestController
METHOD getUser
AT EXIT
IF TRUE
DO
ResponseEntity<Resource<User>> responseEntity = $!;
HttpStatus httpStatus = responseEntity.getStatusCode();
if (httpStatus == HttpStatus.OK) {
ResponseEntity<Resource<User>> newResponseEntity =
new ResponseEntity<>(responseEntity.getBody(), HttpStatus.BAD_REQUEST);
$! = newResponseEntity;
}
ENDRULE
New contributor
Prathiba Mannan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.