Skip to content

Commit

Permalink
[BP] Fix write after response commit on proxy response (#7353)
Browse files Browse the repository at this point in the history
When the Links table is empty an 500 error happens:
java.lang.IllegalStateException: Cannot call sendError() after the response has been committed

This is caused because the response.sendError(...) method is being called twice when
the Links table has no entries. This commits fix this error calling the method only
once.
In addition, it removes unnecessary info returned to the client.

Signed-off-by: Juan Luis Rodríguez <juanluisrp@gmail.com>
  • Loading branch information
juanluisrp authored and josegar74 committed Sep 22, 2023
1 parent 29c7db5 commit 0a7171b
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ protected void service(HttpServletRequest servletRequest, HttpServletResponse se
} catch (SecurityException securityException) {
servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN,
securityException.getMessage());
return;
}

// Check if the link requested is in database link list
Expand All @@ -375,19 +376,16 @@ protected void service(HttpServletRequest servletRequest, HttpServletResponse se
LinkSpecs.filter(host, null, null,
null, null, null));
if (linksFound == 0) {
String message = String.format(
"The proxy does not allow to access '%s' " +
"because the URL host was not registered in any metadata records.",
uri
);
String message = "The proxy does not allow to access the requested URI " +
"because the URL host was not registered in any metadata records.";
if (linkRepository.count() == 0) {
servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN,
"The proxy is configured with DB_LINK_CHECK mode " +
"but the MetadataLink table is empty. " +
"Administrator may need to analyze record links from the admin console " +
"in order to register URL allowed by the proxy. " + message);
message = "The proxy is configured with DB_LINK_CHECK mode " +
"but the MetadataLink table is empty. " +
"Administrator may need to analyze record links from the admin console " +
"in order to register URL allowed by the proxy.";
}
servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, message);
return;
}
proxyCallAllowed = linksFound > 0;
} catch (URISyntaxException e) {
Expand Down

0 comments on commit 0a7171b

Please sign in to comment.