Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final fields of payload object are not recognized when executing POST form-urlencoded #2365

Open
tsypanovs opened this issue Mar 27, 2024 · 1 comment

Comments

@tsypanovs
Copy link

Originally asked in https://stackoverflow.com/questions/78232043/feign-client-final-fields-of-payload-object-are-not-recognized-when-executing-p

In my code I have simple Feign client:

@FeignClient(name = "client", url = "${spring.microservice.tenant-auth.host}")
public interface PerTenantTokenClient {

  @PostMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
  ResponseEntity<AuthenticationResponse> getAuthToken(AuthFormData formData);

}

aimed to execute the following request:

POST https://myhost.net/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type = client_credentials &
client_id = id &
client_secret = secret

getAuthToken() method accepts a payload DTO described as:

@RequiredArgsConstructor
public class AuthFormData {
  private final String grant_type;
  private final String client_id;
  private final String client_secret;
}

When I run this code snippet:

AuthFormData authFormData = new AuthFormData("client_credentials", "id", "secret");
var authTokenResponse = client.getAuthToken(authFormData);

it unexpectedly fails with 400:

[400 Bad Request] during [POST] to [https://myhost.net/oauth/token] [PerTenantTokenClient#getAuthToken(AuthFormData)]: [{
  "error" : "invalid_request",
  "error_description" : "Missing parameter: grant_type"
}]

However, if I remove final from AuthFormData fields' declaration the same code succeeds.

I've tried to declare AuthFormData as Java record and it fails either (apparently due to implicit final on record members).

So my question is whether I'm facing a bug in feign client or something is wrong with my code? I use io.github.openfeign:feign-core:13.1 and Java 21

@gromspys
Copy link
Contributor

As I see it's duplication of this issue: #2152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants