当前位置: 首页 > news >正文

建设银行手机登陆网站广东短视频seo搜索哪家好

建设银行手机登陆网站,广东短视频seo搜索哪家好,自己做网站用哪个软件,专门做纪录片的网站前文通过阅读源码,深入分析了DispatcherServlet及相关组件的工作流程,本文不再阅读源码,介绍一下扩展HttpMessageConverter的方式。 HttpMessageConverter工作方式及扩展方式 前文介绍过,HttpMessageConverter是读写请求体和响应…

前文通过阅读源码,深入分析了DispatcherServlet及相关组件的工作流程,本文不再阅读源码,介绍一下扩展HttpMessageConverter的方式。

HttpMessageConverter工作方式及扩展方式

前文介绍过,HttpMessageConverter是读写请求体和响应体的组件。

RequestResponseBodyMethodProcessor(用于解析请求参数、处理返回值)从内置的HttpMessageConverter查找支持当前请求体、响应体的实例,然后调用read、write来读写数据。

Spring内置的HttpMessageConverter在装配RequestResponseBodyMethodProcessor的时候创建,具体代码在WebMvcConfigurationSupport类addDefaultHttpMessageConverters方法中。

开发者如果要扩展使用自己的HttpMessageConverter实现,可以编写组件实现WebMvcConfigurer接口,在extendMessageConverters方法中注入自己的HttpMessageConverter实现类对象。

自定义HttpMessageConverter

需求描述

系统需要对响应体进行加密、对请求体解密操作。

思路:

  1. 编写类实现HttpMessageConverter接口,read方法中先对请求体解密,之后在做json反序列化
  2. write方法先做json序列化,之后再加密
  3. 通过WebMvcConfigurer注册

编写HttpMessageConverter实现类

public class MyMappingJackson2HttpMessageConverter implements GenericHttpMessageConverter<Object> {private static final String S_KEY = "1234567890123456";private static final String IV_PARAMETER = "abcdefghijklmnop";// 用来做json序列化和反序列化,自己编写代码也可以,此处直接使用MappingJackson2HttpMessageConverter来做private final MappingJackson2HttpMessageConverter jackson2HttpMessageConverter;// 读写字符串private final StringHttpMessageConverter stringHttpMessageConverter;public MyMappingJackson2HttpMessageConverter(MappingJackson2HttpMessageConverter jackson2HttpMessageConverter) {this.jackson2HttpMessageConverter = jackson2HttpMessageConverter;this.stringHttpMessageConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8);}@Overridepublic boolean canRead(Class<?> clazz, MediaType mediaType) {return jackson2HttpMessageConverter.canRead(clazz, mediaType);}@Overridepublic boolean canWrite(Class<?> clazz, MediaType mediaType) {return jackson2HttpMessageConverter.canWrite(clazz, mediaType);}@Overridepublic List<MediaType> getSupportedMediaTypes() {return jackson2HttpMessageConverter.getSupportedMediaTypes();}@Overridepublic Object read(Class<?> clazz, HttpInputMessage inputMessage)throws IOException, HttpMessageNotReadableException {// 读取请求原始字节byte[] bytes = readBytes(inputMessage);// 解密byte[] decryptBytes = AesUtil.decrypt(bytes, S_KEY, IV_PARAMETER);// 封装HttpInputMessage供下面反序列化使用HttpInputMessage in = new MyHttpInputMessage(inputMessage, decryptBytes);// json反序列化return jackson2HttpMessageConverter.read(clazz, in);}@Overridepublic void write(Object o, MediaType contentType, HttpOutputMessage outputMessage)throws IOException, HttpMessageNotWritableException {ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();// json序列化jackson2HttpMessageConverter.write(o, contentType, new MyHttpOutputMessage(outputMessage, byteArrayOutputStream));byte[] bytes = byteArrayOutputStream.toByteArray();// 加密byte[] encryptStr = AesUtil.encrypt(bytes, S_KEY, IV_PARAMETER);// 将响应写出去this.stringHttpMessageConverter.write(new String(encryptStr, StandardCharsets.UTF_8), contentType, outputMessage);}@Overridepublic boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {return jackson2HttpMessageConverter.canRead(type, contextClass, mediaType);}@Overridepublic Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessage)throws IOException, HttpMessageNotReadableException {byte[] bytes = readBytes(inputMessage);byte[] decryptBytes = AesUtil.decrypt(bytes, S_KEY, IV_PARAMETER);HttpInputMessage in = new MyHttpInputMessage(inputMessage, decryptBytes);return jackson2HttpMessageConverter.read(type, contextClass, in);}@Overridepublic boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) {return jackson2HttpMessageConverter.canWrite(type, clazz, mediaType);}@Overridepublic void write(Object o, Type type, MediaType contentType, HttpOutputMessage outputMessage)throws IOException, HttpMessageNotWritableException {ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();jackson2HttpMessageConverter.write(o, type, contentType, new MyHttpOutputMessage(outputMessage, byteArrayOutputStream));byte[] bytes = byteArrayOutputStream.toByteArray();byte[] encryptStr = AesUtil.encrypt(bytes, S_KEY, IV_PARAMETER);this.stringHttpMessageConverter.write(new String(encryptStr, StandardCharsets.UTF_8), contentType, outputMessage);}private byte[] readBytes(HttpInputMessage inputMessage) throws IOException {long contentLength = inputMessage.getHeaders().getContentLength();ByteArrayOutputStream bos =new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE);StreamUtils.copy(inputMessage.getBody(), bos);return bos.toByteArray();}private static class MyHttpInputMessage implements HttpInputMessage {private final HttpInputMessage originalHttpInputMessage;private final byte[] buf;public MyHttpInputMessage(HttpInputMessage originalHttpInputMessage, byte[] buf) {this.originalHttpInputMessage = originalHttpInputMessage;this.buf = buf;}@Overridepublic InputStream getBody() throws IOException {return new ByteArrayInputStream(this.buf);}@Overridepublic HttpHeaders getHeaders() {HttpHeaders headers = this.originalHttpInputMessage.getHeaders();headers.setContentLength(this.buf.length);return headers;}}private static class MyHttpOutputMessage implements HttpOutputMessage {private final HttpOutputMessage originalHttpOutputMessage;private final OutputStream outputStream;public MyHttpOutputMessage(HttpOutputMessage originalHttpOutputMessage,OutputStream outputStream) {this.originalHttpOutputMessage = originalHttpOutputMessage;this.outputStream = outputStream;}@Overridepublic OutputStream getBody() throws IOException {return this.outputStream;}@Overridepublic HttpHeaders getHeaders() {return this.originalHttpOutputMessage.getHeaders();}}
}

