3

Should spaces be possible in @PathParams when creating REST-Services via Jersey 1.19 in Tomcat 2.0.27?

Jersey returns 400 Bad Request whenever I try to call my REST-Service with a space in the filename path param. It does not even reach my code. If there is no space in filename, everything is working as expected. The annotations of my REST method are as follows:

@GET
@Path("/trennblatt/{objId}/{filename}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getTrennblatt(
@PathParam("objId") final long objId,
@PathParam("filename") final String filename,
@Context final HttpServletResponse response)

Tomcat's access log, the encoding seems fine:

[18/Apr/2016:11:09:17 +0200] "GET /.../trennblatt/228342/01%20Aktendecke.pdf HTTP/1.1" 400 1004
[18/Apr/2016:11:09:29 +0200] "GET /.../trennblatt/228342/inspectionsheet.html HTTP/1.1" 200 44870
[18/Apr/2016:11:13:29 +0200] "GET /.../trennblatt/228342/inspectionsheet.html/ HTTP/1.1" 200 44870
[18/Apr/2016:11:13:33 +0200] "GET /.../trennblatt/228342/01%20Aktendecke.pdf/ HTTP/1.1" 400 1004

As the access log shows, I even tried appending another / to my URI template without success.

@Path("/trennblatt/{objId}/{filename}/")

I also tried specifying the character set for filename (everything):

@Path("/trennblatt/{objId}/{filename:.+}")

I tried to to activate Jersey logging by adding:

<init-param>
    <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
    <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
</init-param>

but could not find any additional output. I even procmon'd for accessed files containing "log" or "out".

Googling for things like "jersey rest spaces @PathParam" always returns fun things like "How do I enabled slashes and dots in @PathParam". I can see how this would be an issue. But I could not find any clear statement about whether or not simple (and properly encoded) spaces in @PathParam should work.

When I'm using @QueryParam everything is fine.

@GET
@Path("/trennblatt")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getTrennblatt(
@QueryParam("objId") final long objId,
@QueryParam("filename") final String filename,
@Context final HttpServletResponse response)

[18/Apr/2016:11:17:47 +0200] "GET /.../trennblatt?objId=228342&filename=inspectionsheet.html HTTP/1.1" 200 44870
[18/Apr/2016:11:18:04 +0200] "GET /.../trennblatt?objId=228342&filename=01%20Aktendecke.pdf HTTP/1.1" 200 45081

This is my current workaround but there is a point to using @PathParam (keeping it as similar to our WebDAV service as possible). So I'd really like to get your input on this. Thanks!

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
annih
  • 395
  • 2
  • 6
  • 21
  • Can you reproduce the problem in a single runnable test like [this](https://gist.github.com/psamsotha/8737363cf85a797bf789ddccdadc42b6)? The test I'm running works. – Paul Samsotha Apr 18 '16 at 15:08
  • The test works fine even within my web app project. Not sure though how much of the context this test framework actually uses. It does not run tomcat for sure. So this might be caused by tomcat I guess. Or maybe spring is fiddling with it as well. Any guesses? – annih Apr 18 '16 at 17:20
  • Sorry I have no clue. – Paul Samsotha Apr 19 '16 at 16:41
  • @annih did you ever solve this? I have the same problem – Alb Sep 01 '16 at 08:48
  • Nope. I actually went with @QueryParam in the end. But maybe we can track the issues down a bit more. Are you using tomcat/spring? – annih Sep 13 '16 at 14:40

0 Answers0