拦截一些非法的参数信息,使用注解的方式
mport java.lang.annotation.Annotation; import java.util.Collection; import java.util.Collections; import java.util.Map; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class ParameterValidateInterceptor implements MethodInterceptor { private static Log logger = LogFactory .getLog(ParameterValidateInterceptor.class); private boolean isExpectedParamValue(Annotation[] annotations, Object[] params, int index) { if (annotations != null && annotations.length > 0) { for (Annotation annotation : annotations) { if (annotation instanceof ParamValueValidator) { ParamValueValidator validatorAnnotation = (ParamValueValidator) annotation; if (String.class.isAssignableFrom(validatorAnnotation.classType())) return !StringUtil.isEmpty((String)params[index]); if (Integer.class.isAssignableFrom(validatorAnnotation .classType())) return (Integer) params[index] > 0; if (Long.class.isAssignableFrom(validatorAnnotation .classType())) return (Long) params[index] > 0; if (Collection.class.isAssignableFrom(validatorAnnotation .classType())) return params[index] != null && !((Collection>) params[index]).isEmpty(); } } } return true; } @Override public Object invoke(MethodInvocation invocation) throws Throwable { Object[] params = invocation.getArguments(); if (params != null && params.length > 0) { Annotation[][] annotationss = invocation.getMethod() .getParameterAnnotations(); if (annotationss == null || annotationss.length == 0) return invocation.proceed(); for (int i = 0; i < annotationss.length; i++) { Annotation[] annotations = annotationss[i]; if (!isExpectedParamValue(annotations, params, i)) { String methodName = " [" + invocation.getMethod().getDeclaringClass().getName() + "." + invocation.getMethod().getName() + "] "; logger.debug(methodName + "the parameter value isn't as we expected,null/empty is return."); if (Collection.class.isAssignableFrom(invocation .getMethod().getReturnType())) return Collections.emptyList(); if (Map.class.isAssignableFrom(invocation.getMethod() .getReturnType())) return Collections.emptyMap(); return null; } } } return invocation.proceed(); }
import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) public @interface ParamValueValidator { Class<?> classType(); }
相关推荐
对request请求进行拦截,对请求参数修改。常用于前台提交表单参数关键字的过滤。此工具可以对参数拦截并转义后提交到对应的处理类。 除了添加两个JsFilter.java和GetHttpServletRequestWrapper.java之外,需要在web....
C#SqlParameter参数写法C#SqlParameter参数写法C#SqlParameter参数写法C#SqlParameter参数写法C#SqlParameter参数写法C#SqlParameter参数写法
dynamicparameter离线插件,用于jenkins中的邮件搭建
Parameter estimation for text analysis Gregor Heinrich Parameter estimation for text analysis Gregor Heinrich Parameter estimation for text analysis Gregor Heinrich Parameter estimation for text ...
Autosar SWC Parameter测试模型及生成的代码,Arxml文件
Fixed Parameter Algorithms ppt slides from Venkatesh Raman ppt 课件
parameter批量查询网页PR parameter批量查询网页PR
SqlParameter的用法,详细说明。给你帮助
亲测可用,jenkins的Dynamic Parameter Plug-in 插件,现在因为有漏洞安装不了了,只能手动安装。资源包中有Parameter Plug-in插件和其依赖的插件
sap parameter 参数集 sap profile
camera parameter introduction and control method camera parameter introduction and control method
赠送jar包:sentinel-parameter-flow-control-1.8.0.jar; 赠送原API文档:sentinel-parameter-flow-control-1.8.0-javadoc.jar; 赠送源代码:sentinel-parameter-flow-control-1.8.0-sources.jar; 赠送Maven依赖...
参数估计和反问题:《Parameter estimation and inverse problems》
Jenkins Dynamic Parameter Plugin 插件库已下架,目前这是从之前论坛下载
【jenkins】Extended Choice Parameter参数选择插件,方便自动化控制流程使用,根据预选的参数选择对应的自动化流程。
parameter_server pslite 参数服务器说明 parameter_server pslite 参数服务器说明
Delphi 10.3 ,程序运行到DataModule2.ClientDataSet1.ApplyUpdates(0);语句时,提示“Invalid parameter”错误
SMT_parameter_setting_guide_v5_0
Bayesian Spectrum Analysis and Parameter Estimation