I have a web application with 10 controllers. Each controller represents an endpoint. Each controller has various API operations. I have used basic authentication for the API methods. I have used @RequestHeader in these methods to get the header and resolver username from it. I was wondering if I can get the header in the class level and provide header to all the methods in a Controller class.
I have tried to use the @RequestHeader in class level as instance variable but it does not resolve.
@RestController
@RequestMapping("client")
@Api(value="client")
@Validated
public class ClientRestController {
@GetMapping
@ApiOperation(value = "Client Search", authorizations = {@Authorization (value="basicAuth")})
public ResponseEntity<ClientSearchResponse> getClients(
@RequestHeader HttpHeaders httpHeaders,
//code to use httpHeaders
}
}
I want to able to share the httpHeaders on the controller level and use it to in all the methods in the class because I only need the username from it.