feign接口调用报错【JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space 】

报错

今天在调用feign接口的时候,总是报错,如下

org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:252) -> 
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
 at [Source: (PushbackInputStream); line: 1, column: 2]
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:252)

环境信息

调用方式:

@FeignClient(value = "device", path = "/api/device")
public interface DeviceInfoRestService {
    @PostMapping({"/device/deviceInfos"})
    ResponseEntity<List<DeviceFeign>> deviceInfos(@RequestBody List<String> paramList);
}

在servie服务里面,有用到过滤器进行token进行权限校验

...
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
	try {
      	...
    } catch (Exception e) {
      log.error("转换出错:", e);
    } 
    chain.doFilter(request, response);
}
...

在调用chain.doFilter(request, response)的时候就会报上面的错误,刚开始以为是没加token或者参数里面有特殊字符原因,但在exclude该路径并对feign参数检查后,发现并不是,仍然会报错。

解决方案

在网上查了下,与feign的压缩配置有关,在yaml配置文件添加属性min-request-size: 30000,即触发压缩请求数据的参数大小,也就是超过这个最小参数大小的时候,就会触发压缩,这个值默认为2048(KB),也就2M大小,我这里参数比较多,所以调到了30000,这个可以根据参数情况自己进行调整

在这里插入图片描述

参考:https://docs.spring.io/spring-cloud-openfeign

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值