user3423568
user3423568

Reputation: 811

PathParam in RESTFul ws

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

Upvotes: 0

Views: 844

Answers (1)

lefloh
lefloh

Reputation: 10961

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.

Upvotes: 0

Related Questions