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.
target.path(filePath).reqest()
. And whyMediaType.APPLICATION_JSON
? Doesn't make much sense for the request resource. – Paul SamsothaMediaType.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