'Too many body parameters' Exception on Feign Client

旧巷老猫 提交于 2019-12-12 14:22:12

问题


I am using Springs Feign Client functionality to communicate from one micro service to another.

Now, the called service exposes a REST interface which accepts a file and a related (JSON)Object.

@RequestMapping(value = {CONVERT_PATH, APPLICATION_PATH + CONVERT_PATH}, method = RequestMethod.POST, produces = CONTENT_TYPE)
    public ResponseEntity<InputStreamResource> convert(@RequestPart("file") MultipartFile file, @RequestParam("input") Input in) {...}

This interface is functioning fine, I have verified this by sending a valid multipart/mixed entity to it from a different source.

Then, in my other service, I have setup a matching feign client to use this interface:

@FeignClient("convert")
public interface ConvertClient {
    @RequestMapping(value = CONVERT_PATH, method = RequestMethod.POST, consumes = "multipart/mixed")
    ResponseEntity<InputStreamResource> convert(@RequestPart("file") MultipartFile file, @RequestPart("input") Input in);
}

Again, the connection from one service to the other is working, Ive verified this with a different request interface in the feign client (one which does not use multiple parts).

When I try to build the (client)service with this particular interface-method I get the following exception:

FactoryBean threw exception on object creation; 
nested exception is java.lang.IllegalStateException: Method has too many Body parameters: 
public abstract org.springframework.http.ResponseEntity <..>.feign.ConvertClient.convert(org.springframework.web.multipart.MultipartFile,<..>.Input)

Is there anything I can do to make this work? Its possible to reach the REST interface as i stated, and different feign calls are working. If I am not mistaken this should work. Is Springs Feign just not supporting multipart/mixed for feign interfaces?


回答1:


I just published a custom Feign Encoder that is able to encode multipart requests (one or more files, alongwith json parts). You can try it here. Let me know if there are other use cases that can be implemented, feel free to open issues.



来源:https://stackoverflow.com/questions/34085157/too-many-body-parameters-exception-on-feign-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!