1

I try to enable directory browsing in via a rest service. Its defined like this:

@RequestMapping(path="ls/{path:.+}", method = RequestMethod.GET)
public List<String> getDirectoryListing(@PathVariable("path") String path) throws IOException {
  // ...
}

However, the PathVariable {path:.+} introduces problems, if i use a directory-like definition. For example,

$ curl http://localhost:8080/fileRepo/ls/dir/subdir
                                         \___ ___/
                                             V 
                                          {path:.+} 

will result in

{
 "timestamp":1485690489272,
 "status":404,"error":"Not Found",
 "message":"No message available",
 "path":"/dataset/ls/processed/dir1/subdir"
 }

and have the debug messages on the console

s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /files/ls/dir1/subdir
s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/files/ls/dir1/subdir]
o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/files/ls/dir1/subdir] are [/**]
o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/files/ls/dir1/subdir] are {}

So. how to tell the RequestMappingHandlerMapping that ls/{path:.+} should all resolve to getDirectoryListing?

helt
  • 4,925
  • 3
  • 35
  • 54

1 Answers1

-1

if you are sending dir/subdir in your path variable you need to escape the "/" character in your path variable. You need to encode the path variable part of your url and decode the same at the request handler level.

shubham
  • 472
  • 3
  • 9
  • nope, its not a encoding issue. url decoding is done by transparently by spring, apparently before the url is resolved in search for a request mapping – helt Feb 02 '17 at 17:05