Annotation Interface RequestPath


@Inherited @Documented @Target({FIELD,PARAMETER}) @Retention(RUNTIME) public @interface RequestPath
Qualifies a URI or WebTarget 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 or WebTargets 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 URI injection:

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

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

Example usage with WebTarget injection:

 @WildFlyTest
 public class UserTest {
     @ServerResource
     @RequestPath("/api/users")
     private WebTarget usersTarget;

     @Test
     public void testGetUsers() throws Exception {
         try (Response response = usersTarget.request().get()) {
             Assertions.assertEquals(200, response.getStatus());
             User[] users = response.readEntity(User[].class);
         }
     }
 }
 

Example usage with parameter injection:

 @WildFlyTest
 public class ProductTest {
     @Test
     public void testGetProducts(@ServerResource @RequestPath("/api/products") WebTarget productsTarget) {
         try (Response response = productsTarget.request().get()) {
             Assertions.assertEquals(200, response.getStatus());
         }
     }
 }
 
Since:
1.0.0
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