When using Spring's HATEOAS support, I really like the AnnotationMappingDiscoverer
which helps avoid hard-coding REST resource paths in tests. With it, I can do things like
discoverer = new AnnotationMappingDiscoverer(RequestMapping.class);
Method method = MyController.class.getMethod("myResourceMethod", params);
String path = discoverer.getMapping(method);
And then use that path
as the resource path in tests. Much better than hard-coding paths in tests that have to be kept in sync with the controller class and method annotations.
Is there anything similar for RESTEasy?
You can use the UriBuilder :
Assuming following class:
@Path("persons")
public class PersonResource {
@Path("/{id}")
public Response get(@PathParam("id") String id) {
//
}
}
You would get the path like this:
URI path = UriBuilder.fromResource(PersonResource.class)
.path(PersonResource.class, "get")
.build("4711");
// path = /persons/4711
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.