Merge pull request #3745 from eclipse/jetty-9.4.x-3743-xmlconfig-locations
Issue #3743 - Using Location based XmlConfiguration where possible
This commit is contained in:
commit
5dbc0bdaa5
|
@ -36,9 +36,8 @@ public class FileServerXml
|
||||||
{
|
{
|
||||||
public static void main( String[] args ) throws Exception
|
public static void main( String[] args ) throws Exception
|
||||||
{
|
{
|
||||||
Resource fileserverXml = Resource.newSystemResource("fileserver.xml");
|
Resource fileServerXml = Resource.newSystemResource("fileserver.xml");
|
||||||
XmlConfiguration configuration = new XmlConfiguration(
|
XmlConfiguration configuration = new XmlConfiguration(fileServerXml);
|
||||||
fileserverXml.getInputStream());
|
|
||||||
Server server = (Server) configuration.configure();
|
Server server = (Server) configuration.configure();
|
||||||
server.start();
|
server.start();
|
||||||
server.join();
|
server.join();
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class GlobalWebappConfigBinding implements AppLifeCycle.Binding
|
||||||
|
|
||||||
if (globalContextSettings.exists())
|
if (globalContextSettings.exists())
|
||||||
{
|
{
|
||||||
XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream());
|
XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings);
|
||||||
Resource resource = Resource.newResource(app.getOriginId());
|
Resource resource = Resource.newResource(app.getOriginId());
|
||||||
app.getDeploymentManager().scope(jettyXmlConfig,resource);
|
app.getDeploymentManager().scope(jettyXmlConfig,resource);
|
||||||
jettyXmlConfig.configure(context);
|
jettyXmlConfig.configure(context);
|
||||||
|
|
|
@ -160,7 +160,7 @@ public abstract class AbstractContextProvider extends AbstractLifeCycle implemen
|
||||||
{
|
{
|
||||||
Thread.currentThread().setContextClassLoader(classLoader);
|
Thread.currentThread().setContextClassLoader(classLoader);
|
||||||
|
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(res.getInputStream());
|
XmlConfiguration xmlConfiguration = new XmlConfiguration(res);
|
||||||
HashMap properties = new HashMap();
|
HashMap properties = new HashMap();
|
||||||
//put the server instance in
|
//put the server instance in
|
||||||
properties.put("Server", getServerInstanceWrapper().getServer());
|
properties.put("Server", getServerInstanceWrapper().getServer());
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.osgi.boot.internal.serverfactory;
|
package org.eclipse.jetty.osgi.boot.internal.serverfactory;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -142,10 +141,10 @@ public class ServerInstanceWrapper
|
||||||
|
|
||||||
for (URL jettyConfiguration : jettyConfigurations)
|
for (URL jettyConfiguration : jettyConfigurations)
|
||||||
{
|
{
|
||||||
try(InputStream in = jettyConfiguration.openStream())
|
try
|
||||||
{
|
{
|
||||||
// Execute a Jetty configuration file
|
// Execute a Jetty configuration file
|
||||||
XmlConfiguration config = new XmlConfiguration(in);
|
XmlConfiguration config = new XmlConfiguration(jettyConfiguration);
|
||||||
|
|
||||||
config.getIdMap().putAll(id_map);
|
config.getIdMap().putAll(id_map);
|
||||||
config.getProperties().putAll(properties);
|
config.getProperties().putAll(properties);
|
||||||
|
|
|
@ -69,18 +69,32 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
|
||||||
private String _main;
|
private String _main;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(URL url, XmlParser.Node config, XmlConfiguration configuration)
|
public void init(URL url, XmlParser.Node root, XmlConfiguration configuration)
|
||||||
|
{
|
||||||
|
// Moving back and forth between URL and File/FileSystem/Path/Resource is known to cause escaping issues.
|
||||||
|
init(org.eclipse.jetty.util.resource.Resource.newResource(url), root, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(org.eclipse.jetty.util.resource.Resource jettyResource, XmlParser.Node config, XmlConfiguration configuration)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
|
|
||||||
Resource resource = url != null
|
Resource springResource;
|
||||||
? new UrlResource(url)
|
|
||||||
: new ByteArrayResource(("" +
|
if (jettyResource != null)
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
{
|
||||||
"<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" +
|
springResource = new UrlResource(jettyResource.getURI());
|
||||||
config).getBytes(StandardCharsets.UTF_8));
|
}
|
||||||
|
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()
|
_beanFactory = new DefaultListableBeanFactory()
|
||||||
{
|
{
|
||||||
|
@ -92,7 +106,7 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(resource);
|
new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(springResource);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.websocket.client;
|
package org.eclipse.jetty.websocket.client;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
import org.eclipse.jetty.client.HttpClient;
|
||||||
|
@ -36,9 +35,9 @@ class XmlBasedHttpClientProvider
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try (InputStream in = resource.openStream())
|
try
|
||||||
{
|
{
|
||||||
XmlConfiguration configuration = new XmlConfiguration(in);
|
XmlConfiguration configuration = new XmlConfiguration(resource);
|
||||||
return (HttpClient) configuration.configure();
|
return (HttpClient) configuration.configure();
|
||||||
}
|
}
|
||||||
catch (Throwable t)
|
catch (Throwable t)
|
||||||
|
|
|
@ -18,8 +18,11 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.xml;
|
package org.eclipse.jetty.xml;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A ConfigurationProcessor for non XmlConfiguration format files.
|
* A ConfigurationProcessor for non XmlConfiguration format files.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -31,8 +34,33 @@ import java.net.URL;
|
||||||
*/
|
*/
|
||||||
public interface ConfigurationProcessor
|
public interface ConfigurationProcessor
|
||||||
{
|
{
|
||||||
public void init(URL url, XmlParser.Node root, XmlConfiguration configuration);
|
/**
|
||||||
|
* @deprecated use {@link #init(Resource, XmlParser.Node, XmlConfiguration)} instead
|
||||||
public Object configure( Object obj) throws Exception;
|
*/
|
||||||
public Object configure() throws Exception;
|
@Deprecated
|
||||||
|
void init(URL url, XmlParser.Node root, XmlConfiguration configuration);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize a ConfigurationProcessor from provided Resource and XML
|
||||||
|
*
|
||||||
|
* @param resource the resource being read
|
||||||
|
* @param root the parsed XML root node for the resource
|
||||||
|
* @param configuration the configuration being used (typically for ref IDs)
|
||||||
|
*/
|
||||||
|
default void init(Resource resource, XmlParser.Node root, XmlConfiguration configuration)
|
||||||
|
{
|
||||||
|
// Moving back and forth between URL and File/FileSystem/Path/Resource is known to cause escaping issues.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
init(resource.getURI().toURL(), root, configuration);
|
||||||
|
}
|
||||||
|
catch (MalformedURLException e)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("Unable to convert Resource to URL", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object configure(Object obj) throws Exception;
|
||||||
|
|
||||||
|
Object configure() throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,25 +176,42 @@ public class XmlConfiguration
|
||||||
|
|
||||||
private final Map<String, Object> _idMap = new HashMap<>();
|
private final Map<String, Object> _idMap = new HashMap<>();
|
||||||
private final Map<String, String> _propertyMap = new HashMap<>();
|
private final Map<String, String> _propertyMap = new HashMap<>();
|
||||||
private final URL _url;
|
private final Resource _location;
|
||||||
private final String _dtd;
|
private final String _dtd;
|
||||||
private ConfigurationProcessor _processor;
|
private ConfigurationProcessor _processor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads and parses the XML configuration file.
|
||||||
|
*
|
||||||
|
* @param resource the Resource to the XML configuration
|
||||||
|
* @throws IOException if the configuration could not be read
|
||||||
|
* @throws SAXException if the configuration could not be parsed
|
||||||
|
*/
|
||||||
|
public XmlConfiguration(Resource resource) throws SAXException, IOException
|
||||||
|
{
|
||||||
|
synchronized (__parser)
|
||||||
|
{
|
||||||
|
_location = resource;
|
||||||
|
try(InputStream inputStream = resource.getInputStream())
|
||||||
|
{
|
||||||
|
setConfig(__parser.parse(inputStream));
|
||||||
|
}
|
||||||
|
_dtd = __parser.getDTD();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads and parses the XML configuration file.
|
* Reads and parses the XML configuration file.
|
||||||
*
|
*
|
||||||
* @param configuration the URL of the XML configuration
|
* @param configuration the URL of the XML configuration
|
||||||
* @throws IOException if the configuration could not be read
|
* @throws IOException if the configuration could not be read
|
||||||
* @throws SAXException if the configuration could not be parsed
|
* @throws SAXException if the configuration could not be parsed
|
||||||
|
* @deprecated use {@link XmlConfiguration(Resource)} instead due to escaping issues
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public XmlConfiguration(URL configuration) throws SAXException, IOException
|
public XmlConfiguration(URL configuration) throws SAXException, IOException
|
||||||
{
|
{
|
||||||
synchronized (__parser)
|
this(Resource.newResource(configuration));
|
||||||
{
|
|
||||||
_url = configuration;
|
|
||||||
setConfig(__parser.parse(configuration.toString()));
|
|
||||||
_dtd = __parser.getDTD();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -204,17 +221,23 @@ public class XmlConfiguration
|
||||||
* The String should start with a "<Configure ....>" element.
|
* The String should start with a "<Configure ....>" element.
|
||||||
* @throws IOException if the configuration could not be read
|
* @throws IOException if the configuration could not be read
|
||||||
* @throws SAXException if the configuration could not be parsed
|
* @throws SAXException if the configuration could not be parsed
|
||||||
|
* @deprecated use Constructor which has location information
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public XmlConfiguration(String configuration) throws SAXException, IOException
|
public XmlConfiguration(String configuration) throws SAXException, IOException
|
||||||
{
|
{
|
||||||
configuration = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE Configure PUBLIC \"-//Jetty//Configure//EN\" \"http://eclipse.org/jetty/configure.dtd\">"
|
configuration = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
|
||||||
|
"<!DOCTYPE Configure PUBLIC \"-//Jetty//Configure//EN\" \"http://www.eclipse.org/jetty/configure_9_3.dtd\">"
|
||||||
+ configuration;
|
+ configuration;
|
||||||
InputSource source = new InputSource(new StringReader(configuration));
|
try (StringReader reader = new StringReader(configuration))
|
||||||
synchronized (__parser)
|
|
||||||
{
|
{
|
||||||
_url = null;
|
InputSource source = new InputSource(reader);
|
||||||
setConfig(__parser.parse(source));
|
synchronized (__parser)
|
||||||
_dtd = __parser.getDTD();
|
{
|
||||||
|
_location = null;
|
||||||
|
setConfig(__parser.parse(source));
|
||||||
|
_dtd = __parser.getDTD();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,18 +247,30 @@ public class XmlConfiguration
|
||||||
* @param configuration An input stream containing a complete configuration file
|
* @param configuration An input stream containing a complete configuration file
|
||||||
* @throws IOException if the configuration could not be read
|
* @throws IOException if the configuration could not be read
|
||||||
* @throws SAXException if the configuration could not be parsed
|
* @throws SAXException if the configuration could not be parsed
|
||||||
|
* @deprecated use Constructor which has location information
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public XmlConfiguration(InputStream configuration) throws SAXException, IOException
|
public XmlConfiguration(InputStream configuration) throws SAXException, IOException
|
||||||
{
|
{
|
||||||
InputSource source = new InputSource(configuration);
|
InputSource source = new InputSource(configuration);
|
||||||
synchronized (__parser)
|
synchronized (__parser)
|
||||||
{
|
{
|
||||||
_url = null;
|
_location = null;
|
||||||
setConfig(__parser.parse(source));
|
setConfig(__parser.parse(source));
|
||||||
_dtd = __parser.getDTD();
|
_dtd = __parser.getDTD();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
if (_location == null)
|
||||||
|
{
|
||||||
|
return "UNKNOWN-LOCATION";
|
||||||
|
}
|
||||||
|
return _location.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private void setConfig(XmlParser.Node config)
|
private void setConfig(XmlParser.Node config)
|
||||||
{
|
{
|
||||||
if ("Configure".equals(config.getTag()))
|
if ("Configure".equals(config.getTag()))
|
||||||
|
@ -257,7 +292,7 @@ public class XmlConfiguration
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Unknown XML tag:" + config.getTag());
|
throw new IllegalArgumentException("Unknown XML tag:" + config.getTag());
|
||||||
}
|
}
|
||||||
_processor.init(_url, config, this);
|
_processor.init(_location, config, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -332,14 +367,18 @@ public class XmlConfiguration
|
||||||
|
|
||||||
private static class JettyXmlConfiguration implements ConfigurationProcessor
|
private static class JettyXmlConfiguration implements ConfigurationProcessor
|
||||||
{
|
{
|
||||||
private String _url;
|
|
||||||
XmlParser.Node _root;
|
XmlParser.Node _root;
|
||||||
XmlConfiguration _configuration;
|
XmlConfiguration _configuration;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(URL url, XmlParser.Node root, XmlConfiguration configuration)
|
public void init(URL url, XmlParser.Node root, XmlConfiguration configuration)
|
||||||
{
|
{
|
||||||
_url = url == null ? null : url.toString();
|
// nobody calls this.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(Resource resource, XmlParser.Node root, XmlConfiguration configuration)
|
||||||
|
{
|
||||||
_root = root;
|
_root = root;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
@ -352,7 +391,7 @@ public class XmlConfiguration
|
||||||
if (oClass != null && !oClass.isInstance(obj))
|
if (oClass != null && !oClass.isInstance(obj))
|
||||||
{
|
{
|
||||||
String loaders = (oClass.getClassLoader() == obj.getClass().getClassLoader()) ? "" : "Object Class and type Class are from different loaders.";
|
String loaders = (oClass.getClassLoader() == obj.getClass().getClassLoader()) ? "" : "Object Class and type Class are from different loaders.";
|
||||||
throw new IllegalArgumentException("Object of class '" + obj.getClass().getCanonicalName() + "' is not of type '" + oClass.getCanonicalName() + "'. " + loaders + " in " + _url);
|
throw new IllegalArgumentException("Object of class '" + obj.getClass().getCanonicalName() + "' is not of type '" + oClass.getCanonicalName() + "'. " + loaders + " in " + _configuration);
|
||||||
}
|
}
|
||||||
String id = _root.getAttribute("id");
|
String id = _root.getAttribute("id");
|
||||||
if (id != null)
|
if (id != null)
|
||||||
|
@ -404,7 +443,7 @@ public class XmlConfiguration
|
||||||
}
|
}
|
||||||
catch (NoSuchMethodException x)
|
catch (NoSuchMethodException x)
|
||||||
{
|
{
|
||||||
throw new IllegalStateException(String.format("No constructor %s(%s,%s) in %s", oClass, arguments, namedArgMap, _url));
|
throw new IllegalStateException(String.format("No constructor %s(%s,%s) in %s", oClass, arguments, namedArgMap, _configuration));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (id != null)
|
if (id != null)
|
||||||
|
@ -496,12 +535,12 @@ public class XmlConfiguration
|
||||||
envObj(node);
|
envObj(node);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unknown tag: " + tag + " in " + _url);
|
throw new IllegalStateException("Unknown tag: " + tag + " in " + _configuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
LOG.warn("Config error at " + node, e.toString() + " in " + _url);
|
LOG.warn("Config error at " + node, e.toString() + " in " + _configuration);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -677,7 +716,7 @@ public class XmlConfiguration
|
||||||
{
|
{
|
||||||
Object result = constructor.newInstance(args);
|
Object result = constructor.newInstance(args);
|
||||||
if (constructor.getAnnotation(Deprecated.class) != null)
|
if (constructor.getAnnotation(Deprecated.class) != null)
|
||||||
LOG.warn("Deprecated constructor {} in {}", constructor, _url);
|
LOG.warn("Deprecated constructor {} in {}", constructor, _configuration);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,7 +724,7 @@ public class XmlConfiguration
|
||||||
{
|
{
|
||||||
Object result = method.invoke(obj, args);
|
Object result = method.invoke(obj, args);
|
||||||
if (method.getAnnotation(Deprecated.class) != null)
|
if (method.getAnnotation(Deprecated.class) != null)
|
||||||
LOG.warn("Deprecated method {} in {}", method, _url);
|
LOG.warn("Deprecated method {} in {}", method, _configuration);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,7 +732,7 @@ public class XmlConfiguration
|
||||||
{
|
{
|
||||||
Object result = field.get(object);
|
Object result = field.get(object);
|
||||||
if (field.getAnnotation(Deprecated.class) != null)
|
if (field.getAnnotation(Deprecated.class) != null)
|
||||||
LOG.warn("Deprecated field {} in {}", field, _url);
|
LOG.warn("Deprecated field {} in {}", field, _configuration);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,7 +740,7 @@ public class XmlConfiguration
|
||||||
{
|
{
|
||||||
field.set(obj, arg);
|
field.set(obj, arg);
|
||||||
if (field.getAnnotation(Deprecated.class) != null)
|
if (field.getAnnotation(Deprecated.class) != null)
|
||||||
LOG.warn("Deprecated field {} in {}", field, _url);
|
LOG.warn("Deprecated field {} in {}", field, _configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1519,7 +1558,7 @@ public class XmlConfiguration
|
||||||
if ("Env".equals(tag))
|
if ("Env".equals(tag))
|
||||||
return envObj(node);
|
return envObj(node);
|
||||||
|
|
||||||
LOG.warn("Unknown value tag: " + node, new Throwable());
|
LOG.warn("Unknown value tag: " + node + " in " + _configuration, new Throwable());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,14 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.xml;
|
package org.eclipse.jetty.xml;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.BufferedWriter;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -31,12 +33,18 @@ import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||||
|
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.util.log.StdErrLog;
|
import org.eclipse.jetty.util.log.StdErrLog;
|
||||||
|
import org.eclipse.jetty.util.resource.PathResource;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
@ -50,8 +58,11 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@ExtendWith(WorkDirExtension.class)
|
||||||
public class XmlConfigurationTest
|
public class XmlConfigurationTest
|
||||||
{
|
{
|
||||||
|
public WorkDir workDir;
|
||||||
|
|
||||||
protected String[] _configure=new String [] {"org/eclipse/jetty/xml/configureWithAttr.xml","org/eclipse/jetty/xml/configureWithElements.xml"};
|
protected String[] _configure=new String [] {"org/eclipse/jetty/xml/configureWithAttr.xml","org/eclipse/jetty/xml/configureWithElements.xml"};
|
||||||
|
|
||||||
private static final String STRING_ARRAY_XML = "<Array type=\"String\"><Item type=\"String\">String1</Item><Item type=\"String\">String2</Item></Array>";
|
private static final String STRING_ARRAY_XML = "<Array type=\"String\"><Item type=\"String\">String1</Item><Item type=\"String\">String2</Item></Array>";
|
||||||
|
@ -233,18 +244,26 @@ public class XmlConfigurationTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XmlConfiguration asXmlConfiguration(String rawXml) throws IOException, SAXException
|
||||||
|
{
|
||||||
|
Path testFile = workDir.getEmptyPathDir().resolve("raw.xml");
|
||||||
|
try(BufferedWriter writer = Files.newBufferedWriter(testFile, UTF_8))
|
||||||
|
{
|
||||||
|
writer.write(rawXml);
|
||||||
|
}
|
||||||
|
return new XmlConfiguration(new PathResource(testFile));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetClass() throws Exception
|
public void testGetClass() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration configuration =
|
XmlConfiguration configuration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\"><Get name=\"class\"/></Set></Configure>");
|
||||||
new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\"><Get name=\"class\"/></Set></Configure>");
|
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
configuration.configure(tc);
|
configuration.configure(tc);
|
||||||
assertEquals(TestConfiguration.class,tc.testObject);
|
assertEquals(TestConfiguration.class,tc.testObject);
|
||||||
|
|
||||||
configuration =
|
configuration =
|
||||||
new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\"><Get class=\"java.lang.String\" name=\"class\"><Get id=\"simple\" name=\"simpleName\"/></Get></Set></Configure>");
|
asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\"><Get class=\"java.lang.String\" name=\"class\"><Get id=\"simple\" name=\"simpleName\"/></Get></Set></Configure>");
|
||||||
configuration.configure(tc);
|
configuration.configure(tc);
|
||||||
assertEquals(String.class,tc.testObject);
|
assertEquals(String.class,tc.testObject);
|
||||||
assertEquals("String",configuration.getIdMap().get("simple"));
|
assertEquals("String",configuration.getIdMap().get("simple"));
|
||||||
|
@ -253,8 +272,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testStringConfiguration() throws Exception
|
public void testStringConfiguration() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration configuration =
|
XmlConfiguration configuration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\">SetValue</Set><Set name=\"Test\" type=\"int\">2</Set></Configure>");
|
||||||
new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\">SetValue</Set><Set name=\"Test\" type=\"int\">2</Set></Configure>");
|
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
configuration.configure(tc);
|
configuration.configure(tc);
|
||||||
assertEquals("SetValue", tc.testObject, "Set String 3");
|
assertEquals("SetValue", tc.testObject, "Set String 3");
|
||||||
|
@ -264,8 +282,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testMeaningfullSetException() throws Exception
|
public void testMeaningfullSetException() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration configuration =
|
XmlConfiguration configuration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"PropertyTest\"><Property name=\"null\"/></Set></Configure>");
|
||||||
new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"PropertyTest\"><Property name=\"null\"/></Set></Configure>");
|
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
|
|
||||||
NoSuchMethodException e = assertThrows(NoSuchMethodException.class, () -> {
|
NoSuchMethodException e = assertThrows(NoSuchMethodException.class, () -> {
|
||||||
|
@ -278,7 +295,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testListConstructorArg() throws Exception
|
public void testListConstructorArg() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
|
||||||
+ "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"List\">"
|
+ "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"List\">"
|
||||||
+ STRING_ARRAY_XML + "</Arg></New></Set></Configure>");
|
+ STRING_ARRAY_XML + "</Arg></New></Set></Configure>");
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
|
@ -291,7 +308,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testTwoArgumentListConstructorArg() throws Exception
|
public void testTwoArgumentListConstructorArg() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
|
||||||
+ "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\">"
|
+ "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\">"
|
||||||
+ "<Arg type=\"List\">" + STRING_ARRAY_XML + "</Arg>"
|
+ "<Arg type=\"List\">" + STRING_ARRAY_XML + "</Arg>"
|
||||||
+ "<Arg type=\"List\">" + STRING_ARRAY_XML + "</Arg>"
|
+ "<Arg type=\"List\">" + STRING_ARRAY_XML + "</Arg>"
|
||||||
|
@ -306,7 +323,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testListNotContainingArray() throws Exception
|
public void testListNotContainingArray() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
|
||||||
+ "<New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"List\">Some String</Arg></New></Configure>");
|
+ "<New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"List\">Some String</Arg></New></Configure>");
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
|
|
||||||
|
@ -318,7 +335,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testSetConstructorArg() throws Exception
|
public void testSetConstructorArg() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
|
||||||
+ "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"Set\">"
|
+ "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"Set\">"
|
||||||
+ STRING_ARRAY_XML + "</Arg></New></Set></Configure>");
|
+ STRING_ARRAY_XML + "</Arg></New></Set></Configure>");
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
|
@ -331,7 +348,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testSetNotContainingArray() throws Exception
|
public void testSetNotContainingArray() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
|
||||||
+ "<New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"Set\">Some String</Arg></New></Configure>");
|
+ "<New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"Set\">Some String</Arg></New></Configure>");
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
assertThrows(IllegalArgumentException.class, ()->{
|
assertThrows(IllegalArgumentException.class, ()->{
|
||||||
|
@ -342,7 +359,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testListSetterWithStringArray() throws Exception
|
public void testListSetterWithStringArray() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"List\">"
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"List\">"
|
||||||
+ STRING_ARRAY_XML + "</Set></Configure>");
|
+ STRING_ARRAY_XML + "</Set></Configure>");
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue()));
|
assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue()));
|
||||||
|
@ -353,7 +370,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testListSetterWithPrimitiveArray() throws Exception
|
public void testListSetterWithPrimitiveArray() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"List\">"
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"List\">"
|
||||||
+ INT_ARRAY_XML + "</Set></Configure>");
|
+ INT_ARRAY_XML + "</Set></Configure>");
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue()));
|
assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue()));
|
||||||
|
@ -364,7 +381,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testNotSupportedLinkedListSetter() throws Exception
|
public void testNotSupportedLinkedListSetter() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"LinkedList\">"
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"LinkedList\">"
|
||||||
+ INT_ARRAY_XML + "</Set></Configure>");
|
+ INT_ARRAY_XML + "</Set></Configure>");
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue()));
|
assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue()));
|
||||||
|
@ -376,7 +393,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testArrayListSetter() throws Exception
|
public void testArrayListSetter() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"ArrayList\">"
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"ArrayList\">"
|
||||||
+ INT_ARRAY_XML + "</Set></Configure>");
|
+ INT_ARRAY_XML + "</Set></Configure>");
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue()));
|
assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue()));
|
||||||
|
@ -387,7 +404,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testSetSetter() throws Exception
|
public void testSetSetter() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Set\">"
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Set\">"
|
||||||
+ STRING_ARRAY_XML + "</Set></Configure>");
|
+ STRING_ARRAY_XML + "</Set></Configure>");
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue()));
|
assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue()));
|
||||||
|
@ -398,7 +415,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testSetSetterWithPrimitiveArray() throws Exception
|
public void testSetSetterWithPrimitiveArray() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Set\">"
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Set\">"
|
||||||
+ INT_ARRAY_XML + "</Set></Configure>");
|
+ INT_ARRAY_XML + "</Set></Configure>");
|
||||||
TestConfiguration tc = new TestConfiguration();
|
TestConfiguration tc = new TestConfiguration();
|
||||||
assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue()));
|
assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue()));
|
||||||
|
@ -409,7 +426,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testMap() throws Exception
|
public void testMap() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
|
||||||
" <Set name=\"map\">" +
|
" <Set name=\"map\">" +
|
||||||
" <Map>" +
|
" <Map>" +
|
||||||
|
@ -433,7 +450,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorNamedInjection() throws Exception
|
public void testConstructorNamedInjection() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
||||||
" <Arg>arg1</Arg> " +
|
" <Arg>arg1</Arg> " +
|
||||||
" <Arg>arg2</Arg> " +
|
" <Arg>arg2</Arg> " +
|
||||||
|
@ -450,7 +467,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorNamedInjectionOrdered() throws Exception
|
public void testConstructorNamedInjectionOrdered() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
||||||
" <Arg name=\"first\">arg1</Arg> " +
|
" <Arg name=\"first\">arg1</Arg> " +
|
||||||
" <Arg name=\"second\">arg2</Arg> " +
|
" <Arg name=\"second\">arg2</Arg> " +
|
||||||
|
@ -467,7 +484,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorNamedInjectionUnOrdered() throws Exception
|
public void testConstructorNamedInjectionUnOrdered() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
||||||
" <Arg name=\"first\">arg1</Arg> " +
|
" <Arg name=\"first\">arg1</Arg> " +
|
||||||
" <Arg name=\"third\">arg3</Arg> " +
|
" <Arg name=\"third\">arg3</Arg> " +
|
||||||
|
@ -484,7 +501,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorNamedInjectionOrderedMixed() throws Exception
|
public void testConstructorNamedInjectionOrderedMixed() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
||||||
" <Arg name=\"first\">arg1</Arg> " +
|
" <Arg name=\"first\">arg1</Arg> " +
|
||||||
" <Arg>arg2</Arg> " +
|
" <Arg>arg2</Arg> " +
|
||||||
|
@ -501,7 +518,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorNamedInjectionUnorderedMixed() throws Exception
|
public void testConstructorNamedInjectionUnorderedMixed() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
||||||
" <Arg name=\"third\">arg3</Arg> " +
|
" <Arg name=\"third\">arg3</Arg> " +
|
||||||
" <Arg>arg2</Arg> " +
|
" <Arg>arg2</Arg> " +
|
||||||
|
@ -518,7 +535,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testNestedConstructorNamedInjection() throws Exception
|
public void testNestedConstructorNamedInjection() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
||||||
" <Arg>arg1</Arg> " +
|
" <Arg>arg1</Arg> " +
|
||||||
" <Arg>arg2</Arg> " +
|
" <Arg>arg2</Arg> " +
|
||||||
|
@ -546,7 +563,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testNestedConstructorNamedInjectionOrdered() throws Exception
|
public void testNestedConstructorNamedInjectionOrdered() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
||||||
" <Arg name=\"first\">arg1</Arg> " +
|
" <Arg name=\"first\">arg1</Arg> " +
|
||||||
" <Arg name=\"second\">arg2</Arg> " +
|
" <Arg name=\"second\">arg2</Arg> " +
|
||||||
|
@ -573,7 +590,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testNestedConstructorNamedInjectionUnOrdered() throws Exception
|
public void testNestedConstructorNamedInjectionUnOrdered() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
||||||
" <Arg name=\"first\">arg1</Arg> " +
|
" <Arg name=\"first\">arg1</Arg> " +
|
||||||
" <Arg name=\"third\">arg3</Arg> " +
|
" <Arg name=\"third\">arg3</Arg> " +
|
||||||
|
@ -600,7 +617,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testNestedConstructorNamedInjectionOrderedMixed() throws Exception
|
public void testNestedConstructorNamedInjectionOrderedMixed() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
||||||
" <Arg name=\"first\">arg1</Arg> " +
|
" <Arg name=\"first\">arg1</Arg> " +
|
||||||
" <Arg>arg2</Arg> " +
|
" <Arg>arg2</Arg> " +
|
||||||
|
@ -627,7 +644,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testArgumentsGetIgnoredMissingDTD() throws Exception
|
public void testArgumentsGetIgnoredMissingDTD() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(new ByteArrayInputStream(("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
||||||
" <Arg>arg1</Arg> " +
|
" <Arg>arg1</Arg> " +
|
||||||
" <Arg>arg2</Arg> " +
|
" <Arg>arg2</Arg> " +
|
||||||
|
@ -639,8 +656,7 @@ public class XmlConfigurationTest
|
||||||
" <Arg>arg3</Arg>\n" +
|
" <Arg>arg3</Arg>\n" +
|
||||||
" </New>" +
|
" </New>" +
|
||||||
" </Set>" +
|
" </Set>" +
|
||||||
"</Configure>").getBytes(StandardCharsets.ISO_8859_1)));
|
"</Configure>");
|
||||||
// XmlConfiguration xmlConfiguration = new XmlConfiguration(url);
|
|
||||||
|
|
||||||
AnnotatedTestConfiguration atc = (AnnotatedTestConfiguration)xmlConfiguration.configure();
|
AnnotatedTestConfiguration atc = (AnnotatedTestConfiguration)xmlConfiguration.configure();
|
||||||
|
|
||||||
|
@ -655,7 +671,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testSetGetIgnoredMissingDTD() throws Exception
|
public void testSetGetIgnoredMissingDTD() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(new ByteArrayInputStream(("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
||||||
" <Set name=\"first\">arg1</Set> " +
|
" <Set name=\"first\">arg1</Set> " +
|
||||||
" <Set name=\"second\">arg2</Set> " +
|
" <Set name=\"second\">arg2</Set> " +
|
||||||
|
@ -667,8 +683,7 @@ public class XmlConfigurationTest
|
||||||
" <Set name=\"third\">arg3</Set> " +
|
" <Set name=\"third\">arg3</Set> " +
|
||||||
" </New>" +
|
" </New>" +
|
||||||
" </Set>" +
|
" </Set>" +
|
||||||
"</Configure>").getBytes(StandardCharsets.UTF_8)));
|
"</Configure>");
|
||||||
// XmlConfiguration xmlConfiguration = new XmlConfiguration(url);
|
|
||||||
|
|
||||||
DefaultTestConfiguration atc = (DefaultTestConfiguration)xmlConfiguration.configure();
|
DefaultTestConfiguration atc = (DefaultTestConfiguration)xmlConfiguration.configure();
|
||||||
|
|
||||||
|
@ -683,7 +698,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testNestedConstructorNamedInjectionUnorderedMixed() throws Exception
|
public void testNestedConstructorNamedInjectionUnorderedMixed() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
|
||||||
" <Arg name=\"third\">arg3</Arg> " +
|
" <Arg name=\"third\">arg3</Arg> " +
|
||||||
" <Arg>arg2</Arg> " +
|
" <Arg>arg2</Arg> " +
|
||||||
|
@ -748,7 +763,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testSetBooleanTrue() throws Exception
|
public void testSetBooleanTrue() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
||||||
" <Set name=\"boolean\">true</Set>" +
|
" <Set name=\"boolean\">true</Set>" +
|
||||||
"</Configure>");
|
"</Configure>");
|
||||||
|
@ -760,7 +775,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testSetBooleanFalse() throws Exception
|
public void testSetBooleanFalse() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
||||||
" <Set name=\"boolean\">false</Set>" +
|
" <Set name=\"boolean\">false</Set>" +
|
||||||
"</Configure>");
|
"</Configure>");
|
||||||
|
@ -773,7 +788,7 @@ public class XmlConfigurationTest
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testSetBadBoolean() throws Exception
|
public void testSetBadBoolean() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
||||||
" <Set name=\"boolean\">tru</Set>" +
|
" <Set name=\"boolean\">tru</Set>" +
|
||||||
"</Configure>");
|
"</Configure>");
|
||||||
|
@ -785,7 +800,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testSetBadInteger() throws Exception
|
public void testSetBadInteger() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
||||||
" <Set name=\"integer\">bad</Set>" +
|
" <Set name=\"integer\">bad</Set>" +
|
||||||
"</Configure>");
|
"</Configure>");
|
||||||
|
@ -798,7 +813,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testSetBadExtraInteger() throws Exception
|
public void testSetBadExtraInteger() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
||||||
" <Set name=\"integer\">100 bas</Set>" +
|
" <Set name=\"integer\">100 bas</Set>" +
|
||||||
"</Configure>");
|
"</Configure>");
|
||||||
|
@ -811,7 +826,7 @@ public class XmlConfigurationTest
|
||||||
@Test
|
@Test
|
||||||
public void testSetBadFloatInteger() throws Exception
|
public void testSetBadFloatInteger() throws Exception
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
|
||||||
" <Set name=\"integer\">1.5</Set>" +
|
" <Set name=\"integer\">1.5</Set>" +
|
||||||
"</Configure>");
|
"</Configure>");
|
||||||
|
@ -826,7 +841,7 @@ public class XmlConfigurationTest
|
||||||
{
|
{
|
||||||
// No properties
|
// No properties
|
||||||
String defolt = "baz";
|
String defolt = "baz";
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
||||||
" <Set name=\"first\"><Property name=\"wibble\" deprecated=\"foo,bar\" default=\"" + defolt + "\"/></Set> " +
|
" <Set name=\"first\"><Property name=\"wibble\" deprecated=\"foo,bar\" default=\"" + defolt + "\"/></Set> " +
|
||||||
"</Configure>");
|
"</Configure>");
|
||||||
|
@ -839,7 +854,7 @@ public class XmlConfigurationTest
|
||||||
{
|
{
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
String value = "foo";
|
String value = "foo";
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
||||||
" <Set name=\"first\"><Property name=\"" + name + "\" deprecated=\"other,bar\" default=\"baz\"/></Set> " +
|
" <Set name=\"first\"><Property name=\"" + name + "\" deprecated=\"other,bar\" default=\"baz\"/></Set> " +
|
||||||
"</Configure>");
|
"</Configure>");
|
||||||
|
@ -853,7 +868,7 @@ public class XmlConfigurationTest
|
||||||
{
|
{
|
||||||
String name = "bar";
|
String name = "bar";
|
||||||
String value = "bar";
|
String value = "bar";
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
||||||
" <Set name=\"first\"><Property name=\"foo\" deprecated=\"" + name + "\" default=\"baz\"/></Set> " +
|
" <Set name=\"first\"><Property name=\"foo\" deprecated=\"" + name + "\" default=\"baz\"/></Set> " +
|
||||||
"</Configure>");
|
"</Configure>");
|
||||||
|
@ -867,7 +882,7 @@ public class XmlConfigurationTest
|
||||||
{
|
{
|
||||||
String name = "bar";
|
String name = "bar";
|
||||||
String value = "bar";
|
String value = "bar";
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
||||||
" <Set name=\"first\"><Property name=\"foo\" deprecated=\"other," + name + "\" default=\"baz\"/></Set> " +
|
" <Set name=\"first\"><Property name=\"foo\" deprecated=\"other," + name + "\" default=\"baz\"/></Set> " +
|
||||||
"</Configure>");
|
"</Configure>");
|
||||||
|
@ -881,7 +896,7 @@ public class XmlConfigurationTest
|
||||||
{
|
{
|
||||||
String name = "bar";
|
String name = "bar";
|
||||||
String value = "bar";
|
String value = "bar";
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
||||||
" <Set name=\"first\">" +
|
" <Set name=\"first\">" +
|
||||||
" <Property> " +
|
" <Property> " +
|
||||||
|
@ -904,7 +919,7 @@ public class XmlConfigurationTest
|
||||||
String value = "bar";
|
String value = "bar";
|
||||||
String defaultValue = "_<Property name=\"bar\"/>_<Property name=\"bar\"/>_";
|
String defaultValue = "_<Property name=\"bar\"/>_<Property name=\"bar\"/>_";
|
||||||
String expectedValue = "_" + value + "_" + value + "_";
|
String expectedValue = "_" + value + "_" + value + "_";
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
||||||
" <Set name=\"first\">" +
|
" <Set name=\"first\">" +
|
||||||
" <Property>" +
|
" <Property>" +
|
||||||
|
@ -922,7 +937,7 @@ public class XmlConfigurationTest
|
||||||
public void testPropertyNotFoundWithPropertyInDefaultValueNotFoundWithDefault() throws Exception
|
public void testPropertyNotFoundWithPropertyInDefaultValueNotFoundWithDefault() throws Exception
|
||||||
{
|
{
|
||||||
String value = "bar";
|
String value = "bar";
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
|
||||||
" <Set name=\"first\">" +
|
" <Set name=\"first\">" +
|
||||||
" <Property name=\"not_found\">" +
|
" <Property name=\"not_found\">" +
|
||||||
|
@ -945,7 +960,7 @@ public class XmlConfigurationTest
|
||||||
for(String propName: propNames)
|
for(String propName: propNames)
|
||||||
{
|
{
|
||||||
XmlConfiguration configuration =
|
XmlConfiguration configuration =
|
||||||
new XmlConfiguration("" +
|
asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
|
||||||
" <Set name=\"TestString\">" +
|
" <Set name=\"TestString\">" +
|
||||||
" <Property name=\"" + propName + "\"/>" +
|
" <Property name=\"" + propName + "\"/>" +
|
||||||
|
@ -973,7 +988,7 @@ public class XmlConfigurationTest
|
||||||
for(String propName: propNames)
|
for(String propName: propNames)
|
||||||
{
|
{
|
||||||
XmlConfiguration configuration =
|
XmlConfiguration configuration =
|
||||||
new XmlConfiguration("" +
|
asXmlConfiguration("" +
|
||||||
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
|
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
|
||||||
" <Set name=\"TestString\">" +
|
" <Set name=\"TestString\">" +
|
||||||
" <Property name=\"" + propName + "\"/>" +
|
" <Property name=\"" + propName + "\"/>" +
|
||||||
|
@ -994,7 +1009,7 @@ public class XmlConfigurationTest
|
||||||
public void testDeprecated() throws Exception
|
public void testDeprecated() throws Exception
|
||||||
{
|
{
|
||||||
Class<?> testClass = AnnotatedTestConfiguration.class;
|
Class<?> testClass = AnnotatedTestConfiguration.class;
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
|
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
|
||||||
"<Configure class=\"" + testClass.getName() + "\">" +
|
"<Configure class=\"" + testClass.getName() + "\">" +
|
||||||
" <Set name=\"deprecated\">foo</Set>" +
|
" <Set name=\"deprecated\">foo</Set>" +
|
||||||
" <Set name=\"obsolete\">" +
|
" <Set name=\"obsolete\">" +
|
||||||
|
|
Loading…
Reference in New Issue