Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Too many body parameters' Exception on Feign Client

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?

like image 600
Nils Mehlhorn Avatar asked Nov 10 '22 00:11

Nils Mehlhorn


1 Answers

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.

like image 78
pcan Avatar answered Nov 15 '22 04:11

pcan