included a script for handling the XML-RPC Validator (UserLand Software),

and debugged the handling of parameter serialization so that I think it
can actually pass now...
This commit is contained in:
Eric J. Bowersox
2002-01-17 02:52:22 +00:00
parent 70b7b826a0
commit fddeff906d
5 changed files with 291 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import org.apache.log4j.*;
import org.w3c.dom.*;
import com.silverwrist.util.*;
import com.silverwrist.venice.except.*;
@@ -33,6 +34,8 @@ public class XmlRpcRequest
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(XmlRpcRequest.class);
private static SimpleTimeZone utc = new SimpleTimeZone(0,"UTC");
/*--------------------------------------------------------------------------------
@@ -283,10 +286,14 @@ public class XmlRpcRequest
return parseStruct(type);
else if (name.equals("array"))
return parseArray(type);
else // no dice here
else
{ // no dice here
logger.error("inside a <value/> element: expected a valid type but got a <" + name + "/>");
throw new XmlRpcFault(XmlRpcFault.INVALID_REQUEST,
"invalid type element \"" + name + "\" specified inside a \"value\"");
} // end else
} // end if
else
{ // if there's no type-specific element, treat it as a string
@@ -304,7 +311,7 @@ public class XmlRpcRequest
{
XMLLoader loader = XMLLoader.get();
Element data = loader.postGetSubSection(val,"data");
NodeList nl = val.getChildNodes();
NodeList nl = data.getChildNodes();
ArrayList rc = new ArrayList();
for (int i=0; i<nl.getLength(); i++)
{ // look for <value/> elements within the <data/> element
@@ -312,8 +319,13 @@ public class XmlRpcRequest
if (n.getNodeType()==Node.ELEMENT_NODE)
{ // make sure we've got a value element here!
if (!(n.getNodeName().equals("value")))
{ // this is a bogus value!
logger.error("inside array <data/>: expected a <value/> but found a <" + n.getNodeName() + "/>");
throw new XmlRpcFault(XmlRpcFault.INVALID_REQUEST,
"non-value element found inside array \"data\" element");
} // end if
rc.add(parseValue((Element)n));
} // end if
@@ -342,8 +354,13 @@ public class XmlRpcRequest
if (n.getNodeType()==Node.ELEMENT_NODE)
{ // make sure we've got a value element here!
if (!(n.getNodeName().equals("member")))
{ // this is a bogus value
logger.error("inside <struct/>: expected a <member/> but found a <" + n.getNodeName() + "/>");
throw new XmlRpcFault(XmlRpcFault.INVALID_REQUEST,
"non-member element found inside \"struct\" element");
} // end if
DOMElementHelper h = new DOMElementHelper((Element)n);
String my_name = loader.postGetSubElementText(h,"name").trim();
Element my_val = loader.postGetSubSection(h,"value");
@@ -401,7 +418,7 @@ public class XmlRpcRequest
if (foo instanceof Double)
return "double";
if (foo instanceof Date)
return "dateTime.iso8601";
return "dateTime";
if (foo instanceof byte[])
return "base64";
if (foo instanceof Map)

View File

@@ -104,6 +104,30 @@ public class XmlRpcSerializer
public final String serialize(Object obj) throws XmlRpcFault
{
if (obj.getClass().isArray())
{ // treat arrays specially
Class ct = obj.getClass().getComponentType();
if (ct==Byte.TYPE)
return this.serialize((byte[])obj);
else if (ct==Boolean.TYPE)
return this.serialize((boolean[])obj);
else if (ct==Character.TYPE)
return this.serialize((char[])obj);
else if (ct==Short.TYPE)
return this.serialize((short[])obj);
else if (ct==Integer.TYPE)
return this.serialize((int[])obj);
else if (ct==Long.TYPE)
return this.serialize((long[])obj);
else if (ct==Float.TYPE)
return this.serialize((float[])obj);
else if (ct==Double.TYPE)
return this.serialize((double[])obj);
else
return this.serialize((Object[])obj);
} // end if
if (obj==null)
return serializeString(null);

View File

@@ -180,6 +180,27 @@ public class ScriptLibrary
} // end splitList
public final double toDouble(Object o) throws NumberFormatException
{
if ( (o instanceof Byte) || (o instanceof Short) || (o instanceof Integer) || (o instanceof Long)
|| (o instanceof Float) || (o instanceof Double))
return ((Number)o).doubleValue();
else
return Double.parseDouble(o.toString());
} // end toDouble
public final int toInteger(Object o) throws NumberFormatException
{
if ((o instanceof Byte) || (o instanceof Short) || (o instanceof Integer))
return ((Number)o).intValue();
else if (o instanceof Boolean)
return ((Boolean)o).booleanValue() ? 1 : 0;
else
return Integer.parseInt(o.toString());
} // end toInteger
public final boolean validVeniceID(String s)
{
return IDUtils.isValidVeniceID(s);