Tencent/APIJSON · error · UnsupportedOperationException
不允许 method = " + parser.getMethod() + " 的请求调用远程函数 " + fb.get
Error message
不允许 method = " + parser.getMethod() + " 的请求调用远程函数 " + fb.getMethod() + " ! 必须满足 method 在 " + Arrays.toString(methods) + "内 !
What it means
Function rows may restrict which HTTP request methods (GET/POST/...) may invoke them via a comma-separated methods column. The parser checks parser.getMethod() against that list and throws UnsupportedOperationException when, for example, a write-only function is invoked from a GET request.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java:438
" == false 时不支持远程函数中的脚本形式!如需支持则设置 AbstractFunctionParser.ENABLE_SCRIPT_FUNCTION = true !");
}
if (lang != null && SCRIPT_EXECUTOR_MAP.get(lang) == null) {
throw new ClassNotFoundException("找不到脚本语言 " + lang + " 对应的执行引擎!请先依赖相关库并在后端 APIJSONFunctionParser<T, M, L> 中注册!");
}
int version = row.get("version") != null ? Integer.parseInt(row.get("version").toString()) : 0;
if (parser.getVersion() < version) {
throw new UnsupportedOperationException("不允许 version = " + parser.getVersion() + " 的请求调用远程函数 " + fb.getMethod() + " ! 必须满足 version >= " + version + " !");
}
String tag = (String) row.get("tag"); // TODO 改为 tags,类似 methods 支持多个 tag。或者干脆不要?因为目前非开放请求全都只能后端指定
if (tag != null && tag.equals(parser.getTag()) == false) {
throw new UnsupportedOperationException("不允许 tag = " + parser.getTag() + " 的请求调用远程函数 " + fb.getMethod() + " ! 必须满足 tag = " + tag + " !");
}
String[] methods = StringUtil.split((String) row.get("methods"));
List<String> ml = methods == null || methods.length <= 0 ? null : Arrays.asList(methods);
if (ml != null && ml.contains(parser.getMethod().toString()) == false) {
throw new UnsupportedOperationException("不允许 method = " + parser.getMethod() + " 的请求调用远程函数 " + fb.getMethod() + " ! 必须满足 method 在 " + Arrays.toString(methods) + "内 !");
}
try {
return invoke(parser, fb.getMethod(), fb.getTypes(), fb.getValues(), (String) row.get("returnType"), current, SCRIPT_EXECUTOR_MAP.get(lang));
}
catch (Exception e) {
if (e instanceof NoSuchMethodException) {
throw new IllegalArgumentException("字符 " + function + " 对应的远程函数 " + getFunction(fb.getMethod(), fb.getKeys())
+ " 不在后端 " + parser.getClass().getName() + " 内,也不在父类中!如果需要则先新增对应方法!"
+ "\n请检查函数名和参数数量是否与已定义的函数一致!"
+ "\n且必须为 function(key0,key1,...) 这种单函数格式!"
+ "\nfunction 必须符合 Java 函数命名,key 是用于在 curObj 内取值的键!"
+ "\n调用时不要有空格!" + (Log.DEBUG ? e.getMessage() : ""));
}
if (e instanceof InvocationTargetException) {
Throwable te = ((InvocationTargetException) e).getTargetException();
if (StringUtil.isEmpty(te.getMessage(), true) == false) { //到处把函数声明throws Exception改成throws Throwable挺麻烦
throw te instanceof Exception ? (Exception) te : new Exception(te.getMessage());View on GitHub (pinned to 5284052872)
Solutions
- Call the function from an allowed method: change the request to POST (or GET) as the Function row specifies.
- Or add the needed method to the Function row's methods column.
- Keep function usage aligned with endpoint semantics when designing methods lists.
Example fix
-- before: methods='POST', sent via GET UPDATE sys.Function SET methods='GET,POST' WHERE name='enc'; -- or send the request as POST instead of GET
Defensive patterns
Strategy: validation
Validate before calling
String[] methods = StringUtil.split((String) functionRow.get("methods"));
List<String> allowed = methods == null ? null : Arrays.asList(methods);
if (allowed != null && !allowed.contains(requestMethod.name())) {
// use an allowed HTTP method or extend the row's methods list
} Try / catch
try { parser.invoke(fn, current); } catch (UnsupportedOperationException e) { if (e.getMessage().contains("method")) { /* switch endpoint method or update row */ } throw e; } Prevention
- Designate each function as read or write and set methods accordingly, then call it only from matching endpoints.
- Review methods columns when adding new function-based columns to existing endpoints.
- Keep a client-side map of function -> allowed methods.
When it happens
Trigger: Function row methods='POST' but the request is a GET containing the function call; or methods list omits the method used by the current request.
Common situations: Reusing a function expression in a query endpoint when it was registered only for POST; Function rows copied from a demo with restrictive methods; client switched endpoint method from POST to GET.
Related errors
- 字符 " + function + " 不合法!
- AbstractFunctionParser.ENABLE_REMOTE_FUNCTION == false 时不支持远
- 不允许调用远程函数 " + fb.getMethod() + " !
- language = " + language + " 不合法!AbstractFunctionParser.ENABL
- 不允许 version = " + parser.getVersion() + " 的请求调用远程函数 " + fb.g
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/99ca6cc354644dfd.
Report an issue: GitHub.