title: Java-Jersey based RESTful webservice : What is the best way to handle path param for a file entity
body: <p>I am writing a Java based REST web service using jersey. The entity for which I am writing the web service is a media file. A client requesting for a media file need to send the path and filename as the path param. The media path allowed can be up to a depth of five directories. Now the challenge is to write a single method to handle all the path depth possibilities. Using the path param is the only allowed choice in terms of the business scenario. Here is the method contract, which handles a media file request:</p>
  
  <pre><code>public Response getMediaFile(@PathParam("path") String path,
                          @PathParam("filename") String filename);
  </code></pre>
  
  <p>Problem with this method is that, if the request is like /media/filedir1/filedir2/filename then filename will not be fetch properly. </p>
  
  <p>The solution I have implemented is that, I have overloaded this method to handle all the directories depth but I am not really convinced that this is the best solution:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>And so on.</p>