I want to read a property from application.properties and set as default value to @RequestHeader to an API endpoint. My properties look like
item.includePrice.value=Y
ItemController.java
@PostMapping("/item")
public String postBody(@RequestHeader String includePrice, @RequestBody SomeRequest someRequest) {
if(includePrice != null)
return "You searched for " + someRequest.getItemName;
}
I have referred below questions and tried two approaches.
First approach is, tried using a custom interceptor. But, in order to set the default value for includePrice after reading the property from application.properties under the preHandle method, I do not see addHeader method for HttpServletRequest.
Application Properties value in Spring boot interceptor
Second approach is used below resources and implemented a MutableHttpServletRequest that extends HttpServletRequestWrapper and added the header.
Adding an HTTP Header to the request in a servlet filter
How to add HttpServletRequest headers in HandlerInterceptorAdapter?
Expectation: Regardless the API request sends the includePrice header value or not, at all times, the property should be read from the application.properties and set the default value to my HttpServletRequest.