当前位置:网站首页>Feign report 400 processing
Feign report 400 processing
2022-04-23 16:49:00 【InfoQ】
getXxByIds(String Ids)
feign.FeignException$BadRequest: [400] during [POST] to [http...
Problem recurrence
@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;
}
}
// gateway The service 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);
}
}
use postman Direct access to service testing
url Length limit
- browser url Length limit
- Server length limit Such as tomcat Limit , nginx url Limit
- SpringBoot Project length limit
max-http-header-size
Default 8k, Change the service provided sky Configuration of 100*1024 (100k) , Retry the normal service call .
DataSize maxHttpHeaderSize = DataSize.ofKilobytes(8)
server:
port: 8080
max-http-header-size: 102400
Source code analysis
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);
// Encapsulate parameters
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 {
// Build request
Request request = targetRequest(template);
if (logLevel != Logger.Level.NONE) {
logger.logRequest(metadata.configKey(), logLevel, request);
}
Response response;
long start = System.nanoTime();
try {
// perform http request
response = client.execute(request, options);
...
}
Default
LoadBalancerFeignClient
FeignBlockingLoadBalancerClient
solve
1. Increase the of service providers header Parameters ( More micro services Not very suitable )
2. Change it to requestBody Call the service
summary
RequestTemplate
Request
版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231645272078.html
边栏推荐
猜你喜欢
Derivation of Σ GL perspective projection matrix
STM32__03—初识定时器
G008-hwy-cc-estor-04 Huawei Dorado V6 storage simulator configuration
Loggie source code analysis source file module backbone analysis
Knowledge points and examples of [seven input / output systems]
MySql主从复制
深度学习100例 | 第41天-卷积神经网络(CNN):UrbanSound8K音频分类(语音识别)
How vscode compares the similarities and differences between two files
Sail soft implements a radio button, which can uniformly set the selection status of other radio buttons
How magical is the unsafe class used by all major frameworks?
随机推荐
MySQL master-slave replication
Installation and management procedures
New project of OMNeT learning
04 Lua operator
深度学习100例 | 第41天-卷积神经网络(CNN):UrbanSound8K音频分类(语音识别)
Blue Bridge Cup provincial road 06 -- the second game of the 12th provincial competition
Gartner publie une étude sur les nouvelles technologies: un aperçu du métacosme
Use case labeling mechanism of robot framework
MySQL master-slave synchronization pit avoidance version tutorial
无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
Zhimeng dedecms security setup Guide
Use itextpdf to intercept the page to page of PDF document and divide it into pieces
Cartoon: what are IAAs, PAAS, SaaS?
ACL 2022 | dialogved: a pre trained implicit variable encoding decoding model for dialogue reply generation
批量制造测试数据的思路,附源码
File system read and write performance test practice
About background image gradient()!
NVIDIA graphics card driver error
Differences between MySQL BTREE index and hash index
org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su