diff --git a/backend/framework/plugin/plugin-api-sdk/src/main/java/io/metersphere/plugin/api/spi/AbstractApiPlugin.java b/backend/framework/plugin/plugin-api-sdk/src/main/java/io/metersphere/plugin/api/spi/AbstractApiPlugin.java index b47178d0ba..966f933761 100644 --- a/backend/framework/plugin/plugin-api-sdk/src/main/java/io/metersphere/plugin/api/spi/AbstractApiPlugin.java +++ b/backend/framework/plugin/plugin-api-sdk/src/main/java/io/metersphere/plugin/api/spi/AbstractApiPlugin.java @@ -6,6 +6,7 @@ import io.metersphere.plugin.sdk.spi.AbstractMsPlugin; import io.metersphere.plugin.sdk.util.MSPluginException; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.List; /** @@ -13,14 +14,22 @@ import java.util.List; */ public abstract class AbstractApiPlugin extends AbstractMsPlugin { - public List getPluginOptions(ApiPluginOptionsRequest request) { - String method = request.getOptionMethod(); + /** + * 获取插件选项 + * + * @param request 请求参数 + * @return 选项列表 + */ + public List getPluginOptions(ApiPluginOptionsRequest request) { try { // 这里反射调用插件方法,获取下拉框选项 - return (List) this.getClass().getMethod(method, request.getClass()).invoke(this, request); + Method method = this.getClass().getMethod(request.getOptionMethod(), request.getClass()); + @SuppressWarnings("unchecked") + List result = (List) method.invoke(this, request); + return result; } catch (InvocationTargetException e) { throw new MSPluginException(e.getTargetException()); - } catch (Exception e) { + } catch (NoSuchMethodException | IllegalAccessException e) { throw new MSPluginException(e); } } diff --git a/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/spi/AbstractPlatform.java b/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/spi/AbstractPlatform.java index 0c3c532efe..a492046546 100644 --- a/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/spi/AbstractPlatform.java +++ b/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/spi/AbstractPlatform.java @@ -8,6 +8,7 @@ import io.metersphere.plugin.sdk.util.PluginUtils; import org.apache.commons.lang3.StringUtils; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.List; public abstract class AbstractPlatform implements Platform { @@ -35,13 +36,15 @@ public abstract class AbstractPlatform implements Platform { @Override public List getPluginOptions(PluginOptionsRequest request) { - String method = request.getOptionMethod(); try { // 这里反射调用 getIssueTypes 等方法,获取下拉框选项 - return (List) this.getClass().getMethod(method, request.getClass()).invoke(this, request); + Method method = this.getClass().getMethod(request.getOptionMethod(), request.getClass()); + @SuppressWarnings("unchecked") + List result = (List) method.invoke(this, request); + return result; } catch (InvocationTargetException e) { throw new MSPluginException(e.getTargetException()); - } catch (Exception e) { + } catch (NoSuchMethodException | IllegalAccessException e) { throw new MSPluginException(e); } }