I am developing Resteasy
. I migrated my application\'s maven dependencies from 2.2.x
to 3.0.x
and suddenly I saw most of the API\'s ar
Here's an example with query parameters and a check for the HTTP response code, which is handy for failing fast and avoiding stack traces from the JSON mapper, often hiding the real cause:
Response response = null;
try {
response = target.path("apiMethod")
.queryParam("stringParam", "test")
.queryParam("booleanParam", Boolean.FALSE)
.request().accept(MediaType.APPLICATION_JSON).get();
if (response.getStatus() == Response.Status.BAD_REQUEST.getStatusCode()) { // HTTP 400
throw new BadRequestException("invalid parameters!");
} else if (response.getStatus() ==
Response.Status.NOT_FOUND.getStatusCode()) { // HTTP 404
throw new NotFoundException("resource was not found on server!");
}
List result = response.readEntity(new GenericType>(){});
return result;
} finally {
if (response != null) {
response.close();
}
}