-
Notifications
You must be signed in to change notification settings - Fork 80
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
Running @FeignClient with application/x-www-form-urlencoded throws IllegalStateException: Method has too many Body parameters #79
Comments
NB: Looks like the following does the trick, without the
with a wrapper whose properties match the params from before:
Log:
Oh, and btw: the |
I tried to use following code, but I got the same error when I was using LinkedHasMap. I tried to use FormEncoder Configuration, but when I try to do a normal request, in other Client he tries to encode my request without set configuration in Client properties. @FeignClient(name = "Authentication", url = "\${url.sts}")
interface Authentication {
@PostMapping(consumes = [MediaType.APPLICATION_FORM_URLENCODED_VALUE],
value = ["/api/oauth/token"],
produces = ["application/json"])
fun auth(forms: Headers): Auth
} Headers class: class Headers() {
@JsonProperty("grant_type")
val grantType: String = GRANT_TYPE_STS
@JsonProperty("x-flow-ID")
val flowId = UUID.randomUUID().toString()
@JsonProperty("x-correlationID")
val correlationId = UUID.randomUUID().toString()
@JsonProperty("client_id")
var clientId: String = Strings.EMPTY
@JsonProperty("client_secret")
var clientSecret: String = Strings.EMPTY
constructor(clientId: String, clientSecret: String): this(){
this.clientId = clientId
this.clientSecret = clientSecret
}
companion object {
const val GRANT_TYPE_STS = "client_credentials"
}
} Produces class: class Auth() {
@JsonProperty("access_token")
var accessToken: String = Strings.EMPTY
@JsonProperty("token_type")
var tokenType: String = Strings.EMPTY
@JsonProperty("expires_in")
var expiresIn: Int = 0
@JsonProperty("refresh_token")
var refreshToken: String = Strings.EMPTY
var scope: String = Strings.EMPTY
var active: Boolean = true
} If someone knows any solution without use Encoder bean I'll be thankfull |
I hope this request has not been forgotten. |
I found this issue when using a Feign client in my Spring Boot project. I've tried to create a POJO with the parameters but I need them to be translated. For example, the property clientId needs to be "client_id". I've tried putting @JsonProperty and @param annotations in each field but they get ignored. |
If you're using Gson you should use the @SerializedName("access_token") property instead of the @JsonProperty. |
I figured it out using SpringFeign with some hectic java-based configuration. |
@yandinizzup I suspect the root cause for you is #77, which unfortunately isn't getting any attention. Spring boot correctly wired up the form encoder for me, and I didn't need to explicitly do anything for it in my configuration(s). But because class FormBody(
@FormProperty("the_name")
var theName: String
) |
in kotlin var saved my day. Thanks @upfluentpatrickpilch |
Is it possible to use feign-form's support for
application/x-www-form-urlencoded
forms with Spring Cloud's@EnableFeignClients
/@FeignClient
setup?Currently, I am getting the following exception when starting the
ApplicationContext
:To me, that is an indication that loading the
feign-form
support didn't quite work.I'm using
org.springframework.cloud:spring-cloud-starter-openfeign
,org.springframework.boot:spring-boot-starter
and fordependencyManagement
org.springframework.cloud:spring-cloud-dependencies:Greenwich.SR3
, all with aorg.springframework.boot:spring-boot-starter-parent:2.1.9.RELEASE
parent.My setup, running against a simple standalone wiremock with
--print-all-network-traffic
flag and a single simple mock:When I remove the Spring Cloud feign annotations (
@EnableFeignClients
,@FeignClient
) and replace both the autowiredmyClient
property inMyApp
withprivate MyClient myClient = Feign.builder().encoder(new FormEncoder()).target(MyClient.class, "http://localhost:8080");
and the@RequestMapping
annotation inMyClient
with@RequestLine("POST /foo")
, it all works.So, I know I haven't gone completely wrong. I'm basically just wondering if
feign-forms
support forapplication/x-www-form-urlencoded
forms can be made to work with Spring Cloud's@EnableFeignClients
/@FeignClient
magic (and I've made a mistake somewhere), or if the exception is to be expected?Also (and probably somewhat unrelated), would I have to use the
@Configuration
annotation on theMyClientConfig
class if I used the@FeignClient
annotation and wanted to refine the config programatically?The text was updated successfully, but these errors were encountered: