当前位置:网站首页>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
边栏推荐
- Installation and management procedures
- Pytorch: the pit between train mode and eval mode
- Deepinv20 installation MariaDB
- Summary according to classification in sail software
- Dlib of face recognition framework
- Derivation of Σ GL perspective projection matrix
- Selenium IDE and XPath installation of chrome plug-in
- Bytevcharts visual chart library, I have everything you want
- Calculate pie chart percentage
- vscode如何比较两个文件的异同
猜你喜欢
STM32__03—初识定时器
昆腾全双工数字无线收发芯片KT1605/KT1606/KT1607/KT1608适用对讲机方案
Change the icon size of PLSQL toolbar
阿里研发三面,面试官一套组合拳让我当场懵逼
【Pygame小游戏】10年前风靡全球的手游《愤怒的小鸟》,是如何霸榜的?经典回归......
Day 9 static abstract class interface
Cartoon: what are IAAs, PAAS, SaaS?
Detailed explanation of Niuke - Gloves
Nacos 详解,有点东西
How much do you know about the process of the interview
随机推荐
04 Lua operator
Dancenn: overview of byte self-developed 100 billion scale file metadata storage system
杂文 谈谈古典的《拆掉思维里的墙》
NVIDIA显卡驱动报错
G008-hwy-cc-estor-04 Huawei Dorado V6 storage simulator configuration
Knowledge points and examples of [seven input / output systems]
How much do you know about the process of the interview
Detailed explanation of file operation (2)
There is a problem with the light switch from 1 to 100
Set cell filling and ranking method according to the size of the value in the soft report
Mock test
New project of OMNeT learning
详解牛客----手套
基于GPU实例的Nanopore数据预处理
阿里研发三面,面试官一套组合拳让我当场懵逼
◰GL-阴影贴图核心步骤
◰ GL shadow map core steps
Postman batch production body information (realize batch modification of data)
Gartner announces emerging technology research: insight into the meta universe
Qipengyuan horizon credible meta universe social system meets diversified consumption and social needs