In Quarkus, when returning a url to another resource or a url for a redirect,
how to get the url of the other resource?
The path to a resource method is defined in @Path
annotations. I would not want to use strings to reference to such a resource since that would then break as soon as the @Path
is changed.
For testing there is @TestHTTPResouce @TestHTTPEndpoint(MyResource.class) URL myResourceUrl
but there does not seem to be a similar functionality for the main code.
Using UriBuilder.fromResource(MyResource.class).build();
only returns a string with the path of the resource, but now the full url like ‘https://server:port/basepath/myresource’.
Also, UriBuilder.fromMethod(MyResource.class, "someMethod")
only returns the path of the method, e.g. ‘someMethod’, and is not prefixed with the path of the resource itself. I would expected at least a ‘myResource/someMethod’ path.
Jakarta’s @Context ResourceContext context
argument only provides a way to get an instance of MyResource
but not to get the url.
The UriInfo
context allows resolving of a URI, but that URI cannot be determined for a resource method.