I created the JAX-RS service (MyService), which has a number of additional resources, each of which is a subclass of MySubResource. The selected auxiliary resource class is selected based on the parameters specified in the MyService path, for example:
@Path("/") @Provides({"text/html", "text/xml"})
public class MyResource {
@Path("people/{id}") public MySubResource getPeople(@PathParam("id") String id) {
return new MyPeopleSubResource(id);
}
@Path("places/{id}") public MySubResource getPlaces(@PathParam("id") String id) {
return new MyPlacesSubResource(id);
}
}
where MyPlacesSubResource and MyPeopleSubResource are subclasses of MySubResource.
MySubResource is defined as:
public abstract class MySubResource {
protected abstract Results getResults();
@GET public Results get() { return getResults(); }
@GET @Path("xml")
public Response getXml() {
return Response.ok(getResults(), MediaType.TEXT_XML_TYPE).build();
}
@GET @Path("html")
public Response getHtml() {
return Response.ok(getResults(), MediaType.TEXT_HTML_TYPE).build();
}
}
Results are processed by the corresponding MessageBodyWriters, depending on the type of response image.
While this works, it leads to paths like / people / Bob / html or / people / Bob / xml, where what I really want is /people/Bob.html or / people / Bob.xml
Does anyone know how to accomplish what I want to do?