@RequestHeader in spring not accepting fake headers

Viewed 186

I am using

@RequestHeader(value = "channel") String channel

in Spring application controller to get headers and it works fine for normal headers, however, in some cases, I need to trap a request using filter and use HttpServletRequestWrapper to add some extra headers. The new headers added by overriding getHeader method are not being accepted by @RequestHeader annotation and throws error. However, if I manually get headers using

HttpServletRequest.getHeader("channel")

the new headers work fine. Is there any bug in @RequestHeader implementation? If so, is there any work-around so that I wouldn't have to change the same thing in 50+ APIs.

1 Answers

When resolving @RequestHeader, Spring is using getHeaders(), not getHeader(). You need to override this one.

Related