Skip to content

Feign mixes up header and request param values if they are of the same name #702

Closed

Description

@kameshbrao

I have a service with the some header and request param with the same name. In such case the values of the request headers are mixed up with the values of the request parameters.

My Service is as below:

@GetMapping("/get-rating-headers")
	public List<Rating> testGetRating(@RequestHeader("firstHeader") String header1,@RequestHeader("testParam1") String testHeader2,
									 @RequestParam("testParam2") String testParam2, @RequestParam("testParam1") String testParam1,
									  @RequestParam("bookId") Long bookId){}

My Feign interface looks as below:

@FeignClient("http://rating-service")
interface RatingService {
	@GetMapping("/ratings/get-rating/{bookId}")
	List<Rating> findRatingsByBookId(@PathVariable("bookId") Long bookId);

	@GetMapping("/ratings/get-rating-headers")
	public List<Rating> testGetRating(@RequestHeader("firstHeader") String header1,@RequestHeader("testParam1") String testHeader2,
									  @RequestParam("testParam2") String testParam2,@RequestParam("testParam1") String testParam1,
									  @RequestParam("bookId") Long bookId);
}

My Client call code looks as below:

@GetMapping("/{bookId}")
	public Book findBook(@RequestHeader("firstHeader") String header1,@RequestHeader("testParam1") String header2,
						 @PathVariable Long bookId) {
		System.out.println("Header1:"+header1);
		System.out.println("Header2:"+header2);
		System.out.println("BookId:"+bookId);
		List<Rating> ratings = ratingService.testGetRating(header1,header2,"testParam1","testParam2",bookId);
}

Activity

  1. kdavisk6 commented on May 16, 2018

    @kdavisk6
    Member

    I would ask this question with the Spring folks. From your examples, you are using the Spring Cloud Open Feign annotations and not Feign core. I would check with them first.

  2. kdavisk6 commented on Jul 18, 2018

    @kdavisk6
    Member

    I've looked into this some more and you are correct. In Feign a Param can reference a templated value in either a @Body, @Headers, or @RequestLine value.

    I'm going to look into a possible long term solution for this, but to address your immediate issue, I recommend using different Header and Parameter template names.

  3. kdavisk6 commented on Sep 23, 2018

    @kdavisk6
    Member

    Closed via #778 Documentation added to call out this scenario

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationIssues that require updates to our documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions