Java Reference
In-Depth Information
servlet container, that WAR will have a base URI that browsers and remote clients use to ac-
cess it. @Path expressions are relative to this URI.
To receive a request, a Java method must have at least an HTTP method annotation like
@javax.ws.rs.GET applied to it. This method is not required to have an @Path annotation
on it, though. For example:
@Path ( "/orders" )
public
public class
class OrderResource
OrderResource {
@GET
public
public String getAllOrders () {
...
}
}
An HTTP request of GET /orders would dispatch to the getAllOrders() method.
You can also apply @Path to your Java method. If you do this, the URI matching pattern is a
concatenation of the class's @Path expression and that of the method's. For example:
@Path ( "/orders" )
public
public class
class OrderResource
OrderResource {
@GET
@Path ( "unpaid" )
public
public String getUnpaidOrders () {
...
}
}
So, the URI pattern for getUnpaidOrders() would be the relative URI /orders/unpaid .
@Path Expressions
The value of the @Path annotation is usually a simple string, but you can also define more
complex expressions to satisfy your URI matching needs.
Template parameters
In Chapter 3 , we wrote a customer access service that allowed us to query for a specific cus-
tomer using a wildcard URI pattern:
@Path ( "/customers" )
public
public class
class CustomerResource
CustomerResource {
@GET
Search WWH ::




Custom Search