1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
@Path("/api/v1")
public class MyApiResource {
@Context
private UriInfo uriInfo;
@Autowired
private MyMetrics metrics;
@Autowired
private MyObjectService service;
@GET
@Path("/objects/{objectId}")
@Produces({ MediaType.APPLICATION_JSON })
Object getObject(@PathParam("objectId") String objectId) {
metrics.log(getPathTemplate());
return service.get(objectId);
}
/**
* Cette methode fait de la bidouille pour recuperer l'URI path template
*/
private String getPathTemplate() {
String path = uriInfo.getPath(); // path = /api/v1/objects/1234
for (String paramKey : uriInfo.getPathParameters().keySet()) { // paramKey = objectId
for (String paramValue : uriInfo.getPathParameters().get(paramKey)) { // paramValue = 1234
path = path.replace(paramValue, "{" + paramKey + "}");
}
}
return path; // path = /api/v1/objects/{objectId}
}
} |
Partager