Skip to content

Commit

Permalink
Issue #1334 - throwing a ServletException if unable to commit the res…
Browse files Browse the repository at this point in the history
…ponse (#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>
  • Loading branch information
joakime authored and gregw committed Mar 30, 2017
1 parent 781c575 commit a8ff18d
Showing 1 changed file with 30 additions and 5 deletions.
Expand Up @@ -225,28 +225,53 @@ public String toString()
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;
}
}
}
}
Expand Down

0 comments on commit a8ff18d

Please sign in to comment.