Java Reference
In-Depth Information
System
.
out
.
println
(
uri
);
}
...
}
}
If the request is
GET
http://example.com/customers/usa-db/333
, the output of the
for
loop in the
getCustomer()
method would print out the following:
http:
//example.com/customers
http:
//example.com/customers/usa-db
http:
//example.com/customers/usa-db/333
The matched URIs correspond to the
@Path
expressions on the following:
▪
CustomerDatabaseResource
▪
CustomerDatabaseResource.getDatabase()
▪
CustomerResource.getCustomer()
Honestly, I had a very hard time coming up with a use case for the
getMatchedURIs()
meth-
ods, so I can't really tell you why you might want to use them.
The final method of this category in
UriInfo
is the
getMatchedResources()
method:
public
public interface
interface
UriInfo
UriInfo
{
...
public
public
List
<
Object
>
getMatchedResources
();
}
This method returns a list of JAX-RS resource objects that have serviced the request. Let's
modify our
CustomerResource.getCustomer()
method again to illustrate how this method
works:
public
public class
class
CustomerResource
CustomerResource
{
private
private
Map customerDB
;
public
public
CustomerResource
(
Map db
) {
this
this
.
customerDB
=
db
;
}
@GET
@Path
(
"{id}"
)
@Produces
(
"application/xml"
)
public
public
StreamingOutput
getCustomer
(
@PathParam
(
"id"
)
int
int
id
,
@Context
UriInfo uriInfo
) {
for
(
Object match
:
uriInfo
.
getMatchedResources
()) {