public Object beforeBodyWrite(Object arg0, MethodParameter arg1, MediaType arg2, Class arg3, ServerHttpRequest arg4, ServerHttpResponse arg5) { OutputObject out = new OutputObject(); try { //arg0转换为OutputObject类型 ObjectMapper objectMapper=new ObjectMapper(); out = objectMapper.readValue(org....
二、实例 有一个Controller类,返回参数为OutputObject,我们通过ResponseBodyAdvice,对该类的所有方法返回的OutputObject中的部分数据进行统一加密处理。 //对响应报文统一处理,对bean内容进行加密@Component//声明该类要处理的包路径@ControllerAdvice("com.cmos.edcreg.web.controller")publicclassResponseAdviceimplementsRespo...
beforeBdoyWrite方法中,为对response处理的具体代码。 实例:有一个工程,这个工程中的一个Controller类,返回参数为OutputObject(一个自定义的javaBean),我们要通过ResponseBodyAdvice,对该类的所有方法返回的OutputObject中的部分数据进行统一加密处理。 packagecom.cmos.edcreg.web.intercepter;importorg.slf4j.Logger;impor...
Object afterBodyRead(Object var1, HttpInputMessage var2, MethodParameter var3, Type var4, Class<? extends HttpMessageConverter<?>> var5); @Nullable Object handleEmptyBody(@Nullable Object var1, HttpInputMessage var2, MethodParameter var3, Type var4, Class<? extends HttpMessageConverter<?>> ...
>>converterType){// 判断是否支持对响应体的处理// 返回true表示支持,会执行其他两个方法;返回false表示不支持,不执行其他两个方法returntrue;}@OverridepublicObjectbeforeBodyWrite(Objectbody,MethodParameterreturnType,MediaTypeselectedContentType,Class<?extendsHttpMessageConverter<?>>selectedConverterType,ServerHttp...
*/@OverridepublicObjectbeforeBodyWrite(Object body,MethodParameter arg1,MediaType arg2,Class<? extends HttpMessageConverter<?>>arg3,ServerHttpRequest request,ServerHttpResponse response){//判断url是否需要拦截if(this.ignoring(request.getURI().toString())){returnbody;}if(bodyinstanceofResult){returnbody...
throwsIOException{DecryptHttpInputMessagemessage=newDecryptHttpInputMessage(inputMessage);//todo message可以做各种处理,典型的是将加密串解析成Json,以适配RequestBody转成对象returnmessage;}//报文解析后,可以做的工作@OverridepublicObjectafterBodyRead(Objectbody,HttpInputMessageinputMessage,MethodParameterparameter,...
Object obj = request.getSession().getAttribute(BaseController.session_user); String path = request.getServletPath(); if (StringUtils.isBlank(path)) { path = request.getPathInfo(); } if (obj != null) { path = request.getPathInfo(); ...
有⼀个Controller类,返回参数为OutputObject,我们通过ResponseBodyAdvice,对该类的所有⽅法返回的OutputObject中的部分数据进⾏统⼀加密处理。// 对响应报⽂统⼀处理,对bean内容进⾏加密 @Component //声明该类要处理的包路径 @ControllerAdvice("com.cmos.edcreg.web.controller")public class Response...
}// 否则进行包装ResponseWrapper<Object> responseWrapper =newResponseWrapper<>();if(bodyinstanceofBusinessException) {// 将业务异常的状态码和消息拷贝到responseWrapper中BusinessExceptionbusinessException=(BusinessException) body; responseWrapper.setCode(businessException.getCode()); ...