0

I have below client code:

String filePath = "/testzip/123/TEST-test.zip";
target = mainTarget.path("file").path("{filePath}");
Invocation.Builder invocationBuilder =  target
                .resolveTemplate("filePath", filePath)
                .request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_OCTET_STREAM);

Response response = invocationBuilder.get();

Below is my server code:

@GET
@Path("{filePath}")
@Produces({MediaType.APPLICATION_OCTET_STREAM})
public Response get(@PathParam("filePath") String filePath) {
    File file = new File(filePath);
    return Response.status(Response.Status.OK).entity(file).build();
}

This client is throwing Bad Request exception while I send below filePath:

String filePath = "/testzip/123/TEST-test.zip";

But it is working fine when I send below filePath (simple string):

String filePath = "testzip";

I am not able to figure it out why it is not working when forward slash(/) is present in path parameters.

Nitesh Virani
  • 1,688
  • 4
  • 25
  • 41
  • Try and just do `target.path(filePath).reqest()`. And why `MediaType.APPLICATION_JSON`? Doesn't make much sense for the request resource. – Paul Samsotha Oct 04 '15 at 06:50
  • @peeskillet I have removed `MediaType.APPLICATION_JSON` as it does not make sense. `target.path(filePath).reqest()` did not work for me. It says "The requested resource is not available." because it takes forward slashes as some resource path and trying to find out that resource at server side – Nitesh Virani Oct 04 '15 at 06:59

1 Answers1

1

I believe you cannot have / in a @PathParam by default.

EDIT Have a look here : Tomcat, JAX-RS, Jersey, @PathParam: how to pass dots and slashes?

Community
  • 1
  • 1
Gaël J
  • 11,274
  • 4
  • 17
  • 32