I am writing a Java based REST web service using jersey. The object for which I am writing a web service is a media file. The client requesting the media file must send the path and file name as a path parameter. The valid data transfer path can be up to five directories deep. Now the challenge is to write one method to handle all the possibilities of the depth of the path. Using the path parameter is the only permitted choice in terms of a business scenario. The following is a contract that processes a media request:
public Response getMediaFile(@PathParam("path") String path, @PathParam("filename") String filename);
The problem with this method is that if the request is like / media / filedir 1 / filedir2 / filename, then the file name will not be selected correctly.
The solution I implemented is that I overloaded this method to handle all directory depths, but I'm not sure if this is the best solution:
public Response getMediaFile(@PathParam("path1") String path1, @PathParam("path2") String path2, @PathParam("filename") String filename); public Response getMediaFile(@PathParam("path1") String path1, @PathParam("path2") String path2, @PathParam("path3") String path3, @PathParam("filename") String filename);
And so on.
source share