4.2. @PathParam and PathSegment
The specification has a very simple abstraction for examining a fragment of the URI path being invoked on
javax.ws.rs.core.PathSegment
:
public interface PathSegment { /** * Get the path segment. * <p> * @return the path segment */ String getPath(); /** * Get a map of the matrix parameters associated with the path segment * @return the map of matrix parameters */ MultivaluedMap<String, String> getMatrixParameters(); }
RESTEasy can inject a
PathSegment
instead of a value with your @PathParam
.
@GET @Path("/book/{id}") public String getBook(@PathParam("id") PathSegment id) {...}
This is particularly useful when you have multiple
@PathParam
s that use matrix parameters. Matrix parameters are an arbitrary set of name-value pairs embedded in a URI path segment. The PathSegment
object fives you access to these parameters. See Chapter 7, @MatrixParam for further information.
An example of a matrix parameter:
GET http://host.com/library/book;name=EJB 3.0;author=Bill Burke
A matrix parameter represents a resource that can be addressed by its attributes as well as its raw ID.