Validate using a query string
To validate the REST path, create a ping route that returns a passed
string value. The sample establishes the following URL path for the query:
- Authenticated: http://localhost:8095/{tenantGuid}/ext/sample/ping?pingValue=Hello
- Unauthenticated: http://localhost:8095/{tenantGuid}/ext/open/sample/ping?pingValue=Hello
@GET
and @Path
are
required to establish the REST route. For more information, see "Using @Path and @GET, @POST, etc" in the
jboss.org Community Documentation.The sample code returns an error if the passed value is null, or a
response if the passed value is a valid string.
@QueryParam
pingValue
is the value to return, @Suspended
asyncResponse
is the object that returns a response to the client.The following code is the same in both samples, but
SampleOpenController.java uses
AbstractController.OPEN_PATH_PREFIX
instead. SampleController.java
@GET @Path("/ping") public void pingQueryRoute(@QueryParam("pingValue") String pingValue, @Suspended final AsyncResponse asyncResponse) { // Log the request LOGGER.debug("{}/sample/ping?pingValue={}", AbstractController.PATH_PREFIX, pingValue); // The response to send back Response response = null; // No guarantee a query parameter is sent. Must check for null. if (pingValue != null) { // Create an OK response with the pingValue response = Response.ok(pingValue).build(); } else { // Create an error response response = Response.status(Status.BAD_REQUEST).entity("Must provide 'pingValue' on the query string").build(); // Log the error LOGGER.error("Must provide 'pingValue' on the query string"); } // Send back the response asyncResponse.resume(response); }