HttpServletRequest variable with slash vs %2f

java, rest, spring, web-services

Solution

Typically most of the application server will not not treat `%2F` as `/` if `%2F` is found in URL. But as the specs declare `%2F` is one of the ways a path delimiter can be specified, for handling this scenario, tomcat provides system level property

For tomcat, if

org.apache.tomcat.util.buf. UDecoder.ALLOW_ENCODED_SLASH = true

then `%2F` and `%5C` will be permitted as path delimiters. Refer to the documentation. This can be set as `JAVA_OPTS` in tomcat batch files as follows

set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%   -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

This is specifically for Tomcat. I am sure there would be similar arrangement for other application servers as well.

Problem

Here is my controller: ``` @RequestMapping(method = RequestMethod.GET, value="/test/**", headers="Accept=*/*") public @ResponseBody ResponseEntity<byte[]> getRequest(HttpServletRequest request) { System.out.println((String) request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE )); } ``` Whenever I want to create `GET`request looking like this: `localhost:8080/test/some/request/given/in` My system out write in console: `some/request/given/in` As I want it to. Problem comes when I have instead of slash - `/` symbol `%2F` or `%2f`. When I have those symbols in my path request is not handled by controller at all. Is there any way to fix this?

Original source