Annotation Interface RequestPath


@Inherited @Documented @Target({FIELD,PARAMETER}) @Retention(RUNTIME) public @interface RequestPath
Qualifies a URI injection point with a relative path that is appended to the deployment's base URI. This annotation is used in conjunction with ServerResource to create URIs that point to specific endpoints within your deployed application.

The path specified in this annotation is appended to the base URI of the deployment, handling slashes automatically. For example, if the deployment base URI is http://localhost:8080/myapp and you specify @RequestPath("/api/users"), the resulting URI will be http://localhost:8080/myapp/api/users.

Example usage with field injection:

 @WildFlyTest
 public class OrderTest {
     @ServerResource
     @RequestPath("/api/orders")
     private URI ordersUri;

     @Test
     public void testGetOrders() throws Exception {
         HttpClient client = HttpClient.newHttpClient();
         HttpRequest request = HttpRequest.newBuilder(ordersUri).GET().build();
         HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
         Assertions.assertEquals(200, response.statusCode());
     }
 }
 

Example usage with parameter injection:

 @WildFlyTest
 public class UserTest {
     @Test
     public void testGetUsers(@ServerResource @RequestPath("/api/users") URI usersUri) throws Exception {
         HttpClient client = HttpClient.newHttpClient();
         HttpRequest request = HttpRequest.newBuilder(usersUri).GET().build();
         HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
         Assertions.assertEquals(200, response.statusCode());
     }
 }
 
Author:
James R. Perkins
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The relative path to append to the deployment's base URI.
  • Element Details

    • value

      String value
      The relative path to append to the deployment's base URI. The path can start with or without a leading slash; the framework handles slash normalization automatically.
      Returns:
      the relative path