Skip to content

Commit

Permalink
Make instance.name config XML optional (frankframework#7356)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsm5 authored Aug 20, 2024
1 parent 38bcb96 commit 019781f
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 436 deletions.
13 changes: 13 additions & 0 deletions console/frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<versionRange>[1,)</versionRange>
<goals>
<goal>exec</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.validation.ValidatorHandler;

import jakarta.annotation.Nullable;

import org.apache.commons.digester3.Digester;
import org.apache.commons.digester3.binder.DigesterLoader;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -138,40 +140,44 @@ private void logErrorMessage(String prefix, SAXParseException exception) {
}
}

private Digester getDigester(Configuration configuration) throws ConfigurationException, ParserConfigurationException, SAXException {
XMLReader reader = XmlUtils.getXMLReader(configuration);
Digester digester = new Digester(reader) {
// override Digester.createSAXException() implementations to obtain a clear unduplicated message and a properly nested stacktrace on IBM JDK
@Override
public SAXException createSAXException(String message, Exception e) {
return SaxException.createSaxException(message, getDocumentLocator(), e);
}
@Override
public SAXException createSAXException(Exception e) {
return SaxException.createSaxException(null, getDocumentLocator(), e);
}
};

digester.setUseContextClassLoader(true);
digester.push(configuration);

Resource digesterRulesResource = Resource.getResource(configuration, getDigesterRuleFile());
loadDigesterRules(digester, digesterRulesResource);

if (validation) {
digester.setValidating(true);
digester.setNamespaceAware(true);
digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
URL xsdUrl = ClassLoaderUtils.getResourceURL(CONFIGURATION_VALIDATION_SCHEMA);
if (xsdUrl==null) {
throw new ConfigurationException("cannot get URL from ["+CONFIGURATION_VALIDATION_SCHEMA+"]");
private Digester getDigester(Configuration configuration) throws ConfigurationException {
try {
XMLReader reader = XmlUtils.getXMLReader(configuration);
Digester digester = new Digester(reader) {
// override Digester.createSAXException() implementations to obtain a clear unduplicated message and a properly nested stacktrace on IBM JDK
@Override
public SAXException createSAXException(String message, Exception e) {
return SaxException.createSaxException(message, getDocumentLocator(), e);
}
@Override
public SAXException createSAXException(Exception e) {
return SaxException.createSaxException(null, getDocumentLocator(), e);
}
};

digester.setClassLoader(configuration.getClassLoader());
digester.push(configuration);

Resource digesterRulesResource = Resource.getResource(configuration, getDigesterRuleFile());
loadDigesterRules(digester, digesterRulesResource);

if (validation) {
digester.setValidating(true);
digester.setNamespaceAware(true);
digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");

URL xsdUrl = ClassLoaderUtils.getResourceURL(CONFIGURATION_VALIDATION_SCHEMA);
if (xsdUrl==null) {
throw new ConfigurationException("cannot get URL from ["+CONFIGURATION_VALIDATION_SCHEMA+"]");
}
digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", xsdUrl.toExternalForm());
XmlErrorHandler xeh = new XmlErrorHandler(CONFIGURATION_VALIDATION_SCHEMA);
digester.setErrorHandler(xeh);
}
digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", xsdUrl.toExternalForm());
XmlErrorHandler xeh = new XmlErrorHandler(CONFIGURATION_VALIDATION_SCHEMA);
digester.setErrorHandler(xeh);
return digester;
} catch (ParserConfigurationException | SAXException e) {
throw new ConfigurationException("unable to create configuration parser", e);
}

return digester;
}

private void loadDigesterRules(Digester digester, Resource digesterRulesResource) {
Expand All @@ -191,19 +197,15 @@ public void digest() throws ConfigurationException {
}

private void digestConfiguration(Configuration configuration) throws ConfigurationException {
String configurationFile = ConfigurationUtils.getConfigurationFile(configuration.getClassLoader(), configuration.getName());
Digester digester = null;
Resource configurationResource = getConfigurationResource(configuration);

Resource configurationResource = Resource.getResource(configuration, configurationFile);
if (configurationResource == null) {
throw new ConfigurationException("Configuration file ["+configurationFile+"] not found in ClassLoader ["+configuration.getClassLoader()+"]");
if(configurationResource == null) {
return;
}

Digester digester = getDigester(configuration);
try {
digester = getDigester(configuration);

if (log.isDebugEnabled())
log.debug("digesting configuration [{}] configurationFile [{}]", configuration.getName(), configurationFile);
log.debug("digesting configuration [{}] configurationFile [{}]", configuration::getName, configurationResource::getSystemId);

AppConstants appConstants = AppConstants.getInstance(configuration.getClassLoader());
parseAndResolveEntitiesAndProperties(digester, configuration, configurationResource, appConstants);
Expand All @@ -217,8 +219,25 @@ private void digestConfiguration(Configuration configuration) throws Configurati
}
Locator locator = digester.getDocumentLocator();
String location = locator!=null ? " systemId ["+locator.getSystemId()+"] line ["+locator.getLineNumber()+"] column ["+locator.getColumnNumber()+"]":"";
throw new ConfigurationException("error during unmarshalling configuration from file [" + configurationFile + "] "+location+" with digester-rules-file ["+getDigesterRuleFile()+"] in element ["+currentElementName+"]", t);
throw new ConfigurationException("error during unmarshalling configuration from file [" + configurationResource + "] "+location+" with digester-rules-file ["+getDigesterRuleFile()+"] in element ["+currentElementName+"]", t);
}
}

@Nullable
private Resource getConfigurationResource(Configuration configuration) throws ConfigurationException {
String configurationFile = ConfigurationUtils.getConfigurationFile(configuration.getClassLoader(), configuration.getName());

Resource configurationResource = Resource.getResource(configuration, configurationFile);
if (configurationResource != null) {
return configurationResource;
}

if(ConfigurationUtils.isConfigurationXmlOptional(configuration)) {
configuration.log("no configuration file found, skipping xml digest");
return null;
}

throw new ConfigurationException("Configuration file ["+configurationFile+"] not found in ClassLoader ["+configuration.getClassLoader()+"]");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.frankframework.configuration.classloaders.DatabaseClassLoader;
import org.frankframework.configuration.classloaders.DirectoryClassLoader;
import org.frankframework.configuration.classloaders.IConfigurationClassLoader;
import org.frankframework.configuration.classloaders.WebAppClassLoader;
import org.frankframework.core.IbisTransaction;
import org.frankframework.core.SenderException;
import org.frankframework.dbms.JdbcException;
Expand Down Expand Up @@ -80,6 +81,7 @@ public class ConfigurationUtils {
private static final AppConstants APP_CONSTANTS = AppConstants.getInstance();
private static final boolean CONFIG_AUTO_DB_CLASSLOADER = APP_CONSTANTS.getBoolean("configurations.database.autoLoad", false);
private static final boolean CONFIG_AUTO_FS_CLASSLOADER = APP_CONSTANTS.getBoolean("configurations.directory.autoLoad", false);
private static final String INSTANCE_NAME = AppConstants.getInstance().getProperty("instance.name", null);
private static final String CONFIGURATIONS = APP_CONSTANTS.getProperty("configurations.names.application");
public static final String DEFAULT_CONFIGURATION_FILE = "Configuration.xml";

Expand All @@ -92,6 +94,12 @@ public static boolean isConfigurationStubbed(ClassLoader classLoader) {
return AppConstants.getInstance(classLoader).getBoolean(STUB4TESTTOOL_CONFIGURATION_KEY, false);
}

public static boolean isConfigurationXmlOptional(Configuration configuration) {
return CONFIG_AUTO_FS_CLASSLOADER &&
configuration.getClassLoader() instanceof WebAppClassLoader &&
configuration.getName().equals(INSTANCE_NAME);
}

public static String getConfigurationFile(ClassLoader classLoader, String currentConfigurationName) {
String configFileKey = "configurations." + currentConfigurationName + ".configurationFile";
String configurationFile = AppConstants.getInstance(classLoader).getProperty(configFileKey);
Expand Down
4 changes: 1 addition & 3 deletions test/src/main/configurations/WSS_HTTP/Configuration.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<Configuration>
<Include ref="ConfigurationWebServiceListenerSender.xml"/>
<Include ref="ConfigurationWebServiceListenerSenderNoSoap.xml"/>
<Include ref="ConfigurationHttpListenerSender.xml"/>
<!-- empty configuration -->
</Configuration>

This file was deleted.

Loading

0 comments on commit 019781f

Please sign in to comment.