In our web application we have a lot of REST services. Suddenly it found out that we need to modify one object inside of each request before we go on.
So let's say we have n
different controllers with REST services. In each controller, before we call the service from next layer, we need to modify an object inside the request.
The question is how to achieve this without providing hundreds of changes inside the controllers... Is there any simple way to do this?
UPDATE:
@RestController
public class OrderController {
@Autowired
private OrderService orderService;
@RequestMapping(path = "/order", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public OrderResponse getOrderData(@RequestHeader HttpHeaders httpHeaders,
@RequestBody OrderDataRequest orderDataRequest) {
// Use here interceptor to modify the object Details
// (inside OrderDataRequest) before below call:
OrderResponse resp = orderService.getOrderData(orderDataRequest);
return resp;
}
@RequestMapping(path = "/cancel/{orderId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public boolean cancelOrder(@RequestHeader HttpHeaders httpHeaders,
@RequestBody Details details, @PathVariable Integer orderId) {
// Use here interceptor to modify object Details before below call:
return orderService.cancelOrder(details, orderId);
}
}
In each controller I need to modift the object Details, which as you can see could be inside another object like in the first example or exist alone like in the second option.