Skip to content

Commit

Permalink
ENTESB-6497 - Proxy servlet should not display error stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
tadayosi committed Feb 8, 2017
1 parent 4d85746 commit 765c7c5
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions hawtio-system/src/main/java/io/hawt/web/ProxyServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -193,7 +195,9 @@ protected void service(HttpServletRequest servletRequest, HttpServletResponse se
try {
targetUriObj = new URI(proxyRequestUri);
} catch (URISyntaxException e) {
throw new ServletException(e);
LOG.debug("URL '{}' is not valid: {}", proxyRequestUri, e.getMessage());
servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}

HttpRequest proxyRequest;
Expand Down Expand Up @@ -275,14 +279,17 @@ protected void service(HttpServletRequest servletRequest, HttpServletResponse se
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);
// Exception needs to be suppressed for security reason
LOG.debug("Proxy to " + proxyRequestUri + " failed", e);
if (e instanceof ConnectException || e instanceof UnknownHostException) {
// Target host refused connection or doesn't exist
servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
} else if (e instanceof ServletException) {
// Redirect / Not Modified failed
servletResponse.sendError(HttpServletResponse.SC_BAD_GATEWAY, e.getMessage());
} else {
servletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}

} finally {
// make sure the entire entity was consumed, so the connection is released
Expand Down

0 comments on commit 765c7c5

Please sign in to comment.