Skip to content

Commit

Permalink
add handleRequestException to enable customizing the way request exce…
Browse files Browse the repository at this point in the history
…ptions are handled.
  • Loading branch information
Flint, Shmulik authored and Flint, Shmulik committed Nov 19, 2017
1 parent 41315c2 commit 6166b41
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/main/java/org/mitre/dsmiley/httpproxy/ProxyServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,20 +298,7 @@ protected void service(HttpServletRequest servletRequest, HttpServletResponse se
}

} catch (Exception e) {
//abort request, according to best practice with HttpClient
if (proxyRequest instanceof AbortableHttpRequest) {
AbortableHttpRequest abortableHttpRequest = (AbortableHttpRequest) proxyRequest;
abortableHttpRequest.abort();
}
if (e instanceof RuntimeException)
throw (RuntimeException)e;
if (e instanceof ServletException)
throw (ServletException)e;
//noinspection ConstantConditions
if (e instanceof IOException)
throw (IOException) e;
throw new RuntimeException(e);

handleRequestException(proxyRequest, e);
} finally {
// make sure the entire entity was consumed, so the connection is released
if (proxyResponse != null)
Expand All @@ -321,6 +308,22 @@ protected void service(HttpServletRequest servletRequest, HttpServletResponse se
}
}

protected void handleRequestException(HttpRequest proxyRequest, Exception e) throws ServletException, IOException {
//abort request, according to best practice with HttpClient
if (proxyRequest instanceof AbortableHttpRequest) {
AbortableHttpRequest abortableHttpRequest = (AbortableHttpRequest) proxyRequest;
abortableHttpRequest.abort();
}
if (e instanceof RuntimeException)
throw (RuntimeException)e;
if (e instanceof ServletException)
throw (ServletException)e;
//noinspection ConstantConditions
if (e instanceof IOException)
throw (IOException) e;
throw new RuntimeException(e);
}

protected HttpResponse doExecute(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
HttpRequest proxyRequest) throws IOException {
if (doLog) {
Expand Down

0 comments on commit 6166b41

Please sign in to comment.