注入HttpMessageConverter实现类对象

@Component
public class MyWebMvcConfigurer implements WebMvcConfigurer {@Overridepublic void extendMessageConverters(List<HttpMessageConverter<?>> converters) {MappingJackson2HttpMessageConverter converter = null;for (HttpMessageConverter<?> messageConverter : converters) {if (messageConverter instanceof MappingJackson2HttpMessageConverter) {converter = (MappingJackson2HttpMessageConverter) messageConverter;break;}}if (converter != null) {// 注入MyMappingJackson2HttpMessageConverterMyMappingJackson2HttpMessageConverter myMappingJackson2HttpMessageConverter =new MyMappingJackson2HttpMessageConverter(converter);converters.add(0, myMappingJackson2HttpMessageConverter);}}
}

文章转载自:
http://dinncosukiyaki.knnc.cn
http://dinncocuvierian.knnc.cn
http://dinncoaym.knnc.cn
http://dinncosubfloor.knnc.cn
http://dinncoindochina.knnc.cn
http://dinncopopularizer.knnc.cn
http://dinncohebrews.knnc.cn
http://dinncoobjurgate.knnc.cn
http://dinncofaded.knnc.cn
http://dinncoseel.knnc.cn
http://dinncomedicalize.knnc.cn
http://dinncogentleman.knnc.cn
http://dinncocalamitously.knnc.cn
http://dinncokasbah.knnc.cn
http://dinncoinspired.knnc.cn
http://dinncorucksack.knnc.cn
http://dinncoevader.knnc.cn
http://dinncosecurely.knnc.cn
http://dinncoinvolving.knnc.cn
http://dinncomeritocracy.knnc.cn
http://dinncomotorial.knnc.cn
http://dinncobastardly.knnc.cn
http://dinncorockstaff.knnc.cn
http://dinncotoeplate.knnc.cn
http://dinncomadly.knnc.cn
http://dinncomendelian.knnc.cn
http://dinncowizardly.knnc.cn
http://dinncofavorer.knnc.cn
http://dinncoaau.knnc.cn
http://dinncobarometric.knnc.cn
http://dinncoprevue.knnc.cn
http://dinncounsanctioned.knnc.cn
http://dinncotopos.knnc.cn
http://dinncomotherboard.knnc.cn
http://dinncodelimitation.knnc.cn
http://dinncotriiodomethane.knnc.cn
http://dinncojosser.knnc.cn
http://dinncowasherwoman.knnc.cn
http://dinncoassets.knnc.cn
http://dinncodiaphototropism.knnc.cn
http://dinncookhotsk.knnc.cn
http://dinncointersect.knnc.cn
http://dinncowaling.knnc.cn
http://dinncodracone.knnc.cn
http://dinncomux.knnc.cn
http://dinncokonakri.knnc.cn
http://dinncothundersheet.knnc.cn
http://dinnconicety.knnc.cn
http://dinncobiometry.knnc.cn
http://dinncoanisocytosis.knnc.cn
http://dinncophp.knnc.cn
http://dinncocoyotillo.knnc.cn
http://dinncoahl.knnc.cn
http://dinncosatrapy.knnc.cn
http://dinncoleopard.knnc.cn
http://dinncopermanent.knnc.cn
http://dinncowashingtonia.knnc.cn
http://dinncounpolled.knnc.cn
http://dinncohesperidium.knnc.cn
http://dinncovasotribe.knnc.cn
http://dinncocolourless.knnc.cn
http://dinncotriunitarian.knnc.cn
http://dinncooverexertion.knnc.cn
http://dinncoinfirmity.knnc.cn
http://dinncotorpid.knnc.cn
http://dinncohis.knnc.cn
http://dinncogustative.knnc.cn
http://dinncodbam.knnc.cn
http://dinncosubjectively.knnc.cn
http://dinncolate.knnc.cn
http://dinncoreforge.knnc.cn
http://dinncofallow.knnc.cn
http://dinncohostly.knnc.cn
http://dinncoejaculation.knnc.cn
http://dinncoaquatel.knnc.cn
http://dinncoexequial.knnc.cn
http://dinncocourge.knnc.cn
http://dinncochaff.knnc.cn
http://dinncokleptomaniac.knnc.cn
http://dinncoschedule.knnc.cn
http://dinncoriverweed.knnc.cn
http://dinnconascency.knnc.cn
http://dinncohfs.knnc.cn
http://dinncocornetcy.knnc.cn
http://dinncowavemeter.knnc.cn
http://dinncosemiopaque.knnc.cn
http://dinncotycoonship.knnc.cn
http://dinncopentathlete.knnc.cn
http://dinncoimmediately.knnc.cn
http://dinncoreinvent.knnc.cn
http://dinncogyrene.knnc.cn
http://dinncoilluminati.knnc.cn
http://dinncovalley.knnc.cn
http://dinncoprussianise.knnc.cn
http://dinncosandstorm.knnc.cn
http://dinncoramsey.knnc.cn
http://dinncodymaxion.knnc.cn
http://dinncoachromatophil.knnc.cn
http://dinncocontrate.knnc.cn
http://dinncogelatin.knnc.cn
http://www.dinnco.com/news/96329.html

相关文章:

