Skip to content

Commit

Permalink
changes for throwing error when there is multiple springbootapplicat…
Browse files Browse the repository at this point in the history
…ion node including all server xml configurations

Signed-off-by: Arun Venmany <Arun.Kumar.V.N@ibm.com>
  • Loading branch information
arunvenmany-ibm committed Dec 24, 2024
1 parent de7429a commit f704c3d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ private void parseApplication(Document doc, XPathExpression expression) throws X
// add unique values only
if (!nodeValue.isEmpty()) {
if(expression.equals(XPATH_SERVER_SPRINGBOOT_APPLICATION)){
if(springBootAppNodeLocation.isPresent()){
throw new PluginExecutionException("Found multiple springBootApplication elements specified in the server configuration. Only one springBootApplication can be configured per Liberty server.");
}
springBootAppNodeLocation = Optional.of(nodeValue);
}
String resolved = VariableUtility.resolveVariables(log, nodeValue, null, getProperties(), getDefaultProperties(), getLibertyDirPropertyFiles());
Expand Down Expand Up @@ -550,9 +553,9 @@ private void parseInclude(Document doc) throws XPathExpressionException, IOExcep
for (Document inclDoc : inclDocs) {
parseApplication(inclDoc, XPATH_SERVER_APPLICATION);
parseApplication(inclDoc, XPATH_SERVER_WEB_APPLICATION);
parseApplication(doc, XPATH_SERVER_SPRINGBOOT_APPLICATION);
parseApplication(inclDoc, XPATH_SERVER_SPRINGBOOT_APPLICATION);
parseApplication(inclDoc, XPATH_SERVER_ENTERPRISE_APPLICATION);
parseNames(doc, XPATH_ALL_SERVER_APPLICATIONS);
parseNames(inclDoc, XPATH_ALL_SERVER_APPLICATIONS);
// handle nested include elements
parseInclude(inclDoc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ServerConfigDocumentOverridesTest {
private final static Path SERVER_CONFIG_DIR = WLP_USER_DIR.resolve("servers/defaultServer");
private final static Path SHARED_CONFIG_DIR = WLP_USER_DIR.resolve("shared");
private final static Path SERVERS_RESOURCES_DIR = RESOURCES_DIR.resolve("servers/");
private final static Path SERVER_CONFIG_INCLUDE_DIR = SERVER_CONFIG_DIR.resolve("includes");

// 1. variable default values in server.xml file
// 6. variable values declared in the server.xml file
Expand Down Expand Up @@ -277,4 +278,28 @@ public void testServerConfigDocumentForLCLS() throws IOException, PluginExecutio
assertEquals("ServerConfigDocument http.port variable is not assigned properly ", "1111", configDocument.getProperties().getProperty("http.port"));
assertEquals("ServerConfigDocument includeLocation default property is not assigned properly ", "includes", configDocument.getDefaultProperties().getProperty("includeLocation"));
}

@Test
public void testProcessServerXmlWithMultipleSpringBootNodesInMultipleConfigFiles() throws IOException{
// we have added <springbootapplication> in valid_server.xml and included_server.xml
File serverConfigDir = SERVER_CONFIG_DIR.toFile();
Map<String, File> libertyDirPropMap = new HashMap<String, File>();
libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir);
libertyDirPropMap.put(ServerFeatureUtil.WLP_INSTALL_DIR, WLP_DIR.toFile());
libertyDirPropMap.put(ServerFeatureUtil.WLP_USER_DIR, WLP_USER_DIR.toFile());
libertyDirPropMap.put(ServerFeatureUtil.SHARED_CONFIG_DIR, SHARED_CONFIG_DIR.toFile());
File serversResourceDir = SERVERS_RESOURCES_DIR.toFile();
File springBootServerXmlDir = new File(serversResourceDir, "springBootApplicationTest");

File includedServerXml = new File(springBootServerXmlDir, "included_server.xml");
File newIncludedServerXml = new File(SERVER_CONFIG_INCLUDE_DIR.toFile(), "included_server.xml");
Files.copy(includedServerXml.toPath(), newIncludedServerXml.toPath(), StandardCopyOption.REPLACE_EXISTING);
File validServerXml = new File(springBootServerXmlDir, "valid_server.xml");
File newValidServerXml = new File(SERVER_CONFIG_INCLUDE_DIR.toFile(), "valid_server.xml");
Files.copy(validServerXml.toPath(), newValidServerXml.toPath(), StandardCopyOption.REPLACE_EXISTING);
assertThrows("Found multiple springBootApplication elements specified in the server configuration. Only one springBootApplication can be configured per Liberty server.",
PluginExecutionException.class, () -> new ServerConfigDocument(new TestLogger(), null, libertyDirPropMap));
Files.delete(newIncludedServerXml.toPath());
Files.delete(newValidServerXml.toPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
<variable name="server.env.defined" value="${this.value}"/>
<variable name="bootstrap.property.defined" value="${that.value}"/>
<variable name="config.dropins.server" value="2"/>

<include location="${includeLocationNonDefault}/included_server.xml"/>
<include location="${includeLocationNonDefault}/valid_server.xml"/>
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<springBootApplication id="guide-spring-boot"
location="guide-spring-boot-0.2.0.jar"
name="guide-spring-boot" />
</server>

0 comments on commit f704c3d

Please sign in to comment.