Merge branch 'jetty-9.4.x' of github.com:eclipse/jetty.project into jetty-9.4.x

This commit is contained in:
Joakim Erdfelt 2019-06-10 11:10:08 -05:00
commit da4f116c63
9 changed files with 195 additions and 102 deletions

View File

@ -36,9 +36,8 @@ public class FileServerXml
{
public static void main( String[] args ) throws Exception
{
Resource fileserverXml = Resource.newSystemResource("fileserver.xml");
XmlConfiguration configuration = new XmlConfiguration(
fileserverXml.getInputStream());
Resource fileServerXml = Resource.newSystemResource("fileserver.xml");
XmlConfiguration configuration = new XmlConfiguration(fileServerXml);
Server server = (Server) configuration.configure();
server.start();
server.join();

View File

@ -91,7 +91,7 @@ public class GlobalWebappConfigBinding implements AppLifeCycle.Binding
if (globalContextSettings.exists())
{
XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream());
XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings);
Resource resource = Resource.newResource(app.getOriginId());
app.getDeploymentManager().scope(jettyXmlConfig,resource);
jettyXmlConfig.configure(context);

View File

@ -160,7 +160,7 @@ public abstract class AbstractContextProvider extends AbstractLifeCycle implemen
{
Thread.currentThread().setContextClassLoader(classLoader);
XmlConfiguration xmlConfiguration = new XmlConfiguration(res.getInputStream());
XmlConfiguration xmlConfiguration = new XmlConfiguration(res);
HashMap properties = new HashMap();
//put the server instance in
properties.put("Server", getServerInstanceWrapper().getServer());

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.osgi.boot.internal.serverfactory;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
@ -142,10 +141,10 @@ public class ServerInstanceWrapper
for (URL jettyConfiguration : jettyConfigurations)
{
try(InputStream in = jettyConfiguration.openStream())
try
{
// Execute a Jetty configuration file
XmlConfiguration config = new XmlConfiguration(in);
XmlConfiguration config = new XmlConfiguration(jettyConfiguration);
config.getIdMap().putAll(id_map);
config.getProperties().putAll(properties);

View File

@ -69,18 +69,32 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
private String _main;
@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
{
_configuration = configuration;
Resource resource = url != null
? new UrlResource(url)
: 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));
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()
{
@ -92,7 +106,7 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
}
};
new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(resource);
new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(springResource);
}
catch (Exception e)
{

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.websocket.client;
import java.io.InputStream;
import java.net.URL;
import org.eclipse.jetty.client.HttpClient;
@ -36,9 +35,9 @@ class XmlBasedHttpClientProvider
return null;
}
try (InputStream in = resource.openStream())
try
{
XmlConfiguration configuration = new XmlConfiguration(in);
XmlConfiguration configuration = new XmlConfiguration(resource);
return (HttpClient) configuration.configure();
}
catch (Throwable t)

View File

@ -18,8 +18,11 @@
package org.eclipse.jetty.xml;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.jetty.util.resource.Resource;
/**
* A ConfigurationProcessor for non XmlConfiguration format files.
* <p>
@ -31,8 +34,33 @@ import java.net.URL;
*/
public interface ConfigurationProcessor
{
public void init(URL url, XmlParser.Node root, XmlConfiguration configuration);
public Object configure( Object obj) throws Exception;
public Object configure() throws Exception;
/**
* @deprecated use {@link #init(Resource, XmlParser.Node, XmlConfiguration)} instead
*/
@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;
}

View File

@ -176,25 +176,42 @@ public class XmlConfiguration
private final Map<String, Object> _idMap = new HashMap<>();
private final Map<String, String> _propertyMap = new HashMap<>();
private final URL _url;
private final Resource _location;
private final String _dtd;
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.
*
* @param configuration the URL of the XML configuration
* @throws IOException if the configuration could not be read
* @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
{
synchronized (__parser)
{
_url = configuration;
setConfig(__parser.parse(configuration.toString()));
_dtd = __parser.getDTD();
}
this(Resource.newResource(configuration));
}
/**
@ -204,17 +221,23 @@ public class XmlConfiguration
* The String should start with a "&lt;Configure ....&gt;" element.
* @throws IOException if the configuration could not be read
* @throws SAXException if the configuration could not be parsed
* @deprecated use Constructor which has location information
*/
@Deprecated
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;
InputSource source = new InputSource(new StringReader(configuration));
synchronized (__parser)
try (StringReader reader = new StringReader(configuration))
{
_url = null;
setConfig(__parser.parse(source));
_dtd = __parser.getDTD();
InputSource source = new InputSource(reader);
synchronized (__parser)
{
_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
* @throws IOException if the configuration could not be read
* @throws SAXException if the configuration could not be parsed
* @deprecated use Constructor which has location information
*/
@Deprecated
public XmlConfiguration(InputStream configuration) throws SAXException, IOException
{
InputSource source = new InputSource(configuration);
synchronized (__parser)
{
_url = null;
_location = null;
setConfig(__parser.parse(source));
_dtd = __parser.getDTD();
}
}
@Override
public String toString()
{
if (_location == null)
{
return "UNKNOWN-LOCATION";
}
return _location.toString();
}
private void setConfig(XmlParser.Node config)
{
if ("Configure".equals(config.getTag()))
@ -257,7 +292,7 @@ public class XmlConfiguration
{
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 String _url;
XmlParser.Node _root;
XmlConfiguration _configuration;
@Override
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;
_configuration = configuration;
}
@ -352,7 +391,7 @@ public class XmlConfiguration
if (oClass != null && !oClass.isInstance(obj))
{
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");
if (id != null)
@ -404,7 +443,7 @@ public class XmlConfiguration
}
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)
@ -496,12 +535,12 @@ public class XmlConfiguration
envObj(node);
break;
default:
throw new IllegalStateException("Unknown tag: " + tag + " in " + _url);
throw new IllegalStateException("Unknown tag: " + tag + " in " + _configuration);
}
}
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;
}
}
@ -677,7 +716,7 @@ public class XmlConfiguration
{
Object result = constructor.newInstance(args);
if (constructor.getAnnotation(Deprecated.class) != null)
LOG.warn("Deprecated constructor {} in {}", constructor, _url);
LOG.warn("Deprecated constructor {} in {}", constructor, _configuration);
return result;
}
@ -685,7 +724,7 @@ public class XmlConfiguration
{
Object result = method.invoke(obj, args);
if (method.getAnnotation(Deprecated.class) != null)
LOG.warn("Deprecated method {} in {}", method, _url);
LOG.warn("Deprecated method {} in {}", method, _configuration);
return result;
}
@ -693,7 +732,7 @@ public class XmlConfiguration
{
Object result = field.get(object);
if (field.getAnnotation(Deprecated.class) != null)
LOG.warn("Deprecated field {} in {}", field, _url);
LOG.warn("Deprecated field {} in {}", field, _configuration);
return result;
}
@ -701,7 +740,7 @@ public class XmlConfiguration
{
field.set(obj, arg);
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))
return envObj(node);
LOG.warn("Unknown value tag: " + node, new Throwable());
LOG.warn("Unknown value tag: " + node + " in " + _configuration, new Throwable());
return null;
}

