码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 远程调用,参数压缩问题


    错误信息

    {
        "msg": "Error while extracting response for type [XXX] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens\n at [Source: (PushbackInputStream); line: 1, column: 2]",
        "code": "500",
        "root": ""
    }

    问题分析

    Tomcat 9.0.45

    FeignClient Request

    Request Header包含

    accept-encoding = gzip, deflate, br

    FeignServer Request

    Request Header包含,但是也被分成了两个header

    accept-encoding=gzip

    accept-encoding=deflate

    FeignClient Response

    包含content-encoding:gzip

    所以在JSON反序列化时会报错

    原因

    org.apache.coyote.CompressionConfig只考虑一个Accept-Encoding请求头。当请求包含多个这样的标头时,可能不使用压缩,具体取决于所考虑的标头是哪个。(fixed in 9.0.25)

    在上述验证过程中,FeignServer接收FeignClient请求时,Accept-Encoding请求头确实被分成了两个。

    相关链接

    Spring Boot:

    Server Side Compression not working when sending Accept-Encoding with multiple values separately · Issue #18176 · spring-projects/spring-boot · GitHub

    Apache Tomcat:

    63737 – Compression may not work when there are multiple Accept-Encoding headers in the request

    解决方案

    方案一

    Spring Cloud升级至Hoxton版本

    针对除OkHttpClient以外的http客户端,可以启用默认的gzip解码器,以UTF-8编码/解码gzip响应

    相关配置:

    feign.compression.response.enabled=true

    feign.compression.response.useGzipDecoder=true

    相关链接:

    Adding gzip support for Spring Decoder by jskim1991 · Pull Request #230 · spring-cloud/spring-cloud-openfeign · GitHub

    方案二

    引入依赖:

    
        org.springframework.boot
        spring-boot-autoconfigure
    
    
        org.springframework.boot
        spring-boot-configuration-processor
        true
    
    
        org.springframework.cloud
        spring-cloud-starter-openfeign
    
    
        io.github.openfeign
        feign-httpclient
    
    
        io.github.openfeign
        feign-okhttp
    

    添加配置:

    feign.okhttp.enabled=true

  • 相关阅读:
    1_MyBatis入门
    干货 | 科研人的KPI怎么算,H指数和G指数是什么
    (十九)ATP应用测试平台——springboot集成RocketMQ案例实战
    ​Distil-Whisper:比Whisper快6倍,体积小50%的语音识别模型
    VUE综合数据库编程
    开启智慧之旅,AI与机器学习驱动的微服务设计模式探索
    【2023,学点儿新Java-50】阶段性章节复习:String类的使用 以及与基本数据类型变量间的运算 | 认识进制 | 常用运算符回顾之算术运算符、赋值运算符
    2.0SpingMVC使用RESTful
    菜鸟教程《Python 3 教程》笔记(17):输入和输出
    记录开发过程中遇到的oracle 分页问题
  • 原文地址:https://blog.csdn.net/U2133048/article/details/134268454
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号