本文整理汇总了Java中com.thetransactioncompany.jsonrpc2.JSONRPC2Error.INVALID_PARAMS属性的典型用法代码示例。如果您正苦于以下问题:Java JSONRPC2Error.INVALID_PARAMS属性的具体用法?Java JSONRPC2Error.INVALID_PARAMS怎么用?Java JSONRPC2Error.INVALID_PARAMS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.thetransactioncompany.jsonrpc2.JSONRPC2Error
的用法示例。
在下文中一共展示了JSONRPC2Error.INVALID_PARAMS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensureEnumString
/**
* Throws a {@code JSONRPC2Error.INVALID_PARAMS} exception if the input
* string doesn't match a value in the specified string array.
*
* <p>This method is intended to check a string against a set of
* acceptable values.
*
* @param input The string to check.
* @param enumStrings The acceptable string values.
* @param ignoreCase {@code true} for a case insensitive match.
*
* @return The matching string value.
*
* @throws JSONRPC2Error With proper code and message if the input
* string didn't match.
*/
protected static String ensureEnumString(final String input, final String[] enumStrings, final boolean ignoreCase)
throws JSONRPC2Error {
for (String en : enumStrings) {
if (ignoreCase) {
if (en.toLowerCase().equals(input.toLowerCase()))
return en;
}
else {
if (en.equals(input))
return en;
}
}
// No match -> raise error
throw JSONRPC2Error.INVALID_PARAMS;
}
示例2: ensureParameter
/**
* Throws a {@code JSONRPC2Error.INVALID_PARAMS} exception if there is
* no parameter by the specified name or its type doesn't map to the
* specified.
*
* <p>You may use this method to fire the proper JSON-RPC 2.0 error
* on a missing or badly-typed mandatory parameter.
*
* @param name The parameter name.
* @param clazz The corresponding Java class that the parameter
* should map to (any one of the return types of the
* {@code getXXX()} getter methods. Set to
* {@code Object.class} to allow any type.
* @param allowNull If {@code true} allows a {@code null} parameter
* value.
*
* @throws JSONRPC2Error On a missing parameter or bad type
* ({@link JSONRPC2Error#INVALID_PARAMS}).
*/
public void ensureParameter(final String name, final Class clazz, final boolean allowNull)
throws JSONRPC2Error {
// First, check existence only
ensureParameter(name);
// Now check type
Object value = params.get(name);
if (value == null) {
if (allowNull)
return; // ok
else
throw JSONRPC2Error.INVALID_PARAMS;
}
if (! clazz.isAssignableFrom(value.getClass()))
throw JSONRPC2Error.INVALID_PARAMS;
}
示例3: getBooleanArray
/**
* Retrieves the specified boolean array (maps from JSON array of
* true/false values) parameter.
*
* @param name The parameter name.
*
* @return The parameter value as a boolean array.
*
* @throws JSONRPC2Error On a missing parameter, bad type or
* {@code null} value
* ({@link JSONRPC2Error#INVALID_PARAMS}).
*/
public boolean[] getBooleanArray(final String name)
throws JSONRPC2Error {
try {
List list = getList(name);
boolean[] booleanArray = new boolean[list.size()];
for (int i = 0; i < list.size(); i++) {
booleanArray[i] = (Boolean)list.get(i);
}
return booleanArray;
} catch (ClassCastException e) {
throw JSONRPC2Error.INVALID_PARAMS;
}
}
示例4: getIntArray
/**
* Retrieves the specified integer array (maps from JSON array of
* integer numbers) parameter.
*
* @param name The parameter name.
*
* @return The parameter value as an int array.
*
* @throws JSONRPC2Error On a missing parameter, bad type or
* {@code null} value
* ({@link JSONRPC2Error#INVALID_PARAMS}).
*/
public int[] getIntArray(final String name)
throws JSONRPC2Error {
try {
List list = getList(name);
int[] intArray = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
Number number = (Number)list.get(i);
intArray[i] = number.intValue();
}
return intArray;
} catch (ClassCastException e) {
throw JSONRPC2Error.INVALID_PARAMS;
}
}
示例5: getLongArray
/**
* Retrieves the specified long array (maps from JSON array of integer
* numbers) parameter.
*
* @param name The parameter name.
*
* @return The parameter value as a long array.
*
* @throws JSONRPC2Error On a missing parameter, bad type or
* {@code null} value
* ({@link JSONRPC2Error#INVALID_PARAMS}).
*/
public long[] getLongArray(final String name)
throws JSONRPC2Error {
try {
List list = getList(name);
long[] longArray = new long[list.size()];
for (int i = 0; i < list.size(); i++) {
Number number = (Number)list.get(i);
longArray[i] = number.longValue();
}
return longArray;
} catch (ClassCastException e) {
throw JSONRPC2Error.INVALID_PARAMS;
}
}
示例6: getFloatArray
/**
* Retrieves the specified float array (maps from JSON array of
* fraction numbers) parameter.
*
* @param name The parameter name.
*
* @return The parameter value as a float array.
*
* @throws JSONRPC2Error On a missing parameter, bad type or
* {@code null} value
* ({@link JSONRPC2Error#INVALID_PARAMS}).
*/
public float[] getFloatArray(final String name)
throws JSONRPC2Error {
try {
List list = getList(name);
float[] floatArray = new float[list.size()];
for (int i = 0; i < list.size(); i++) {
Number number = (Number)list.get(i);
floatArray[i] = number.floatValue();
}
return floatArray;
} catch (ClassCastException e) {
throw JSONRPC2Error.INVALID_PARAMS;
}
}
示例7: getDoubleArray
/**
* Retrieves the specified double array (maps from JSON array of
* fraction numbers) parameter.
*
* @param name The parameter name.
*
* @return The parameter value as a double array.
*
* @throws JSONRPC2Error On a missing parameter, bad type or
* {@code null} value
* ({@link JSONRPC2Error#INVALID_PARAMS}).
*/
public double[] getDoubleArray(final String name)
throws JSONRPC2Error {
try {
List list = getList(name);
double[] doubleArray = new double[list.size()];
for (int i = 0; i < list.size(); i++) {
Number number = (Number)list.get(i);
doubleArray[i] = number.doubleValue();
}
return doubleArray;
} catch (ClassCastException e) {
throw JSONRPC2Error.INVALID_PARAMS;
}
}
示例8: ensureParameter
/**
* Throws a {@code JSONRPC2Error.INVALID_PARAMS} exception if there is
* no parameter at the specified position or its type doesn't map to the
* specified.
*
* <p>You may use this method to fire the proper JSON-RPC 2.0 error
* on a missing or badly-typed mandatory parameter.
*
* @param position The parameter position.
* @param clazz The corresponding Java class that the parameter
* should map to (any one of the return types of the
* {@code getXXX()} getter methods. Set to
* {@code Object.class} to allow any type.
* @param allowNull If {@code true} allows a {@code null} parameter
* value.
*
* @throws JSONRPC2Error On a missing parameter or bad type
* ({@link JSONRPC2Error#INVALID_PARAMS}).
*/
public void ensureParameter(final int position, final Class clazz, final boolean allowNull)
throws JSONRPC2Error {
// First, check existence only
ensureParameter(position);
// Now check type
Object value = params.get(position);
if (value == null) {
if (allowNull)
return; // ok
else
throw JSONRPC2Error.INVALID_PARAMS;
}
if (! clazz.isAssignableFrom(value.getClass()))
throw JSONRPC2Error.INVALID_PARAMS;
}
示例9: getBooleanArray
/**
* Retrieves the specified boolean array (maps from JSON array of
* true/false values) parameter.
*
* @param position The parameter position.
*
* @return The parameter value as a boolean array.
*
* @throws JSONRPC2Error On a missing parameter, bad type or
* {@code null} value
* ({@link JSONRPC2Error#INVALID_PARAMS}).
*/
public boolean[] getBooleanArray(final int position)
throws JSONRPC2Error {
try {
List list = getList(position);
boolean[] booleanArray = new boolean[list.size()];
for (int i = 0; i < list.size(); i++) {
booleanArray[i] = (Boolean)list.get(i);
}
return booleanArray;
} catch (ClassCastException e) {
throw JSONRPC2Error.INVALID_PARAMS;
}
}
示例10: getIntArray
/**
* Retrieves the specified integer array (maps from JSON array of integer
* numbers) parameter.
*
* @param position The parameter position.
*
* @return The parameter value as an int array.
*
* @throws JSONRPC2Error On a missing parameter, bad type or
* {@code null} value
* ({@link JSONRPC2Error#INVALID_PARAMS}).
*/
public int[] getIntArray(final int position)
throws JSONRPC2Error {
try {
List list = getList(position);
int[] intArray = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
Number number = (Number)list.get(i);
intArray[i] = number.intValue();
}
return intArray;
} catch (ClassCastException e) {
throw JSONRPC2Error.INVALID_PARAMS;
}
}
示例11: getFloatArray
/**
* Retrieves the specified float array (maps from JSON array of fraction
* numbers) parameter.
*
* @param position The parameter position.
*
* @return The parameter value as a float array.
*
* @throws JSONRPC2Error On a missing parameter, bad type or
* {@code null} value
* ({@link JSONRPC2Error#INVALID_PARAMS}).
*/
public float[] getFloatArray(final int position)
throws JSONRPC2Error {
try {
List list = getList(position);
float[] floatArray = new float[list.size()];
for (int i = 0; i < list.size(); i++) {
Number number = (Number)list.get(i);
floatArray[i] = number.floatValue();
}
return floatArray;
} catch (ClassCastException e) {
throw JSONRPC2Error.INVALID_PARAMS;
}
}
示例12: getDoubleArray
/**
* Retrieves the specified double array (maps from JSON array of fraction
* numbers) parameter.
*
* @param position The parameter position.
*
* @return The parameter value as a double array.
*
* @throws JSONRPC2Error On a missing parameter, bad type or
* {@code null} value
* ({@link JSONRPC2Error#INVALID_PARAMS}).
*/
public double[] getDoubleArray(final int position)
throws JSONRPC2Error {
try {
List list = getList(position);
double[] doubleArray = new double[list.size()];
for (int i = 0; i < list.size(); i++) {
Number number = (Number)list.get(i);
doubleArray[i] = number.doubleValue();
}
return doubleArray;
} catch (ClassCastException e) {
throw JSONRPC2Error.INVALID_PARAMS;
}
}
示例13: handleVideoSearch
/**
* YouTube search handler
*
* @param request
* @return Top rated YouTube video
*/
private JSONRPC2Response handleVideoSearch(JSONRPC2Request request) {
Map<String, Object> param = request.getNamedParams();
if (param != null) {
String text = String.valueOf(param.get(SEARCH_TEXT));
if (!Strings.isNullOrEmpty(text)) {
Video topVideo = SearchEngine.getSearchEngine().getTopRatedVideo(text);
return new JSONRPC2Response(topVideo, request.getID());
}
}
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, request.getID());
}
示例14: validateParams
/**
* Check incoming request for required arguments, to make sure they are valid.
* @param requiredArgs - Array of names of required arguments. If null don't check for any parameters.
* @param req - Incoming JSONRPC2 request
* @param useAuth - If true, will validate authentication token.
* @return - null if no errors were found. Corresponding JSONRPC2Error if error is found.
*/
public static JSONRPC2Error validateParams(String[] requiredArgs, JSONRPC2Request req, Boolean useAuth) {
// Error on unnamed parameters
if (req.getParamsType() != JSONRPC2ParamsType.OBJECT) {
return JSONRPC2Error.INVALID_PARAMS;
}
HashMap params = (HashMap) req.getParams();
// Validate authentication token.
if (useAuth) {
JSONRPC2Error err = validateToken(params);
if (err != null) {
return err;
}
}
// If there exist any required arguments.
if (requiredArgs != null && requiredArgs.length > 0) {
String missingArgs = "";
for (int i = 0; i < requiredArgs.length; i++) {
if (!params.containsKey(requiredArgs[i])) {
missingArgs = missingArgs.concat(requiredArgs[i] + ",");
}
}
if (missingArgs.length() > 0) {
missingArgs = missingArgs.substring(0, missingArgs.length() - 1);
return new JSONRPC2Error(JSONRPC2Error.INVALID_PARAMS.getCode(), "Missing parameter(s): " + missingArgs);
}
}
return null;
}
示例15: process
public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx) {
if (req.getMethod().equals("GetRate")) {
JSONRPC2Error err = JSONRPC2Helper.validateParams(requiredArgs, req);
if (err != null)
return new JSONRPC2Response(err, req.getID());
HashMap inParams = (HashMap) req.getParams();
String input = (String) inParams.get("Stat");
if (input == null) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
}
long period;
try {
period = (Long) inParams.get("Period");
} catch (NumberFormatException e) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
}
RateStat rateStat = I2PAppContext.getGlobalContext().statManager().getRate(input);
// If RateStat or the requested period doesn't already exist, create them.
if (rateStat == null || rateStat.getRate(period) == null) {
long[] tempArr = new long[1];
tempArr[0] = period;
I2PAppContext.getGlobalContext().statManager().createRequiredRateStat(input, "I2PControl", "I2PControl", tempArr);
rateStat = I2PAppContext.getGlobalContext().statManager().getRate(input);
}
if (rateStat.getRate(period) == null)
return new JSONRPC2Response(JSONRPC2Error.INTERNAL_ERROR, req.getID());
Map outParams = new HashMap();
Rate rate = rateStat.getRate(period);
rate.coalesce();
outParams.put("Result", rate.getAverageValue());
return new JSONRPC2Response(outParams, req.getID());
}
return new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
}