Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2013-06-03 18:31:07 +0000
committerJoakim Erdfelt2013-06-03 18:34:38 +0000
commit670b6a964cf637e4de2045213ff3116bff245f77 (patch)
treef077b37e1a35de17328821af2969fea6f9fb60af /jetty-xml
parent8b39cbe5bf2edef6cbd8374e37bfa484eaa6d92f (diff)
downloadorg.eclipse.jetty.project-670b6a964cf637e4de2045213ff3116bff245f77.tar.gz
org.eclipse.jetty.project-670b6a964cf637e4de2045213ff3116bff245f77.tar.xz
org.eclipse.jetty.project-670b6a964cf637e4de2045213ff3116bff245f77.zip
408945 XML Args ignored without DTD
+ Semi-reverting prior commit as it broke with DTD use + Fixing up logic to allow for <Arg> <Set> <Call> with and without DTD + Adding testcase that uses default constructor with <Set> calls to setup a class
Diffstat (limited to 'jetty-xml')
-rw-r--r--jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java43
-rw-r--r--jetty-xml/src/test/java/org/eclipse/jetty/xml/DefaultTestConfiguration.java74
-rw-r--r--jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java36
3 files changed, 129 insertions, 24 deletions
diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java
index fc79853691..f68a308b3a 100644
--- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java
+++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java
@@ -742,37 +742,40 @@ public class XmlConfiguration
{
Class<?> oClass = nodeClass(node);
int argIndex = node.size();
- for (int i = 0; i < node.size(); i++)
- {
- Object o = node.get(i);
- if (o instanceof String)
- continue;
- if (!((XmlParser.Node)o).getTag().equals("Arg"))
- {
- argIndex = i;
- break;
- }
- }
-
+
Map<String, Object> namedArgMap = new HashMap<>();
List<Object> arguments = new LinkedList<>();
+ XmlParser.Node child;
+ // Find the <Arg> elements
for (int i = 0; i < node.size(); i++)
{
Object o = node.get(i);
-
if (o instanceof String)
{
+ // Skip raw String nodes
continue;
}
- XmlParser.Node argNode = (XmlParser.Node)o;
-
- String namedAttribute = argNode.getAttribute("name");
- Object value=value(obj,(XmlParser.Node)o);
- if (namedAttribute != null)
- namedArgMap.put(namedAttribute,value);
- arguments.add(value);
+ child = (XmlParser.Node)o;
+ if(child.getTag().equals("Arg"))
+ {
+ String namedAttribute = child.getAttribute("name");
+ Object value=value(obj,child);
+ if (namedAttribute != null)
+ {
+ // named arguments
+ namedArgMap.put(namedAttribute,value);
+ }
+ // raw arguments
+ arguments.add(value);
+ } else {
+ // The first non <Arg> child is the start of
+ // elements that configure the class, such as
+ // <Set> and <Call> nodes
+ argIndex = i;
+ break;
+ }
}
if (LOG.isDebugEnabled())
diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/DefaultTestConfiguration.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/DefaultTestConfiguration.java
new file mode 100644
index 0000000000..40c0927b89
--- /dev/null
+++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/DefaultTestConfiguration.java
@@ -0,0 +1,74 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.xml;
+
+public class DefaultTestConfiguration
+{
+ private String first;
+ private String second;
+ private String third;
+
+ DefaultTestConfiguration nested;
+
+ public DefaultTestConfiguration()
+ {
+ /* default constructor */
+ }
+
+ public String getFirst()
+ {
+ return first;
+ }
+
+ public void setFirst(String first)
+ {
+ this.first = first;
+ }
+
+ public String getSecond()
+ {
+ return second;
+ }
+
+ public void setSecond(String second)
+ {
+ this.second = second;
+ }
+
+ public String getThird()
+ {
+ return third;
+ }
+
+ public void setThird(String third)
+ {
+ this.third = third;
+ }
+
+ public DefaultTestConfiguration getNested()
+ {
+ return nested;
+ }
+
+ public void setNested(DefaultTestConfiguration nested)
+ {
+ this.nested = nested;
+ }
+
+}
diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java
index 22267cfdd4..f4b76f1fca 100644
--- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java
+++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java
@@ -552,10 +552,10 @@ public class XmlConfigurationTest
" <Arg>arg2</Arg> " +
" <Arg>arg3</Arg> " +
" <Set name=\"nested\"> " +
- " <New class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">\n" +
- " <Arg>arg1</Arg>\n" +
- " <Arg>arg2</Arg>\n" +
- " <Arg>arg3</Arg>\n" +
+ " <New class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">\n" +
+ " <Arg>arg1</Arg>\n" +
+ " <Arg>arg2</Arg>\n" +
+ " <Arg>arg3</Arg>\n" +
" </New>" +
" </Set>" +
"</Configure>").getBytes("ISO-8859-1")));
@@ -572,6 +572,34 @@ public class XmlConfigurationTest
}
@Test
+ public void testSetGetIgnoredMissingDTD() throws Exception
+ {
+ XmlConfiguration xmlConfiguration = new XmlConfiguration(new ByteArrayInputStream(("" +
+ "<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
+ " <Set name=\"first\">arg1</Set> " +
+ " <Set name=\"second\">arg2</Set> " +
+ " <Set name=\"third\">arg3</Set> " +
+ " <Set name=\"nested\"> " +
+ " <New class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">\n" +
+ " <Set name=\"first\">arg1</Set> " +
+ " <Set name=\"second\">arg2</Set> " +
+ " <Set name=\"third\">arg3</Set> " +
+ " </New>" +
+ " </Set>" +
+ "</Configure>").getBytes("ISO-8859-1")));
+// XmlConfiguration xmlConfiguration = new XmlConfiguration(url);
+
+ DefaultTestConfiguration atc = (DefaultTestConfiguration)xmlConfiguration.configure();
+
+ Assert.assertEquals("first parameter not wired correctly","arg1", atc.getFirst());
+ Assert.assertEquals("second parameter not wired correctly","arg2", atc.getSecond());
+ Assert.assertEquals("third parameter not wired correctly","arg3", atc.getThird());
+ Assert.assertEquals("nested first parameter not wired correctly","arg1", atc.getNested().getFirst());
+ Assert.assertEquals("nested second parameter not wired correctly","arg2", atc.getNested().getSecond());
+ Assert.assertEquals("nested third parameter not wired correctly","arg3", atc.getNested().getThird());
+ }
+
+ @Test
public void testNestedConstructorNamedInjectionUnorderedMixed() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +

Back to the top