Java Reference
In-Depth Information
class to define the full path to the RESTful web service. The annotation is defined as fol-
lows:
@Target(value = {ElementType.TYPE, ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Path {
public String value();
}
Parameters can be encoded within the URI using curly brackets ({}) . The parameters
are bound to method parameters using @java.ws.rs.PathParam ; we'll cover this an-
notation next. There can be as many curly brackets containing annotations that will be
passed into the web service as needed.
Using the @PathParam annotation
The @javax.ws.rs.PathParam annotation maps the parameters specified by the
@javax.ws.rs.Path annotation to actual parameters of the Java method. The JAX-RS
implementation will perform type conversion when invoking your methods. The annota-
tion is defined as follows:
@Target(value = {ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface PathParam {
public String value();
}
Consider the following example that has two parameters encoded within the URI, userId
and category :
@GET
@Path("/list/{userId}/{category}")
public List<Item> listBids(
@PathParam("category")String category,
@PathParam("userId")long userId
) {
...
}
In this example, category and userID are mapped from the request URI to the para-
meters. Assuming the class is annotated with @Path("/bidService") , an example
invocation would look like this:
Search WWH ::




Custom Search