Issue #1334 - throwing a ServletException if unable to commit the response (#1336)

* Issue #1334 - throwing a ServletException if unable to commit the response

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>

* Issue #1334 - using addSuppressed(ex) instead of MultiException

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2017-03-29 20:50:55 -04:00 committed by Greg Wilkins
parent 781c5750d9
commit a8ff18db9d
1 changed files with 30 additions and 5 deletions

View File

@ -225,28 +225,53 @@ public class Dispatcher implements RequestDispatcher
return String.format("Dispatcher@0x%x{%s,%s}",hashCode(),_named,_uri);
}
private void commitResponse(ServletResponse response, Request baseRequest) throws IOException
@SuppressWarnings("Duplicates")
private void commitResponse(ServletResponse response, Request baseRequest) throws IOException, ServletException
{
if (baseRequest.getResponse().isWriting())
{
try
{
// Try closing Writer first (based on knowledge in Response obj)
response.getWriter().close();
}
catch (IllegalStateException e)
catch (IllegalStateException e1)
{
response.getOutputStream().close();
try
{
// Try closing OutputStream as alternate route
// This path is possible due to badly behaving Response wrappers
response.getOutputStream().close();
}
catch(IllegalStateException e2)
{
ServletException servletException = new ServletException("Unable to commit the response", e2);
servletException.addSuppressed(e1);
throw servletException;
}
}
}
else
{
try
{
// Try closing OutputStream first (based on knowledge in Response obj)
response.getOutputStream().close();
}
catch (IllegalStateException e)
catch (IllegalStateException e1)
{
response.getWriter().close();
try
{
// Try closing Writer as alternate route
// This path is possible due to badly behaving Response wrappers
response.getWriter().close();
}
catch(IllegalStateException e2)
{
ServletException servletException = new ServletException("Unable to commit the response", e2);
servletException.addSuppressed(e1);
throw servletException;
}
}
}
}