RequestMapping with slashes and dot
The most dynamic approach would be to use MatrixVariable
to manage the list of addresses but it is not applicable in your context since the paths cannot be modified as far as I understand from your question.
The best thing you can do to manage your dynamic path is to proceed in two steps:
- Set a
RequestMapping
that extracts all the data except the addresses - Extract the addresses manually in the method
So for the first step you will have something like that:
@RequestMapping(value="/service/{country}/{city}/**/{file}.atom")
public String service(@PathVariable String country,
@PathVariable String city, @PathVariable String file,
HttpServletRequest request, Model model) {
This mapping matchs with all the required paths and allows to extract the country, the city and the file name.
In the second step we will use what has been extracted to get the addresses by doing something like this:
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
path = path.substring(String.format("/service/%s/%s/", country, city).length(),
path.length() - String.format("%s.atom", file).length());
String[] addrs = path.split("/");
- First we extract from the request the full path
- Then we remove what we have already extracted which are here the beginning and the end of the path
- Then finally we use
String.split
to extract all the addresses
At this level you have everything you need.