Reputation: 435
We are facing a super strange problem: in our endpoint:
@PostMapping(value = "/send_event_to_payment_process")
@Async
public void sendEvent(@Valid @RequestBody final SendEventRequestDto dto, @RequestHeader(value = TENANT) String foo) {
the mapped @RequestHeader variable foo contains the vaue twice joined with a ',' ("test,test"). If we read the header programmatically using the request context:
public void sendEvent(@Valid @RequestBody final SendEventRequestDto dto, @Context final HttpServletRequest request) {
final String tenant = request.getHeader(TENANT);
we receive the proper value (only once: "test").
Any clues what the problem might be?!
Thank you!
Upvotes: 1
Views: 1972
Reputation: 124441
You are comparing different things.
The HttpServletRequest.getHeader
method always returns a single value, even if there are multiple values for the header. It will return the first (see the javadoc of the method).
Spring uses the HttpServletRequest::getHeaders
method to get all the values. Which retrieves all header values and, depending on the value, return the String[]
or creates a single concatenated String
.
To compare the same things you also should use the getHeaders
method and then you will have the same result. Which means your request contains 2 header values for the given header.
Upvotes: 1