Ancuta Ancuta - 1 year ago 47
Java Question

Limitation of path in Spring

I came across an interesting question while working with Spring and REST API and that problem is: Is the path limited to a certain number of characters in Spring?

The code is as follows

@RequestMapping(value = {REST_PREFIX + "/{key}"}, method = {RequestMethod.GET})
public DashboardItem getExceptionByKey(@PathVariable("key") String key, HttpServletRequest request, HttpServletResponse httpResponse_p) {"URL is {}", request.getRequestURL());"Key is {}", key);
return InspectionUtils.getExceptionByKey(key);

An example of a key is


When sending the request I made sure to encode the URL and in my program the URL I am receiving is the following


Thus I am receiving the hole key, but when it parses it, the variable key is only


I thought that it may be special characters, but it doesn't look like it. My second guess is that there is a limitation for the length of the path.

So my question to you is if there is a limitation regarding the path or is there another problem?

Thank you

rob rob
Answer Source

This is some kind of spring convention that treats everything after the last dot as a file extension and cuts it off. You could simply try adding a trailing / in your request mapping and the request. I.e. REST_PREFIX + "/{key}/"

For a more complicated but better solution if you are not the one calling your API see this question

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download