0

I need to use as PathParam the path of a file, how can I do? Should I use URLEncode e URLDecode? Can someone give me an example?

The structure of my ws is:

@Path("/{filePath}")
public Response convert(@PathParam("filePath") String filePath) throws Throwable 
{ 
    ..
}

Thanks in advance

Tim
  • 41,901
  • 18
  • 127
  • 145
user3423568
  • 741
  • 1
  • 6
  • 4
  • Why would you want it to be A File's path? @Path is used to give the path of a RESTful call or inventory and it's relative to the App's path defined in the web.xml under tag – Anirudh Apr 29 '14 at 16:43
  • I need to pass the file path to the rest service. Recovered files should I do operations on it – user3423568 Apr 29 '14 at 17:31

1 Answers1

0

Use the .* regex for the pathParam. Otherwise jax-rs will only expect one segment. Then resolve the path against your base-directory.

@GET
@Path("/backup/{filePath : .*}")
public Response convert(@PathParam("filePath") String filePath) {
    java.nio.file.Path absolutePath = Paths.get("/path/to/backup", filePath);
    return Response.ok(absolutePath.toString()).build();
}

Paths.get("C:/path/to/backup", filePath) should work if you are using windows. (Untested)

Unrelated: I don’t see a reason for throwing a Throwable.

lefloh
  • 10,653
  • 3
  • 28
  • 50