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:
parent
70b7b826a0
commit
fddeff906d
|
@ -277,6 +277,9 @@
|
|||
<!-- Configuration for the RPC interfaces. -->
|
||||
<rpc>
|
||||
<xmlrpc-methods>
|
||||
<!-- XML-RPC validation suite -->
|
||||
<method name="validator1\.[a-zA-Z]*"><script name="test/validation.js"/></method>
|
||||
|
||||
<method name="venice:test\.sumDifference">
|
||||
<!-- <object class="com.silverwrist.venice.ui.rpc.XmlRpcTestHandler"/> -->
|
||||
<script name="test/test1.js"/>
|
||||
|
|
223
rpcscripts/test/validation.js
Normal file
223
rpcscripts/test/validation.js
Normal file
|
@ -0,0 +1,223 @@
|
|||
// The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
// (the "License"); you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
// WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
// language governing rights and limitations under the License.
|
||||
//
|
||||
// The Original Code is the Venice Web Communities System.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
// Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
|
||||
// Implements the XML-RPC Validation Suite functions as documented by UserLand Software,
|
||||
// see http://www.xmlrpc.com/validator1Docs
|
||||
|
||||
importPackage(java.util);
|
||||
importPackage(Packages.com.silverwrist.venice.ui.rpc);
|
||||
|
||||
xreq = bsf.lookupBean("xmlrpc");
|
||||
|
||||
if ("validator1.arrayOfStructsTest"==xreq.method)
|
||||
{ // arrayOfStructsTest coming right up!
|
||||
if (xreq.paramCount!=1)
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
|
||||
else if ("array"!=xreq.getParamType(0))
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch"));
|
||||
else
|
||||
{ // The parameter is an array of structs containing at least three elements, named
|
||||
// "moe", "larry", and "curly", all of which are integers. We need to add up all
|
||||
// the "curly" elements and return the sum.
|
||||
parm = vlib.castList(xreq.getParam(0));
|
||||
accum = 0;
|
||||
it = parm.iterator();
|
||||
while (it.hasNext())
|
||||
{ // build the return value
|
||||
str = vlib.castMap(it.next());
|
||||
accum += vlib.toInteger(str.get("curly"));
|
||||
|
||||
} // end while
|
||||
|
||||
vlib.output(vlib.createInteger(accum));
|
||||
|
||||
} // end else
|
||||
|
||||
vlib.done();
|
||||
|
||||
} // end if
|
||||
|
||||
if ("validator1.countTheEntities"==xreq.method)
|
||||
{ // countTheEntities test coming right up!
|
||||
if (xreq.paramCount!=1)
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
|
||||
else if ("string"!=xreq.getParamType(0))
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch"));
|
||||
else
|
||||
{ // We get a string in which we're supposed to count the number of left angle brackets,
|
||||
// right angle brackets, ampersands, quotes, and apostrophes. We return that information
|
||||
// in a formatted structure.
|
||||
str = xreq.getParamString(0) + "";
|
||||
nleft = 0;
|
||||
nright = 0;
|
||||
namper = 0;
|
||||
napos = 0;
|
||||
nquot = 0;
|
||||
for (i=0; i<str.length; i++)
|
||||
{ // count the entities - note that we use ASCII codes to find the characters because
|
||||
// JavaScript doesn't do character constants all that well
|
||||
ch = str.charCodeAt(i);
|
||||
if (ch==60)
|
||||
nleft++;
|
||||
else if (ch==62)
|
||||
nright++;
|
||||
else if (ch==38)
|
||||
namper++;
|
||||
else if (ch==39)
|
||||
napos++;
|
||||
else if (ch==34)
|
||||
nquot++;
|
||||
|
||||
} // end for
|
||||
|
||||
// create the return value
|
||||
rc = vlib.createMap();
|
||||
rc.put("ctLeftAngleBrackets",vlib.createInteger(nleft));
|
||||
rc.put("ctRightAngleBrackets",vlib.createInteger(nright));
|
||||
rc.put("ctAmpersands",vlib.createInteger(namper));
|
||||
rc.put("ctApostrophes",vlib.createInteger(napos));
|
||||
rc.put("ctQuotes",vlib.createInteger(nquot));
|
||||
vlib.output(rc);
|
||||
|
||||
} // end else
|
||||
|
||||
vlib.done();
|
||||
|
||||
} // end if
|
||||
|
||||
if ("validator1.easyStructTest"==xreq.method)
|
||||
{ // easyStructTest test coming right up!
|
||||
if (xreq.paramCount!=1)
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
|
||||
else if ("struct"!=xreq.getParamType(0))
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch"));
|
||||
else
|
||||
{ // We get a struct, which has at least three fields, named "moe", "larry", and "curly",
|
||||
// all integers. We must add these and return the result.
|
||||
parm = vlib.castMap(xreq.getParam(0));
|
||||
val = vlib.toInteger(parm.get("moe")) + vlib.toInteger(parm.get("larry"))
|
||||
+ vlib.toInteger(parm.get("curly"));
|
||||
vlib.output(vlib.createInteger(val));
|
||||
|
||||
} // end else
|
||||
|
||||
vlib.done();
|
||||
|
||||
} // end if
|
||||
|
||||
if ("validator1.echoStructTest"==xreq.method)
|
||||
{ // echoStructTest test coming right up!
|
||||
if (xreq.paramCount!=1)
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
|
||||
else if ("struct"!=xreq.getParamType(0))
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch"));
|
||||
else // just echo back the struct we got as a parameter - how easy is that?!?
|
||||
vlib.output(xreq.getParam(0));
|
||||
vlib.done();
|
||||
|
||||
} // end if
|
||||
|
||||
if ("validator1.manyTypesTest"==xreq.method)
|
||||
{ // manyTypesTest coming right up!
|
||||
if (xreq.paramCount!=6)
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
|
||||
else if ( ("int"!=xreq.getParamType(0)) || ("boolean"!=xreq.getParamType(1))
|
||||
|| ("string"!=xreq.getParamType(2)) || ("double"!=xreq.getParamType(3))
|
||||
|| ("dateTime"!=xreq.getParamType(4)) || ("base64"!=xreq.getParamType(5)))
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch"));
|
||||
else
|
||||
{ // all six of the passed parameters must be returned in a single array
|
||||
rc = vlib.createList();
|
||||
for (i=0; i<6; i++)
|
||||
rc.add(xreq.getParam(i));
|
||||
vlib.output(rc);
|
||||
|
||||
} // end else
|
||||
|
||||
vlib.done();
|
||||
|
||||
} // end if
|
||||
|
||||
if ("validator1.moderateSizeArrayCheck"==xreq.method)
|
||||
{ // moderateSizeArrayCheck test coming right up!
|
||||
if (xreq.paramCount!=1)
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
|
||||
else if ("array"!=xreq.getParamType(0))
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch"));
|
||||
else
|
||||
{ // The given array will contain between 100 and 200 strings. We need to concatenate the
|
||||
// first and last string and return them.
|
||||
parm = vlib.castList(xreq.getParam(0));
|
||||
s1 = parm.get(0) + "";
|
||||
s2 = parm.get(parm.size()-1) + "";
|
||||
vlib.output(s1 + s2);
|
||||
|
||||
} // end else
|
||||
|
||||
vlib.done();
|
||||
|
||||
} // end if
|
||||
|
||||
if ("validator1.nestedStructTest"==xreq.method)
|
||||
{ // nestedStructTest coming right up!
|
||||
if (xreq.paramCount!=1)
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
|
||||
else if ("struct"!=xreq.getParamType(0))
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch"));
|
||||
else
|
||||
{ // The structure represents a calendar, one struct per year, each containing one struct per
|
||||
// month, each containing one struct per day. (Months and days are identified by 2-digit
|
||||
// numbers with leading zeroes, January is month 1.) We look up the structure for April 1,
|
||||
// 2000 ("2000.04.01") and find that it contains at least three members, named "moe", "larry",
|
||||
// and "curly", all three integers. We need to add those three values and return the result.
|
||||
map_all = vlib.castMap(xreq.getParam(0));
|
||||
map_year = vlib.castMap(map_all.get("2000"));
|
||||
map_month = vlib.castMap(map_year.get("04"));
|
||||
map_day = vlib.castMap(map_month.get("01"));
|
||||
val = vlib.toInteger(map_day.get("moe")) + vlib.toInteger(map_day.get("larry"))
|
||||
+ vlib.toInteger(map_day.get("curly"));
|
||||
vlib.output(vlib.createInteger(val));
|
||||
|
||||
} // end else
|
||||
|
||||
vlib.done();
|
||||
|
||||
} // end if
|
||||
|
||||
if ("validator1.simpleStructReturnTest"==xreq.method)
|
||||
{ // simpleStructReturnTest coming right up!
|
||||
if (xreq.paramCount!=1)
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
|
||||
else if ("int"!=xreq.getParamType(0))
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch"));
|
||||
else
|
||||
{ // we get an integer, we need to return a struct which gives that same integer multiplied
|
||||
// by 10, 100, and 1000, in elements "times10", "times100", and "times1000", respectively
|
||||
base_val = xreq.getParamInt(0);
|
||||
rc = vlib.createMap();
|
||||
rc.put("times10",vlib.createInteger(base_val * 10));
|
||||
rc.put("times100",vlib.createInteger(base_val * 100));
|
||||
rc.put("times1000",vlib.createInteger(base_val * 1000));
|
||||
vlib.output(rc);
|
||||
|
||||
} // end else
|
||||
|
||||
vlib.done();
|
||||
|
||||
} // end if
|
||||
|
||||
// just in case there's a method name that wasn't listed
|
||||
vlib.output(new XmlRpcFault(XmlRpcFault.METHOD_NOT_FOUND,"invalid method name: " + xreq.method));
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user