HTML Body for Non-200 JAX-RS Responses on Payara Server 📎
@Path("ping")
public class PingResource {
@GET
@Path("bodyless")
@Produces(MediaType.APPLICATION_JSON)
public Response bodyless() {
return Response.
status(412).
build();
}
}
The following command:
curl -i localhost:8080/jaxrs-non200-with-json/resources/ping/bodyless
...generates a reponse with a default HTML body including the error message in a human-readable format:
HTTP/1.1 412 Precondition Failed
Server: Payara Server 5.194 #badassfish
(...)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
(...)
An "erroneous" HTTP response with body:
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response ping() {
JsonObject result = Json.createObjectBuilder().
add("hey", "joe").
build();
return Response.status(412).
entity(result).
build();
}
...requested with curl -i localhost:8080/jaxrs-non200-with-json/resources/ping
Arrives as expected:
HTTP/1.1 412 Precondition Failed
Server: Payara Server 5.194 #badassfish
(...)
{"hey":"joe"}
The behaviour described in this post was discussed during the 72nd airhacks.tv episode.