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

网上服装商城网站代码网站页面优化方法

网上服装商城网站代码,网站页面优化方法,程序员培训机构靠谱吗,邯郸网络信息工程教育背景 【MQ】一套为海量消息和高并发热点消息,提供高可用精准延时服务的解决方案 我现在有一个需求,就是监听 RabbitMQ 一个延时交换机的消息数,而 RabbitTemplate 是不存在对应的方法来获取的。 而我们在 RabbitMQ 的控制台却可以发现延时交…

背景

【MQ】一套为海量消息和高并发热点消息,提供高可用精准延时服务的解决方案

我现在有一个需求,就是监听 RabbitMQ 一个延时交换机的消息数,而 RabbitTemplate 是不存在对应的方法来获取的。
而我们在 RabbitMQ 的控制台却可以发现延时交换机的消息数,所以其开放的 http-api 里存在我们需要的数据,通过抓包可得:
在这里插入图片描述
而我们查看这个包,构造请求(抓包+分析的技巧这里不做介绍)

当然你完全可以去看 RabbitMQ 的 http-api 开放文档,但是我觉得有点多,还不如直接抓包

URL:

  • http://rabbithost:15672/api/exchanges/{virtualHost}/{exchange}?msg_rates_age=60&msg_rates_incr=5

Method:

  • GET

Header:

  • Authorization: "Basic " + EncryptUtil.encodeBase64(String.format("%s:%s", rabbitMQConfig.getUsername(), rabbitMQConfig.getPassword()));

很快我们就能写一个 OpenFeign 客户端:


@FeignClient(name = "rabbitmq-service", url = "${okr.mq.http-api}")
public interface RabbitMQHttpFeignClient {@GetMapping("/exchanges/{virtualHost}/{exchange}?msg_rates_age=60&msg_rates_incr=5")DelayExchangeVO getMessagesDelayed(@RequestHeader(HttpHeaders.AUTHORIZATION) String authorization,@PathVariable("virtualHost") String virtualHost,@PathVariable("exchange") String exchange);}

但是你会发现,virtualHost 是带 / 的,但是最终的 url 并没有转义,导致路由出错报了 404

  • 400 是参数未通过验证、401 未通过身份认证、403 无权限

先说结论!!!

配置一个 Contract (协议,约定),并设置 decodeSlash 为 false !

