HTML Body for Non-200 JAX-RS Responses on Payara Server
Payara generates for all client errors (400–499) and server errors (500–599) a default HTML body for "bodyless" responses like:
@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.
Another possible solution to prevent Payara from producing the default HTML response is to configure an empty errorReportValve.
In domain.xml -> configs -> config -> http-service -> virtual-server
add the following tag
<property name="errorReportValve" value=""></property>
Example:
<configs>
<config name="server-config">
<http-service>
<access-log></access-log>
<virtual-server network-listeners="http-listener-1,http-listener-2" id="server">
<property name="errorReportValve" value=""></property>
</virtual-server>
<virtual-server network-listeners="admin-listener" id="__asadmin"></virtual-server>
</http-service>
Posted by Per-Axel Felth on March 12, 2020 at 11:59 PM CET #