Fábio Fábio - 1 month ago 20
Java Question

Optional @PathParam in Jax-RS

I have a service where the last part of the path is optional, the user can both enter /mypath/ and /mypath/param1/.

I tried to use a regular expression to filter the last part of the path:

@Path("/mypath{param1: (/param1)?}")


I'm using RestEasy as my JAX-RS provider and the code works as expected in Tomcat but when I deploy it in JBoss i get the a 405 return code when I do not submit the optional part.

Am I doing something wrong here or it's not possible to accomplish this in a portable way?

Answer

The problem was the lack of whitespace before the colon:

@Path("/mypath{param1: (/param1)?}")

should be:

@Path("/mypath{param1 : (/param1)?}")

Apparently it's a bug, because the specification makes the whitespace around the colon optional. I also found that I'm not the first bitten by this bug.

Comments