I think you want to use a UriBuilder.
The example I have looks like this:
private String buildRef(Airport a, UriBuilder ub) {
URI result = ub.path(AirportRM.class,"getByCode").build(a.getCode());
return result.toString();
}
where "AirportRM" is a resource class, and "getByCode" is one of the
methods in it. The URI will be built based on the URI template
detemined by the @Path annotations for AirportRM and its method
getByCode(), with the param expected replaced by the parameter to
build().
Moises