ARTEMIS-4515 Fix setting web request log using system properties

This commit is contained in:
Domenico Francesco Bruscino 2023-11-28 11:51:03 +01:00 committed by clebertsuconic
parent bba832139c
commit 6597f028a3
4 changed files with 84 additions and 1 deletions

View File

@ -115,4 +115,60 @@ public class RequestLogDTO {
*/
@XmlAttribute
public String format;
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public Boolean getAppend() {
return append;
}
public void setAppend(Boolean append) {
this.append = append;
}
public Boolean getExtended() {
return extended;
}
public void setExtended(Boolean extended) {
this.extended = extended;
}
public String getFilenameDateFormat() {
return filenameDateFormat;
}
public void setFilenameDateFormat(String filenameDateFormat) {
this.filenameDateFormat = filenameDateFormat;
}
public Integer getRetainDays() {
return retainDays;
}
public void setRetainDays(Integer retainDays) {
this.retainDays = retainDays;
}
public String getIgnorePaths() {
return ignorePaths;
}
public void setIgnorePaths(String ignorePaths) {
this.ignorePaths = ignorePaths;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
}

View File

@ -180,6 +180,7 @@ public class WebServerDTO extends ComponentDTO {
public WebServerDTO() {
componentClassName = "org.apache.activemq.artemis.component.WebServerComponent";
bindings = new ArrayList<>();
requestLog = new RequestLogDTO();
}
public List<BindingDTO> getAllBindings() {

View File

@ -175,7 +175,8 @@ public class WebServerComponent implements ExternalComponent, WebServerComponent
defaultHandler.setServeIcon(false);
defaultHandler.setRootRedirectLocation(this.webServerConfig.rootRedirectLocation);
if (this.webServerConfig.requestLog != null) {
if (this.webServerConfig.requestLog != null &&
this.webServerConfig.requestLog.filename != null) {
server.setRequestLog(getRequestLog());
}

View File

@ -156,6 +156,31 @@ public class WebServerDTOConfigTest {
testSetWebBindingAppProperties(webServer, BINDING_TEST_NAME, APP_TEST_URL);
}
@Test
public void testSetRequestLogProperties() throws Throwable {
WebServerDTO webServer = new WebServerDTO();
Properties properties = new Properties();
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "requestLog.filename", "filenameTest");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "requestLog.append", "true");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "requestLog.extended", "true");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "requestLog.filenameDateFormat", "filenameDateFormatTest");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "requestLog.retainDays", "3");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "requestLog.ignorePaths", "ignorePathTest0,ignorePathTest1,ignorePathTest2");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "requestLog." + INVALID_ATTRIBUTE_NAME, "true");
Configuration configuration = new ConfigurationImpl();
String systemWebPropertyPrefix = ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix();
configuration.parsePrefixedProperties(webServer, "system-" + systemWebPropertyPrefix, properties, systemWebPropertyPrefix);
Assert.assertEquals("filenameTest", webServer.getRequestLog().getFilename());
Assert.assertEquals(true, webServer.getRequestLog().getAppend());
Assert.assertEquals(true, webServer.getRequestLog().getExtended());
Assert.assertEquals("filenameDateFormatTest", webServer.getRequestLog().getFilenameDateFormat());
Assert.assertEquals(Integer.valueOf(3), webServer.getRequestLog().getRetainDays());
Assert.assertEquals("ignorePathTest0,ignorePathTest1,ignorePathTest2", webServer.getRequestLog().getIgnorePaths());
testStatus(configuration.getStatus(), "system-" + systemWebPropertyPrefix, "requestLog.");
}
private void testSetWebBindingAppProperties(WebServerDTO webServer, String bindingName, String appName) throws Throwable {
Properties properties = new Properties();
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".apps." + appName + ".url", APP_TEST_URL);