当前位置:网站首页>feign报400处理
feign报400处理
2022-04-23 16:45:00 【InfoQ】
getXxByIds(String Ids)
feign.FeignException$BadRequest: [400] during [POST] to [http...
问题重现
@Slf4j
@RestController
public class SkyController {
@GetMapping("/sky")
public String sky (@RequestParam(required = false) String name) {
log.info(name);
return name;
}
@PostMapping("/deliver")
public String deliver (String packageBox) {
log.info(packageBox);
return packageBox;
}
@PostMapping("/feignPost")
public String feignPost(@RequestParam(name = "name") String name){
log.info(name);
return name;
}
@PostMapping("/feignBody")
public String feignBody(@RequestBody String name){
log.info(name);
return name;
}
}
// 网关 服务名称
@FeignClient(value = "paw-dogs-sky-service")
public interface SkyFeignClient {
@PostMapping("/deliver")
String deliver (@RequestParam(name = "packageBox") String packageBox);
@PostMapping("/feignPost")
String feignPost(@RequestParam(name = "name") String name);
@PostMapping("/feignBody")
String feignBody(@RequestBody String name);
}
@Slf4j
@SpringBootTest
class SkyFeignClientTest {
@Autowired
SkyFeignClient skyFeignClient;
@Test
void deliver () {
String param = RandomUtil.randomString(10*1024);
log.info(param);
String result = skyFeignClient.deliver(param);
log.info(result);
}
@Test
void feignPost () {
String param = RandomUtil.randomString(10*1024);
log.info(param);
String result = skyFeignClient.feignPost(param);
log.info(result);
}
@Test
void feignBody () {
String param = RandomUtil.randomString(1*1024);
log.info(param);
String result = skyFeignClient.feignBody(param);
log.info(result);
}
}

用postman直接访问服务测试


url长度限制
- 浏览器url长度限制
- 服务器长度限制 如tomcat限制, nginx url限制
- SpringBoot 项目长度限制
max-http-header-size
默认8k,更改提供服务sky的配置100*1024 (100k) ,重试服务正常调用。
DataSize maxHttpHeaderSize = DataSize.ofKilobytes(8)
server:
port: 8080
max-http-header-size: 102400
源码分析
RequestTemplate
Map<String, QueryTemplate> queries = new LinkedHashMap<>()
packageBox--> packageBox={packageBox}
SpringMvcContract
processAnnotationOnClass
processAnnotationOnMethod
processAnnotationsOnParameter
AnnotatedParameterProcessor
RequestParamParameterProcessor
public boolean processArgument(AnnotatedParameterContext context,
Annotation annotation, Method method) {
int parameterIndex = context.getParameterIndex();
Class<?> parameterType = method.getParameterTypes()[parameterIndex];
MethodMetadata data = context.getMethodMetadata();
if (Map.class.isAssignableFrom(parameterType)) {
checkState(data.queryMapIndex() == null,
"Query map can only be present once.");
data.queryMapIndex(parameterIndex);
return true;
}
RequestParam requestParam = ANNOTATION.cast(annotation);
String name = requestParam.value();
checkState(emptyToNull(name) != null,
"RequestParam.value() was empty on parameter %s", parameterIndex);
context.setParameterName(name);
// 对参数进行封装
Collection<String> query = context.setTemplateParameter(name,
data.template().queries().get(name));
data.template().query(name, query);
return true;
}
SynchronousMethodHandler
executeAndDecode(template, options)
Object executeAndDecode(RequestTemplate template, Options options) throws Throwable {
// 构建请求
Request request = targetRequest(template);
if (logLevel != Logger.Level.NONE) {
logger.logRequest(metadata.configKey(), logLevel, request);
}
Response response;
long start = System.nanoTime();
try {
// 执行http请求
response = client.execute(request, options);
...
}
Default
LoadBalancerFeignClient
FeignBlockingLoadBalancerClient
解决
1. 调大服务提供者的header参数(微服务较多 不太适用)
2. 改为requestBody调用服务
总结
RequestTemplate
Request
版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://xie.infoq.cn/article/26efaf86283ef5499d55ccc28
边栏推荐
- 漫画:什么是IaaS、PaaS、SaaS?
- On the security of key passing and digital signature
- Postman batch production body information (realize batch modification of data)
- Encapsulating the logging module
- Set cell filling and ranking method according to the size of the value in the soft report
- About JMeter startup flash back
- 人脸识别框架之dlib
- Report FCRA test question set and answers (11 wrong questions)
- 无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
- Detailed explanation of Niuke - Gloves
猜你喜欢
Deepinv20 installation MariaDB
The solution of not displaying a whole line when the total value needs to be set to 0 in sail software
Detailed explanation of file operation (2)
STM32__03—初识定时器
NVIDIA graphics card driver error
Postman batch production body information (realize batch modification of data)
人脸识别框架之dlib
Zhongang Mining: Fluorite Flotation Process
PyMySQL
The font of the soft cell changes color
随机推荐
Encapsulating the logging module
面试百分百问到的进程,你究竟了解多少
博士申请 | 厦门大学信息学院郭诗辉老师团队招收全奖博士/博后/实习生
安装及管理程序
Server log analysis tool (identify, extract, merge, and count exception information)
Quick install mongodb
Project framework of robot framework
Use case labeling mechanism of robot framework
Gartner announces emerging technology research: insight into the meta universe
Detailed explanation of gzip and gunzip decompression parameters
JMeter setting environment variable supports direct startup by entering JMeter in any terminal directory
关于 background-image 渐变gradient()那些事!
Public variables of robotframework
loggie 源码分析 source file 模块主干分析
Bytevcharts visual chart library, I have everything you want
Differences between MySQL BTREE index and hash index
Set the color change of interlaced lines in cells in the sail software and the font becomes larger and red when the number is greater than 100
Mock test
logback的配置文件加载顺序
Nacos 详解,有点东西