Liran Zelkha has uploaded a new change for review. Change subject: core: Remove error message when reports.xml doesn't exist ......................................................................
core: Remove error message when reports.xml doesn't exist WebAdmin requests the reports.xml file after login, and ServletUtils prints an error message to the log if the file is not found. This patch provides an option to hide error messages on unneeded files that don't exist. Change-Id: Iaf6b075eb4754c5bb4153da8c6032a01bf801516 Bug-Url: https://bugzilla.redhat.com/1060242 Signed-off-by: [email protected] <[email protected]> --- M backend/manager/modules/branding/src/test/java/org/ovirt/engine/core/branding/BrandingServletTest.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/servlet/ServletUtils.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/FileServletTest.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/ServletUtilsTest.java A packaging/dbscripts/upgrade/03_04_0650_not_required_files.sql 6 files changed, 47 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/24/25324/1 diff --git a/backend/manager/modules/branding/src/test/java/org/ovirt/engine/core/branding/BrandingServletTest.java b/backend/manager/modules/branding/src/test/java/org/ovirt/engine/core/branding/BrandingServletTest.java index fef3a15..b200d34 100644 --- a/backend/manager/modules/branding/src/test/java/org/ovirt/engine/core/branding/BrandingServletTest.java +++ b/backend/manager/modules/branding/src/test/java/org/ovirt/engine/core/branding/BrandingServletTest.java @@ -21,7 +21,11 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; +import org.ovirt.engine.core.common.config.Config; +import org.ovirt.engine.core.common.config.ConfigValues; +import org.ovirt.engine.core.common.config.IConfigUtilsInterface; @RunWith(MockitoJUnitRunner.class) public class BrandingServletTest { @@ -66,6 +70,11 @@ @Test public void testDoGet_NotFound_MissingFile() throws IOException, ServletException { + final IConfigUtilsInterface configUtils = Mockito.mock(IConfigUtilsInterface.class); + Mockito.when(configUtils.getValue(ConfigValues.NotRequiredFiles, "general")) + .thenReturn(""); + Config.setConfigUtils(configUtils); + // The file should not exist, and thus return a 404. testServlet.doGet(mockRequest, mockResponse); verify(mockResponse).sendError(HttpServletResponse.SC_NOT_FOUND); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java index a75c3aa..a781039 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java @@ -1634,5 +1634,10 @@ @DefaultValueAttribute("true") GetFileStats, + @Reloadable + @TypeConverterAttribute(String.class) + @DefaultValueAttribute("") + NotRequiredFiles, + Invalid; } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/servlet/ServletUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/servlet/ServletUtils.java index f3ceb26..0d9fbec 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/servlet/ServletUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/servlet/ServletUtils.java @@ -12,6 +12,8 @@ import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; +import org.ovirt.engine.core.common.config.Config; +import org.ovirt.engine.core.common.config.ConfigValues; public class ServletUtils { // The log: @@ -79,7 +81,10 @@ // Make sure the file exits and is readable and send a 404 error // response if it doesn't: if (!canReadFile(file)) { - log.error("Can't read file \"" + (file != null ? file.getAbsolutePath() : "") + "\" for request \"" + request.getRequestURI() + "\", will send a 404 error response."); + if (!isWhiteListFiles(file)) { + log.error("Can't read file \"" + (file != null ? file.getAbsolutePath() : "") + "\" for request \"" + + request.getRequestURI() + "\", will send a 404 error response."); + } response.sendError(HttpServletResponse.SC_NOT_FOUND); } else { @@ -117,6 +122,18 @@ } } + private static boolean isWhiteListFiles(File file) { + if (file == null) + return false; + + String fileName = file.getName(); + + if (Config.<String> getValue(ConfigValues.NotRequiredFiles).contains(fileName)) { + return true; + } + return false; + } + /** * Check if the file is readable. * @param file diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/FileServletTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/FileServletTest.java index 2def429..d0f9a7b 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/FileServletTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/FileServletTest.java @@ -13,6 +13,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.ovirt.engine.core.utils.MockConfigRule.mockConfig; import java.io.File; import java.io.IOException; @@ -26,15 +27,21 @@ import javax.servlet.http.HttpServletResponse; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.ovirt.engine.core.common.config.ConfigValues; +import org.ovirt.engine.core.utils.MockConfigRule; @RunWith(MockitoJUnitRunner.class) public class FileServletTest { FileServlet testServlet; + @ClassRule + public static MockConfigRule mcr = new MockConfigRule(mockConfig(ConfigValues.NotRequiredFiles, "")); + @Mock ServletConfig mockConfig; @Mock diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/ServletUtilsTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/ServletUtilsTest.java index 64753be..950181c 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/ServletUtilsTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/ServletUtilsTest.java @@ -14,6 +14,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.ovirt.engine.core.utils.MockConfigRule.mockConfig; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; @@ -27,10 +28,16 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.junit.ClassRule; import org.junit.Test; +import org.ovirt.engine.core.common.config.ConfigValues; +import org.ovirt.engine.core.utils.MockConfigRule; public class ServletUtilsTest { + @ClassRule + public static MockConfigRule mcr = new MockConfigRule(mockConfig(ConfigValues.NotRequiredFiles, "")); + /** * Test method for {@link org.ovirt.engine.core.utils.servlet.ServletUtils#canReadFile(java.io.File)}. */ diff --git a/packaging/dbscripts/upgrade/03_04_0650_not_required_files.sql b/packaging/dbscripts/upgrade/03_04_0650_not_required_files.sql new file mode 100644 index 0000000..8dfc962 --- /dev/null +++ b/packaging/dbscripts/upgrade/03_04_0650_not_required_files.sql @@ -0,0 +1 @@ +select fn_db_add_config_value('NotRequiredFiles','reports.xml','general'); \ No newline at end of file -- To view, visit http://gerrit.ovirt.org/25324 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iaf6b075eb4754c5bb4153da8c6032a01bf801516 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Liran Zelkha <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
