当前位置:网站首页>Feign call fails. JSON parse error illegal character ((ctrl-char, code 31)) only regular white space (R
Feign call fails. JSON parse error illegal character ((ctrl-char, code 31)) only regular white space (R
2022-07-29 00:13:00 【m0_ fifty-four million eight hundred and sixty-one thousand six】
background :feign No call , Report errors , I've been sleepy for almost a month !!! Abominable , It took two days to solve , I tried Baidu once , It's no use , Almost crying , Now let's talk about the solution process .
① At first, I opened the log to further check the error information , Need to be in feign Use the log level in the configuration file , Log level is FULL, And add the log level in the configuration file .
② And then I found that there was a mistake 404 not found, At first, I thought that the parameters were not enough , Called as three parameters , Pass two parameters when calling , After adding it, it still reports an error , Then I found that the annotation was used incorrectly , It used to be @PathVariable( Copied without change ), Use @RequestParam Post error change ( A low-level mistake ).
③ Report errors :nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space ( , , ) is allowed between tokens
at [Source: (ByteArrayInputStream); line: 1, column: 2].
④ then feign Call interface , Use String receive , Print out the string , I found the code ???
It was also found that binary data came back ??
Then began the crazy Baidu , I tried countless times , What configurations are added to various , You can't get rid of compression and so on , There is nothing like adding filters .
Finally, I found the answer in a big brother's article , Like me, he found garbled codes when he printed them , The question is gzip The received data is compressed , So random code , I still tried the useless configuration he said , The result is useful to me !!!!!( His next method that really works for her doesn't work for me , Also add interceptors )
answer : Add... To the configuration file feign.compression.response.useGzipDecoder by true that will do .
⑤ The mess is gone , I found only Chinese garbled , by !!!!!! It's been a long time for me again , Baidu has tried all its schemes , I also saw feign Log all parameters , It seems no problem , People are almost crying , Finally found a solution .
@Configuration
public class FeignConfig implements RequestInterceptor {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
@Bean
public Decoder feignDecoder() {
return new ResponseEntityDecoder(new SpringDecoder( () -> {
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter() {
@Override
public Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
Object result=null;
if ("java.lang.String".equals(type.getTypeName())) {
result= StreamUtils.copyToString(inputMessage.getBody(), Charset.forName("utf8"));
} else {
result=super.read(type, contextClass, inputMessage);
}
return result;
}
};
return new HttpMessageConverters(fastConverter);
}));
}
@Override
public void apply(RequestTemplate requestTemplate) {
try {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
.getRequestAttributes();
if (null != servletRequestAttributes) {
HttpServletRequest request = servletRequestAttributes.getRequest();
// Get all header file information key
Enumeration<String> headerNames = request.getHeaderNames();
if (null != headerNames) {
while (headerNames.hasMoreElements()) {
// Get the header file key and value
String headerName = headerNames.nextElement();
String headerValue = request.getHeader(headerName);
// skip content-length, Or you might report too many bites written problem
if ("content-length".equalsIgnoreCase(headerName)) {
continue;
}
// Add token data to header file , When used feign When called , Will be passed to the next microservice
requestTemplate.header(headerName, headerValue);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Bean
public Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}
Reference resources :Feign The statement - You know
answer : Add a decoder , Turn into utf8 That's all right. .
边栏推荐
- Interpretation of ISO 13400 (doip) standard
- Type 1-5 components
- [TA frost wolf \u may - "hundred people plan"] Figure 3.6 texture compression - inclusion slimming
- 【C】喝汽水,找单身狗问题
- 熊市下PLATO如何通过Elephant Swap,获得溢价收益?
- GhostNets on Heterogeneous Devices via Cheap Operations
- 软件设计师的错题汇总
- Powercli batch add esxi to vCenter
- 1-7 solve the problem of this pointing of methods in classes
- Review of categories 1-4
猜你喜欢
【C】 Introduction and Simulation Implementation of ATOI and offsetof
Web系统常见安全漏洞介绍及解决方案-CSRF攻击
Multi sensor fusion positioning (I) -- 3D laser odometer
IDEA报错Error running ‘Application‘ Command line is too long解决方案
Use pytoch to quickly train the network model
SAP temporary tablespace error handling
Doip communication of canoe application case
Leetcode60. permutation sequence
VMware VCSA 7.0 Install
【微服务】Nacos集群搭建以及加载文件配置
随机推荐
双重for循环优化
Is the declarative code of compose so concise?
JS four formulas for judging data types
1-6 state与绑定事件
Type 1-5 components
Develop effective Tao spell
Dual for loop optimization
Those "experiences and traps" in the data center
IDEA报错Error running ‘Application‘ Command line is too long解决方案
Detailed principle explanation and verification results of digital clock based on FPGA
The failure rate is as high as 80%. How to correctly complete the strategic planning of digital transformation?
Leetcode59. Spiral matrix II
【C】 Introduction and Simulation Implementation of ATOI and offsetof
Powercli batch add esxi to vCenter
Centos7 install mysql8
Real time data warehouse: Netease strictly selects the practice of real-time data warehouse based on Flink
【微服务】Nacos集群搭建以及加载文件配置
连接池-归还连接详解(下)
实时数仓:美团点评Flink的实时数仓应用分享
Real time data warehouse: Didi's real-time data warehouse landing practice