Can ErrorPageGenerator produce output other than HTML?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Can ErrorPageGenerator produce output other than HTML?

Henning Verbeek
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
Reply | Threaded
Open this post in threaded view
|

Re: Can ErrorPageGenerator produce output other than HTML?

Ryan Lubke-2
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()


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