简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM