报错

今天在调用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

GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e 2 个月前
8c391e04 5 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