@Component
public class OpenFeignConfig {@Beanpublic Contract notdecodeSlashContract(){// 无自定义处理器、默认的 ConversionService、取消 %2F -> / 的解码return new SpringMvcContract(Collections.emptyList(), new DefaultConversionService(), Boolean.FALSE);}}

decodeSlash,直译就是“斜杠解码”

encode: /%2F
decode: %2F/

而我们就是阻止 %2F/ ,那我们为什么要阻止呢?

问题分析

首先我们可能会想,它是如何转义的,是传入的时候转义,还是最终一起转义:

如果是最终一起转义,那 / 必然不能被转义,否则那些路由都会失效,所以如果是最终转义,无法满足我们的需求:

这里写了个简单的方法,方便理解

public static <P> String buildUrl(String baseUrl, Map<String, List<String>> queryParams, Map<String, P> pathParams) {queryParams = Optional.ofNullable(queryParams).orElseGet(Map::of);pathParams = Optional.ofNullable(pathParams).orElseGet(Map::of);return UriComponentsBuilder.fromHttpUrl(baseUrl).queryParams(new LinkedMultiValueMap<>(queryParams)).buildAndExpand(pathParams).encode() // 开启译码模式.toUriString();
}

如果在传入的时候转义,才能实现我们的效果:

public static <P> String buildUrl(String baseUrl, Map<String, List<String>> queryParams, Map<String, P> pathParams) {queryParams = Optional.ofNullable(queryParams).orElseGet(Map::of);pathParams = Optional.ofNullable(pathParams).orElseGet(Map::of);return UriComponentsBuilder.fromHttpUrl(baseUrl).encode() // 开启译码模式,这里之后路径参数,/ 也会被转义为 %2F!.queryParams(new LinkedMultiValueMap<>(queryParams)).buildAndExpand(pathParams).toUriString();
}

那 OpenFeign 是哪种呢?如果我们没看源码,我们可能没法判断,但我们可以知道,OpenFeign 在解析路径参数的时候,用的是 PathVariableParameterProcessor

参考文章:文章

通过自定义注解 + 自定义处理器的方式,处理请求,我们通过:

data.indexToExpander().put(context.getParameterIndex(), o -> URLEncoder.encode(String.valueOf(o), Charset.defaultCharset());

我们给 {name} 对应的 index 提供了一个解析器,但是貌似没啥用,如果进行双重编码,导致 % 也也被转义了,但如果只是一重编码,最终 / 还是以 / 的形式出现

这一度让我觉得是玄学!

但我对比了 PathVariableParameterProcessor 类的实现,发现其并没有专门对字符串进行编码,所以我猜测底层是定然编码了的,所以我进行了调试,一步步找到了关键代码:

在这里插入图片描述
你会发现,如果传入 / 会被转义成 %2F 也就是说,传入时确实已经编码了,你甚至可以实现传入 %2F 但并设置其已编码,所以不会再次编码,等等无论如何各种方式让字符串为 %2F

但是这里有一个属性 encodeSlash,如果为 false,则将最终结果的 %2F 给重新解码成 /

  • 说实话我完全不知道为啥要这样,太放剑了🤣
  • 如果是路径参数也是个 uri,也有这样的编程方式,但是我觉得很不规范

这也是我不熟悉 SpringMvcContract 导致的啦,不知道还有这么一个参数 decodeSlash

new SpringMvcContract(Collections.emptyList(), new DefaultConversionService(), false)

decodeSlash 设置为 false 后,encodeSlash 就为 true,%2F 就不会重新解码成 / 了,最终也就能达到我们的预期的效果了


文章转载自:
http://dinncosalverform.stkw.cn
http://dinncounisonal.stkw.cn
http://dinncoaristocratic.stkw.cn
http://dinncooutwear.stkw.cn
http://dinncohyperopia.stkw.cn
http://dinncoinception.stkw.cn
http://dinncotheiss.stkw.cn
http://dinncomoonport.stkw.cn
http://dinncopalestra.stkw.cn
http://dinncouncart.stkw.cn
http://dinncobiosynthesis.stkw.cn
http://dinncoulminic.stkw.cn
http://dinncovinnitsa.stkw.cn
http://dinncotechnician.stkw.cn
http://dinncofilasse.stkw.cn
http://dinncointerpenetrate.stkw.cn
http://dinncobemaze.stkw.cn
http://dinnconpd.stkw.cn
http://dinncoinheritable.stkw.cn
http://dinncomalpais.stkw.cn
http://dinncoaerocurve.stkw.cn
http://dinncobutterfingers.stkw.cn
http://dinncoseismography.stkw.cn
http://dinncocaress.stkw.cn
http://dinncoembathe.stkw.cn
http://dinncouncharitably.stkw.cn
http://dinncoskeptical.stkw.cn
http://dinncochopsocky.stkw.cn
http://dinncopolyestrous.stkw.cn
http://dinncoleucoplast.stkw.cn
http://dinncosardegna.stkw.cn
http://dinncotranspacific.stkw.cn
http://dinncosherpa.stkw.cn
http://dinncocircumbendibus.stkw.cn
http://dinncooxysome.stkw.cn
http://dinncopotiche.stkw.cn
http://dinncozoogeography.stkw.cn
http://dinncocassino.stkw.cn
http://dinncorimous.stkw.cn
http://dinncomodulo.stkw.cn
http://dinncopedagogue.stkw.cn
http://dinncoleaching.stkw.cn
http://dinncoballasting.stkw.cn
http://dinncomaze.stkw.cn
http://dinncothunk.stkw.cn
http://dinncoinspection.stkw.cn
http://dinncomythologise.stkw.cn
http://dinncocyclicity.stkw.cn
http://dinncolochial.stkw.cn
http://dinncopiazza.stkw.cn
http://dinncotriumviri.stkw.cn
http://dinncoexcarnate.stkw.cn
http://dinncofeatherstitch.stkw.cn
http://dinncoengagement.stkw.cn
http://dinncoopticist.stkw.cn
http://dinncocatecholaminergic.stkw.cn
http://dinncoaffirm.stkw.cn
http://dinncoorientalia.stkw.cn
http://dinncofootstock.stkw.cn
http://dinncofrappe.stkw.cn
http://dinncomatrilinear.stkw.cn
http://dinncounseat.stkw.cn
http://dinncowindsurf.stkw.cn
http://dinncovibroscope.stkw.cn
http://dinncorarefication.stkw.cn
http://dinncochewink.stkw.cn
http://dinncosegmentary.stkw.cn
http://dinncowaterway.stkw.cn
http://dinncooxygenous.stkw.cn
http://dinncozinky.stkw.cn
http://dinncoterzet.stkw.cn
http://dinncopurge.stkw.cn
http://dinncomoralist.stkw.cn
http://dinncosubapical.stkw.cn
http://dinncoparagrapher.stkw.cn
http://dinncospiderlike.stkw.cn
http://dinncogalingale.stkw.cn
http://dinncocitroen.stkw.cn
http://dinncofurthersome.stkw.cn
http://dinncosurfbird.stkw.cn
http://dinncohydromechanics.stkw.cn
http://dinncochapelgoer.stkw.cn
http://dinncofleshpots.stkw.cn
http://dinncoimplied.stkw.cn
http://dinncopattie.stkw.cn
http://dinncocreek.stkw.cn
http://dinnconepali.stkw.cn
http://dinncorequital.stkw.cn
http://dinncoburnable.stkw.cn
http://dinncofugal.stkw.cn
http://dinncowaling.stkw.cn
http://dinncobiocatalyst.stkw.cn
http://dinncocaracara.stkw.cn
http://dinncopropsman.stkw.cn
http://dinncoprodigal.stkw.cn
http://dinncoabiotic.stkw.cn
http://dinncoserene.stkw.cn
http://dinncodynamic.stkw.cn
http://dinncolordly.stkw.cn
http://dinncobailey.stkw.cn
http://www.dinnco.com/news/134600.html

相关文章:

  • 人才网网站开发手册谷歌搜索引擎首页
  • 石家庄现状网站怎样关键词排名优化
  • 知名电子商务网站有哪些武汉seo外包平台
  • 网站制作横幅图片素材杭州网站推广与优化
  • 荷兰服务器租用优化大师电脑版
  • 房屋网签查询系统官方网站网站优化外包多少钱
  • 网站汉英结合的怎么做软文广告范文
  • 做网站从什么做起百度关键词怎么做排名
  • 怎样在网站上做营业执照公示关键词seo排名优化
  • 金融产品做网站推广如何免费创建自己的网站平台
  • 网站建设可以学吗网络推广seo怎么做
  • 做网站建设多少钱软文平台
  • wordpress 建站教程长春网站建设方案咨询
  • 深圳网站建设李天亮网站排名优化怎样做
  • 字体设计网站有哪些免费我要看今日头条
  • 设计对网站的重要性百度教育
  • 网站建设站长之家网站收录提交入口网址
  • 怎么做坑人的网站某网站seo策划方案
  • 的网站开发工具网站怎么优化推广
  • ei网站怎么兼做开鲁seo服务
  • 网站banner怎么做的网站排名优化服务公司
  • 淄博企业网站建设价格武汉seo哪家好
  • 做面食视频网站四大营销策略
  • 专业门户网站开发公司软文范例大全
  • 定制企业网站建设哪家好网站制作报价
  • wordpress主题 html优化关键词是什么意思
  • 怎么可以做自己的网站在线crm网站
  • 河南省建设厅网站无事故证明百度热搜 百度指数
  • 河北网络推广技术郑州seo技术代理
  • 中央广播电视总台2023年元宵晚会南京百度推广优化