Class HalLinkProvider
- All Implemented Interfaces:
jakarta.ws.rs.core.Feature
Usage:
@Path("") interface TestApi { @Path("/testPath/{testArg}") @GET String testMethod(@PathParam("testArg") String testArg, @QueryParam("query") query); } // Get the generated HALLink HALLink HalLink = linkTo(methodOn(TestApi.class).testMethod("ResourceID", "detailed")).asHalLink(); // Get the generated URI URI Uri = linkTo(methodOn(TestApi.class).testMethod("ResourceID", "detailed")).asURI();
The example would create the following URI:
"baseUri/testPath/ResourceID?query=detailed"
The builder will use the `UriInfo` of the current request context to create absolute URIs. If no request context is available, it will fall back to a simple path without host that does not include any configured root or context path.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
configure
(jakarta.ws.rs.core.FeatureContext context) static HalLinkProvider
Returns the singleton instance of the HalLinkProviderstatic LinkResult
Creates a HALLink based on JAX-RS annotated parameters of an interface.static <T> T
Creates and returns a proxy instance based on the passed type parameter with a method invocation handler, which processes and saves the needed method invocation information in the current thread.
-
Method Details
-
linkTo
Creates a HALLink based on JAX-RS annotated parameters of an interface. This method requires a second entrypoint with HalLinkInvocationStateUtility.methodOn(Class) to process the annotated JAX-RS interface with the corresponding PathParam and QueryParam and the passed arguments to the proxied method invocation.Example:
@Path("") interface TestApi { @Path("/testPath/{testArg}") @GET String testMethod(@PathParam("testArg") String testArg, @QueryParam("query") query); } // Get the generated HALLink HALLink halLink = linkTo(methodOn(TestApi.class).testMethod("ResourceID", "detailed")).asHalLink(); // Get the generated URI URI uri = linkTo(methodOn(TestApi.class).testMethod("ResourceID", "detailed")).asURI();
The example would create the following URI:
"baseUri/testPath/ResourceID?query=detailed"
The builder will use the `UriInfo` of the current request context to create absolute URIs. If no request context is available, it will fall back to a simple path without host that does not include any configured root or context path.
- Parameters:
invocation
- the invocation placeholder.- Returns:
- the generated LinkResult based on the method invocation
- Throws:
HalLinkMethodInvocationException
- - If no method invocation is provided via methodOn(Class)
-
methodOn
Creates and returns a proxy instance based on the passed type parameter with a method invocation handler, which processes and saves the needed method invocation information in the current thread. Parameters in the afterwards called method of the proxy will be used to resolve the URI template of the corresponding method. The called method of the interface must have a return type, which means it should not be of typevoid
.After the method invocation of the proxy instance the outer method linkTo(Object) will process the derived information of the invocation to create the HALLink.
It should be ensured that the parameters are annotated with PathParam or with QueryParam. The passed class type must represent interfaces, not classes or primitive types.
- Type Parameters:
T
- the type parameter based on the passed type.- Parameters:
type
- the type on which the method should be invoked must be an interface.- Returns:
- the proxy instance
- Throws:
HalLinkMethodInvocationException
- if the proxy instance could not be created
-
configure
public boolean configure(jakarta.ws.rs.core.FeatureContext context) - Specified by:
configure
in interfacejakarta.ws.rs.core.Feature
-
getInstance
Returns the singleton instance of the HalLinkProvider- Returns:
- the HalLinProvider instance
-