9

I'm trying to use Feign and Eureka to forward a post request from server A to server B. Both servers are discrovered sucessfully by Eureka.

This works:

@Feignclient
public interface MyFeignClient {
    @RequestMapping(value = "test", = RequestMethod.POST, consumes = "application/json")
    ResponseEntity<String> theActualMethod(
            HttpServletRequest request,
            @RequestHeader("firstHeader") String header1,
            @RequestHeader("secondHeader") byte[] header2);
}

However, when I change the second argument to @RequestBody in order to read the POST request content, I get an exception:

java.lang.IllegalStateException: Method has too many Body parameters: public abstract org.springframework.http.ResponseEntity MyFeignClient.theActualMethod(javax.servlet.http.HttpServletRequest,java.lang.String,byte[])
Yoaz Menda
  • 1,555
  • 2
  • 21
  • 43

2 Answers2

10

The problem was that a method in Feign interface cannot have more than one 'general' argument. you can have as many header arguments as you want but not more than one as body. Since @RequestBody doesn't do anything it is regarded not as a header but as another variable in addition to the HttpServletRequest request variable.

So I had to change my business logic to have only one parameter.

Yoaz Menda
  • 1,555
  • 2
  • 21
  • 43
  • I found my way here because I removed all the `@Param("foo")` from `@Param("foo") String foo` in my interface methods because I mistakenly thought they were redundant :/ – Naruto Sempai Feb 05 '17 at 19:49
  • This seems like something they should support. I have the same problem. Can't find any other solution. – Alper Akture Dec 15 '17 at 00:15
2

For me, the issue was that I used @Param (as in feign.Param) instead of @RequestParam (as in org.springframework.web.bind.annotation.RequestParam). Changing all @Param to @RequestParam solved it for me.

I Don't know why this is but a related question on Feign's repository might explain a little.

asherbret
  • 5,439
  • 4
  • 38
  • 58