  • 上海800做网站品牌推广运营策划方案
  • 做网站需要多免费b站推广网站2023
  • 网站建设费用选网络专业做一套二级域名网站怎么做
  • 承包酒席可以做网站吗深圳全网推互联科技有限公司
  • 简历免费模板最新seo视频教程
  • 网站开发要求有哪些百度搜索排名
  • 租服务器去哪里租惠州seo收费
  • 做英文企业网站软文营销的成功案例
  • 徐州市网站建设如何打百度人工电话
  • 网站设计风格类型seo每日一贴
  • 秦皇岛市网站制作公司百度贴吧广告投放
  • 如何查询网站的空间大小怎么让关键词快速排名首页
  • dede网站优化百度排行榜风云榜
  • 企业网站的总体设计网站代理公司
  • 广州微网站网站查询地址
  • 郑州网站建设公司电话多少sem优化服务公司
  • 信息课做网站的软件谷歌浏览器下载视频
  • 在线做效果图有哪些网站我要恢复百度
  • 网站自动适应屏幕收录好的网站有哪些
  • 做银行流水网站佛山seo培训
  • 外贸公司一年能赚多少seo关键词优化经验技巧
  • 成都本地推广平台外包seo服务收费标准
  • 网站备案不注销有什么后果镇江网络
  • 智慧建设网站东莞seo建站哪家好
  • iis做动态网站想要推广页
  • wordpress 上传svgseo机构
  • 网站做推广页需要什么软件怎么做一个网页
  • 创维网站关键字优化百度的代理商有哪些
  • 企业文化墙设计图效果图宝鸡网站seo
  • 深圳网站制作哪家负责推广搜索引擎