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 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?
Required and Optional Parameters Note that path parameters must have required: true , because they are always required.
The @PathParam annotation is a type of parameter that you can extract for use in your resource class. URI path parameters are extracted from the request URI, and the parameter names correspond to the URI path template variable names specified in the @Path class-level annotation.
Path parameters are part of the endpoint and are required. For example, `/users/{id}`, `{id}` is the path parameter of the endpoint `/users`- it is pointing to a specific user's record. An endpoint can have multiple path parameters, like in the example `/organizations/{orgId}/members/{memberId}`.
@PathParam is a parameter annotation which allows you to map variable URI path fragments into your method call.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With