OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.36k stars 1.91k forks source link

@FormParam of jaxrs cannot pass arguments #2135

Open zhanjinhao opened 12 months ago

zhanjinhao commented 12 months ago

jaxrs version: 3.0.7.Final feign version: 11.10

I want to use @FormParam to pass arguments, and this is my code :

server:

    @POST
    @Path("/system/authentication/findGroupByUserName")
    List<Group> findGroupByUserName(@FormParam("username") String string);

client, service:

    @POST
    @Path("/system/authentication/findGroupByUserName")
    @Headers(value = {" content-type : application/x-www-form-urlencoded "})
    List<Group> findGroupByUserName(@FormParam("username") String string);

client feign builder:

  Feign.builder()
            // required values 
            .logger(new Slf4jLogger(type))
            .client(new ApacheHttpClient(HttpClientUtils.getHttpClient()))
            .contract(new JAXRSContract())
            .encoder(new JacksonEncoder())
            .decoder(new JacksonDecoder())
            .options(options);

My JAXRSContract class is copy from feign-jaxrs peoject and I wrote some code so that it can parse the @Headers annotation. Now my issue is that the argument usename is encode to json instead of form. I have traced the code and found the code below : feign.jackson.JacksonEncoder#encode image

The data format of the form is: username = '123456', but the data format of the json is {"username":"123456"}. So how can i config the feign builder to make it work , or is there some other solutions.

Thanks !

gromspys commented 9 months ago

@Headers(value = {" content-type : application/x-www-form-urlencoded "})

jaxrs version: 3.0.7.Final feign version: 11.10

I want to use @FormParam to pass arguments, and this is my code :

server:

    @POST
    @Path("/system/authentication/findGroupByUserName")
    List<Group> findGroupByUserName(@FormParam("username") String string);

client, service:

    @POST
    @Path("/system/authentication/findGroupByUserName")
    @Headers(value = {" content-type : application/x-www-form-urlencoded "})
    List<Group> findGroupByUserName(@FormParam("username") String string);

client feign builder:

  Feign.builder()
            // required values 
            .logger(new Slf4jLogger(type))
            .client(new ApacheHttpClient(HttpClientUtils.getHttpClient()))
            .contract(new JAXRSContract())
            .encoder(new JacksonEncoder())
            .decoder(new JacksonDecoder())
            .options(options);

My JAXRSContract class is copy from feign-jaxrs peoject and I wrote some code so that it can parse the @Headers annotation. Now my issue is that the argument usename is encode to json instead of form. I have traced the code and found the code below : feign.jackson.JacksonEncoder#encode image

The data format of the form is: username = '123456', but the data format of the json is {"username":"123456"}. So how can i config the feign builder to make it work , or is there some other solutions.

Thanks !

Not sure that you need to copy JAXRSContract contract to support @Headers annotation. If you want to add content-type to the header you can use @Consumes annotation.