Issue #3743 - Using Location based XmlConfiguration where possible

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2019-06-06 12:27:41 -05:00
parent 6686083462
commit a72a6ab875
4 changed files with 53 additions and 5 deletions

View File

@ -68,6 +68,45 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
private DefaultListableBeanFactory _beanFactory;
private String _main;
@Override
public void init(org.eclipse.jetty.util.resource.Resource jettyResource, XmlParser.Node config, XmlConfiguration configuration)
{
try
{
_configuration = configuration;
Resource springResource;
if (jettyResource != null)
{
springResource = new UrlResource(jettyResource.getURI());
}
else
{
springResource = new ByteArrayResource(("" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" +
config).getBytes(StandardCharsets.UTF_8));
}
_beanFactory = new DefaultListableBeanFactory()
{
@Override
protected void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs)
{
_configuration.initializeDefaults(bw.getWrappedInstance());
super.applyPropertyValues(beanName, mbd, bw, pvs);
}
};
new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(springResource);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
@Override
public void init(URL url, XmlParser.Node config, XmlConfiguration configuration)
{

View File

@ -38,8 +38,9 @@ public interface ConfigurationProcessor
*/
@Deprecated
void init(URL url, XmlParser.Node root, XmlConfiguration configuration);
void init(Resource resource, XmlParser.Node root, XmlConfiguration configuration);
Object configure( Object obj) throws Exception;
Object configure() throws Exception;
}

View File

@ -268,6 +268,15 @@ public class XmlConfiguration
}
}
private String getLocation()
{
if (_location == null)
{
return "UNKNOWN-LOCATION";
}
return _location.toString();
}
private void setConfig(XmlParser.Node config)
{
if ("Configure".equals(config.getTag()))
@ -283,7 +292,7 @@ public class XmlConfiguration
break;
}
if (_processor == null)
throw new IllegalStateException("Unknown configuration type: " + config.getTag() + " in " + this);
throw new IllegalStateException("Unknown configuration type: " + config.getTag() + " in " + getLocation());
}
else
{
@ -371,7 +380,7 @@ public class XmlConfiguration
@Override
public void init(Resource resource, XmlParser.Node root, XmlConfiguration configuration)
{
_location = resource == null ? null : resource.toString();
_location = resource == null ? "UNKNOWN_RESOURCE" : resource.toString();
_root = root;
_configuration = configuration;
}
@ -379,7 +388,7 @@ public class XmlConfiguration
@Override
public void init(URL url, XmlParser.Node root, XmlConfiguration configuration)
{
_location = url == null ? null : url.toString();
_location = url == null ? "UNKNOWN_URL" : url.toString();
_root = root;
_configuration = configuration;
}

View File

@ -666,7 +666,6 @@ public class XmlConfigurationTest
" </New>" +
" </Set>" +
"</Configure>");
// XmlConfiguration xmlConfiguration = new XmlConfiguration(url);
DefaultTestConfiguration atc = (DefaultTestConfiguration)xmlConfiguration.configure();