Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Custom error handler & use with Proxy Servlet

OK, I have at least partly answered my own question now. Problem was I didn't understand the continuation mechanism that was being used within the proxy servlet. I was trying to call response.sendError() when the response had been suspended.


On 27/04/11 13:52, Mark Payne wrote:
I have been using Jetty 7.1.6 embedded to host a couple of servlets I
have written myself, as well as a servlet that I extended from the jetty
ProxyServlet. I use the extended ProxyServlet so that I can call some
custom code when the HttpExchange onExpire() or onException() methods
get called. The general arrangement of things is as follows:


server = new Server(port);

ServletContextHandler context = new ServletContextHandler(
context.setErrorHandler(new CustomErrorHandler(this));

// First servlet
context.addServlet(new ServletHolder(new CustomServlet1(), "/context1/*");

// Second servlet
context.addServlet(new ServletHolder(new CustomServlet2(), "/context2/*");

// Forward any requests that can't be handled by CustomServlet1
// or CustomServlet2 to another server that can handle them
context.addServlet(new ServletHolder(new CustomProxy.Transparent(
"/", backEndServerHost, backEndServerPort)), "/");


The class that creates & starts the Jetty server needs to keep track of
whether there are any problems with the servlets i.e. if for some reason
they respond with status 500 (Internal server error). To do this I
create a custom error handler that I add to the ServletContextHandler
using setErrorHandler() as shown above.

Now, when I do response.sendError() in my custom servlets this gets
picked up by the custom error handler which checks the status code and
acts as I want. But when I call response.sendError() as a result of
onExpire() or onException() in the proxy servlet the custom error
handler isn't called. I still get a formatted HTML page with some
information about the exception, so SOME error handling code gets
called, but not mine. Can anyone explain why not?



Back to the top