createRestServlet兼容throws IOException和RuntimeException的子类

This commit is contained in:
Redkale
2018-08-20 17:28:34 +08:00
parent 587160c5fe
commit cfecfabc92

View File

@@ -750,13 +750,12 @@ public final class Rest {
if (ignore) continue;
Class[] extypes = method.getExceptionTypes();
if (extypes.length > 1) {
if (mappings != null && mappings.length > 0) throw new RuntimeException("@" + RestMapping.class.getSimpleName() + " only for method with throws IOException");
continue;
}
if (extypes.length == 1 && extypes[0] != IOException.class) {
if (mappings != null && mappings.length > 0) throw new RuntimeException("@" + RestMapping.class.getSimpleName() + " only for method with throws IOException");
continue;
if (extypes.length > 0) {
for (Class exp : extypes) {
if (!RuntimeException.class.isAssignableFrom(exp) && !IOException.class.isAssignableFrom(exp)) {
throw new RuntimeException("@" + RestMapping.class.getSimpleName() + " only for method(" + method + ") with throws IOException");
}
}
}
paramtypes.add(TypeToken.getGenericType(method.getGenericParameterTypes(), serviceType));
if (mappings.length == 0) { //没有Mapping设置一个默认值