question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Params order: "Body parameters cannot be used with form parameters."

See original GitHub issue

Hi,

This issue has already been discussed in #399. I got the same error with Feign 8.18.0, on a Swagger-codegen generated client (so i cannot modify the client). The annotations used are the good ones (feign.param for path params).

Interface :

@RequestLine("POST /client/session/{sessionUid}/slot/{slot}/sign")
@Headers({"Content-Type: application/json","Accept: application/json",})
SignResponse sign(@Param(value="sessionUid", expander=ParamExpander.class) String sessionUid, @Param(value="slot", expander=ParamExpander.class) Integer slot, SignRequest body);

Error:

java.lang.IllegalStateException: Body parameters cannot be used with form parameters.

However, if I change params order (body in first or second place) manually in the generated code, it works.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
JRJurmancommented, Dec 12, 2017

We ended up running into this issue because one of our path param had an underscore in it. We made the path parameter camel case, and that resolved the issue.

Doesn’t seem like you’re running into that here, but maybe this will help someone in the future running into the same issue.

1reaction
kdavisk6commented, Dec 27, 2019

I’ve done some more research into this and this exception is thrown during contract parsing when we encounter a @Param annotated method parameter that does not have a corresponding variable in the @RequestLine template and an explicit request body parameter is also present.

Feign will treat method parameters annotated this way as application/www-form-urlencoded parameters, creating an implicit request body; therefore it is not possible to provide an explicit request body. Here is an example:

/* 
 * This will cause an exception. username and password will be treated as 
 * application/www-form-urlencoded request body parameters and Credentials
 * are also being supplied as part of the request body.  We cannot support both
 */
@RequestLine("POST /authenticate")
public User authenticate(
   @Param("username") String username, 
   @Param("password") String password, 
   Credentials credentials); 

Admittedly, the Contract checks this after each parameter processed. This means that if you change up the order of the parameters we will miss this check, causing undefined behavior. #1137 will fix the ordering issue.

In this particular case, there was a bug in RequestTemplate where the variable processing and identification was incorrect, due to our decision to encode variable names when registering them with the template. This explains why @JRJurman’s change from _ to camel case corrected his issue. We corrected this in #778 and further refined this in #1138.

If anyone here is still experiencing this issue, can they test with version 10.7 and report if the issue is resolved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feign client with Headers and json data - Stack Overflow
I recieved the exception IllegalStateException: Body parameters cannot be used with form parameters. even after updating to latest feign .
Read more >
feign.MethodMetadata.bodyIndex java code examples - Tabnine
formParams ().isEmpty(), "Body parameters cannot be used with form parameters."); checkState(data.bodyIndex() == null, "Method has too many Body parameters: ...
Read more >
Specify Parameters - SQL Server | Microsoft Learn
The parameter values supplied with a procedure call must be constants or a variable; a function name cannot be used as a parameter...
Read more >
Building requests | Postman Learning Center
Your requests can send parameters, authorization details, and any body data you require. For example, if you're building a client ...
Read more >
Request Body - FastAPI
The same as when declaring query parameters, when a model attribute has a default value, it is not required. Otherwise, it is required....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found