A few things to address ...
Don't put
HttpServletResponse and PrintWriter as field members.
Keep in mind that you have 1
instance and multiple requests.
Don't call
baseRequest.setHandled(true) till you are done handling the
request.
Don't forget to close your
writer.
Using the try-with-resources
pattern that might make this easier for you (as PrintWriter
is an AutoCloseable resource)
try(PrintWriter writer =
response.getWriter())
{
// your logic on what
content to respond with.
writer.println("Hello");
} finally {
baseRequest.setHandled(true)
}
Under
Jetty, you can have multiple handlers work with the same
response.getWriter(), merely ending the handler, or setting
the baseRequest.setHandled(true) is not sufficient to let
jetty know that the response is done.
If
you don't want to close the PrintWriter, at least flush it.
(but know that an unclosed Writer will result in Jetty
issuing the response content as chunked)
(Note:
the Handler behavior in this regard is different than the
Servlet behavior)