meirrav
meirrav

Reputation: 771

Is it possible to check values of headers using @RequestMapping

I would like to validate that the request received has some headers and that these headers follow some condition. I saw that I can use @requestmapping to check that all the headers are present like so:

@RequestMapping(method  = RequestMethod.POST,
            headers = {"PHS-DP-Created-Date","PHS-DP-Modified-Date","PHS-DP-Accessed-Date","PHS-DP-Revision"},
            value   = {"/{accountID}/{containerID}/{objectID:.+}"})

But I can't find a way to check there values against some condition (for example value > 0)

Is it at all possible using annotations?

Upvotes: 0

Views: 1358

Answers (1)

Maciej Walkowiak
Maciej Walkowiak

Reputation: 12932

You can check only if particular header exist and if it's equal/not equal to a value. For example:

@RequestMapping(value = "/hello", headers = "my-header=my-value", method = RequestMethod.POST)
...
@RequestMapping(value = "/hello", headers = "my-header!=my-value", method = RequestMethod.POST)

You can't unfortunately check any additional conditions. To find out more about the details look at HeadersRequestCondition class.

The only option you have is to create custom RequestMappingHandlerMapping and change behavior how request is mapped to methods.

Upvotes: 2

Related Questions