View File

@ -18,12 +18,14 @@
package org.eclipse.jetty.xml;
import java.io.ByteArrayInputStream;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
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.HashMap;
import java.util.List;
@ -31,12 +33,18 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
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.Logger;
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.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.Matchers.containsString;
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.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class XmlConfigurationTest
{
public WorkDir workDir;
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>";
@ -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
public void testGetClass() throws Exception
{
XmlConfiguration configuration =
new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\"><Get name=\"class\"/></Set></Configure>");
XmlConfiguration configuration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\"><Get name=\"class\"/></Set></Configure>");
TestConfiguration tc = new TestConfiguration();
configuration.configure(tc);
assertEquals(TestConfiguration.class,tc.testObject);
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);
assertEquals(String.class,tc.testObject);
assertEquals("String",configuration.getIdMap().get("simple"));
@ -253,8 +272,7 @@ public class XmlConfigurationTest
@Test
public void testStringConfiguration() throws Exception
{
XmlConfiguration configuration =
new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\">SetValue</Set><Set name=\"Test\" type=\"int\">2</Set></Configure>");
XmlConfiguration configuration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\">SetValue</Set><Set name=\"Test\" type=\"int\">2</Set></Configure>");
TestConfiguration tc = new TestConfiguration();
configuration.configure(tc);
assertEquals("SetValue", tc.testObject, "Set String 3");
@ -264,8 +282,7 @@ public class XmlConfigurationTest
@Test
public void testMeaningfullSetException() throws Exception
{
XmlConfiguration configuration =
new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"PropertyTest\"><Property name=\"null\"/></Set></Configure>");
XmlConfiguration configuration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"PropertyTest\"><Property name=\"null\"/></Set></Configure>");
TestConfiguration tc = new TestConfiguration();
NoSuchMethodException e = assertThrows(NoSuchMethodException.class, () -> {
@ -278,7 +295,7 @@ public class XmlConfigurationTest
@Test
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\">"
+ STRING_ARRAY_XML + "</Arg></New></Set></Configure>");
TestConfiguration tc = new TestConfiguration();
@ -291,7 +308,7 @@ public class XmlConfigurationTest
@Test
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\">"
+ "<Arg type=\"List\">" + STRING_ARRAY_XML + "</Arg>"
+ "<Arg type=\"List\">" + STRING_ARRAY_XML + "</Arg>"
@ -306,7 +323,7 @@ public class XmlConfigurationTest
@Test
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>");
TestConfiguration tc = new TestConfiguration();
@ -318,7 +335,7 @@ public class XmlConfigurationTest
@Test
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\">"
+ STRING_ARRAY_XML + "</Arg></New></Set></Configure>");
TestConfiguration tc = new TestConfiguration();
@ -331,7 +348,7 @@ public class XmlConfigurationTest
@Test
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>");
TestConfiguration tc = new TestConfiguration();
assertThrows(IllegalArgumentException.class, ()->{
@ -342,7 +359,7 @@ public class XmlConfigurationTest
@Test
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>");
TestConfiguration tc = new TestConfiguration();
assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue()));
@ -353,7 +370,7 @@ public class XmlConfigurationTest
@Test
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>");
TestConfiguration tc = new TestConfiguration();
assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue()));
@ -364,7 +381,7 @@ public class XmlConfigurationTest
@Test
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>");
TestConfiguration tc = new TestConfiguration();
assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue()));
@ -376,7 +393,7 @@ public class XmlConfigurationTest
@Test
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>");
TestConfiguration tc = new TestConfiguration();
assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue()));
@ -387,7 +404,7 @@ public class XmlConfigurationTest
@Test
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>");
TestConfiguration tc = new TestConfiguration();
assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue()));
@ -398,7 +415,7 @@ public class XmlConfigurationTest
@Test
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>");
TestConfiguration tc = new TestConfiguration();
assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue()));
@ -409,7 +426,7 @@ public class XmlConfigurationTest
@Test
public void testMap() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
" <Set name=\"map\">" +
" <Map>" +
@ -433,7 +450,7 @@ public class XmlConfigurationTest
@Test
public void testConstructorNamedInjection() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg>arg1</Arg> " +
" <Arg>arg2</Arg> " +
@ -450,7 +467,7 @@ public class XmlConfigurationTest
@Test
public void testConstructorNamedInjectionOrdered() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " +
" <Arg name=\"second\">arg2</Arg> " +
@ -467,7 +484,7 @@ public class XmlConfigurationTest
@Test
public void testConstructorNamedInjectionUnOrdered() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " +
" <Arg name=\"third\">arg3</Arg> " +
@ -484,7 +501,7 @@ public class XmlConfigurationTest
@Test
public void testConstructorNamedInjectionOrderedMixed() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " +
" <Arg>arg2</Arg> " +
@ -501,7 +518,7 @@ public class XmlConfigurationTest
@Test
public void testConstructorNamedInjectionUnorderedMixed() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"third\">arg3</Arg> " +
" <Arg>arg2</Arg> " +
@ -518,7 +535,7 @@ public class XmlConfigurationTest
@Test
public void testNestedConstructorNamedInjection() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg>arg1</Arg> " +
" <Arg>arg2</Arg> " +
@ -546,7 +563,7 @@ public class XmlConfigurationTest
@Test
public void testNestedConstructorNamedInjectionOrdered() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " +
" <Arg name=\"second\">arg2</Arg> " +
@ -573,7 +590,7 @@ public class XmlConfigurationTest
@Test
public void testNestedConstructorNamedInjectionUnOrdered() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " +
" <Arg name=\"third\">arg3</Arg> " +
@ -600,7 +617,7 @@ public class XmlConfigurationTest
@Test
public void testNestedConstructorNamedInjectionOrderedMixed() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " +
" <Arg>arg2</Arg> " +
@ -627,7 +644,7 @@ public class XmlConfigurationTest
@Test
public void testArgumentsGetIgnoredMissingDTD() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration(new ByteArrayInputStream(("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg>arg1</Arg> " +
" <Arg>arg2</Arg> " +
@ -639,8 +656,7 @@ public class XmlConfigurationTest
" <Arg>arg3</Arg>\n" +
" </New>" +
" </Set>" +
"</Configure>").getBytes(StandardCharsets.ISO_8859_1)));
// XmlConfiguration xmlConfiguration = new XmlConfiguration(url);
"</Configure>");
AnnotatedTestConfiguration atc = (AnnotatedTestConfiguration)xmlConfiguration.configure();
@ -655,7 +671,7 @@ public class XmlConfigurationTest
@Test
public void testSetGetIgnoredMissingDTD() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration(new ByteArrayInputStream(("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\">arg1</Set> " +
" <Set name=\"second\">arg2</Set> " +
@ -667,8 +683,7 @@ public class XmlConfigurationTest
" <Set name=\"third\">arg3</Set> " +
" </New>" +
" </Set>" +
"</Configure>").getBytes(StandardCharsets.UTF_8)));
// XmlConfiguration xmlConfiguration = new XmlConfiguration(url);
"</Configure>");
DefaultTestConfiguration atc = (DefaultTestConfiguration)xmlConfiguration.configure();
@ -683,7 +698,7 @@ public class XmlConfigurationTest
@Test
public void testNestedConstructorNamedInjectionUnorderedMixed() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"third\">arg3</Arg> " +
" <Arg>arg2</Arg> " +
@ -748,7 +763,7 @@ public class XmlConfigurationTest
@Test
public void testSetBooleanTrue() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"boolean\">true</Set>" +
"</Configure>");
@ -760,7 +775,7 @@ public class XmlConfigurationTest
@Test
public void testSetBooleanFalse() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"boolean\">false</Set>" +
"</Configure>");
@ -773,7 +788,7 @@ public class XmlConfigurationTest
@Disabled
public void testSetBadBoolean() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"boolean\">tru</Set>" +
"</Configure>");
@ -785,7 +800,7 @@ public class XmlConfigurationTest
@Test
public void testSetBadInteger() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"integer\">bad</Set>" +
"</Configure>");
@ -798,7 +813,7 @@ public class XmlConfigurationTest
@Test
public void testSetBadExtraInteger() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"integer\">100 bas</Set>" +
"</Configure>");
@ -811,7 +826,7 @@ public class XmlConfigurationTest
@Test
public void testSetBadFloatInteger() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"integer\">1.5</Set>" +
"</Configure>");
@ -826,7 +841,7 @@ public class XmlConfigurationTest
{
// No properties
String defolt = "baz";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\"><Property name=\"wibble\" deprecated=\"foo,bar\" default=\"" + defolt + "\"/></Set> " +
"</Configure>");
@ -839,7 +854,7 @@ public class XmlConfigurationTest
{
String name = "foo";
String value = "foo";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\"><Property name=\"" + name + "\" deprecated=\"other,bar\" default=\"baz\"/></Set> " +
"</Configure>");
@ -853,7 +868,7 @@ public class XmlConfigurationTest
{
String name = "bar";
String value = "bar";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\"><Property name=\"foo\" deprecated=\"" + name + "\" default=\"baz\"/></Set> " +
"</Configure>");
@ -867,7 +882,7 @@ public class XmlConfigurationTest
{
String name = "bar";
String value = "bar";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\"><Property name=\"foo\" deprecated=\"other," + name + "\" default=\"baz\"/></Set> " +
"</Configure>");
@ -881,7 +896,7 @@ public class XmlConfigurationTest
{
String name = "bar";
String value = "bar";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\">" +
" <Property> " +
@ -904,7 +919,7 @@ public class XmlConfigurationTest
String value = "bar";
String defaultValue = "_<Property name=\"bar\"/>_<Property name=\"bar\"/>_";
String expectedValue = "_" + value + "_" + value + "_";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\">" +
" <Property>" +
@ -922,7 +937,7 @@ public class XmlConfigurationTest
public void testPropertyNotFoundWithPropertyInDefaultValueNotFoundWithDefault() throws Exception
{
String value = "bar";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\">" +
" <Property name=\"not_found\">" +
@ -945,7 +960,7 @@ public class XmlConfigurationTest
for(String propName: propNames)
{
XmlConfiguration configuration =
new XmlConfiguration("" +
asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
" <Set name=\"TestString\">" +
" <Property name=\"" + propName + "\"/>" +
@ -973,7 +988,7 @@ public class XmlConfigurationTest
for(String propName: propNames)
{
XmlConfiguration configuration =
new XmlConfiguration("" +
asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
" <Set name=\"TestString\">" +
" <Property name=\"" + propName + "\"/>" +
@ -994,7 +1009,7 @@ public class XmlConfigurationTest
public void testDeprecated() throws Exception
{
Class<?> testClass = AnnotatedTestConfiguration.class;
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"" + testClass.getName() + "\">" +
" <Set name=\"deprecated\">foo</Set>" +
" <Set name=\"obsolete\">" +