users@grizzly.java.net

Re: Can ErrorPageGenerator produce output other than HTML?

From: Ryan Lubke <ryan.lubke_at_oracle.com>
Date: Fri, 05 May 2017 08:58:59 -0700

Yes. Provide a custom implementation of the ErrorPageGenerator
interface which can be used on a per-response [1] basis, or set globally
on the NetworkListener instance [2] of the HttpServer.

[1] Response.setErrorPageGenerator()
[2] NetworkListener.setDefaultErrorPageGenerator()


> Henning Verbeek <mailto:hankipanky_at_gmail.com>
> May 4, 2017 at 03:20
> Hello,
>
> I'm using Grizzly within Jersey, purely as a REST endpoint. The server
> consumes and produces content only with mediatype application/json.
> For most errors, I can make this happen by registering Jersy
> ExceptionMappers with Jersey: they produce a
> javax.ws.rs.core.Response, where I can control the mediatype of the
> entity.
>
> Some errors don't make it Jersey though, instead grizzly uses the
> configured default
> org.glassfish.grizzly.http.server.ErrorPageGenerator. An example is
> when an incoming request exceeds the configured maxPostSize.
> Unfortunately, the ErrorPageGenerator#generate() method requires me to
> generate a "HTML representation of the error page". I'd like to return
> a response with mediatype application/json. Is that possible?
>
> Thanks for your help.
> Regards,
> Henning