1

Use Case

I have following rest client

@RegisterRestClient(configKey = "service")
public interface Service {

  @POST
  @Path("Invoice")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  Response request(@QueryParam("instance") String instance, @BeanParam Input input);

}

Input is a class which is a POJO including properties like

public class Input {

  @FormParam("title")
  public String title;

  @FormParam("description")
  public String description;

Problem

The request to the API is working fine, but in my case, the order of properties does matter (The reason behind that is something, I cannot answer at the moment, sorry).

So sending title=Test&description=Testdescription is different to description=Testdescription&title=Test.

Other solutions I have tried

  1. With Form instead of POJO: No data is send to the server
  @POST
  @Path("Invoice")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  CustomResponse requestForm(@QueryParam("instance") String instance, @BeanParam Form form);
  1. With Entit<Form>: No data is send to the server
  @POST
  @Path("Invoice")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  CustomResponse requestForm(@QueryParam("instance") String instance, @BeanParam Entity<Form> form);

Assumption

I found out, that org.jboss.resteasy.client.jaxrs.internal.proxy.processors.FormProcessor is using a HashMap internally. I think that is exactly the problem, because there is no guaranteed order. Is my assumption correct?

Question

How can I work around that and always provide the same order for the API using the Microprofile Rest Client.

Workaround

It works with a org.jboss.resteasy.client.jaxrs.ResteasyClient invoking like

 Response response = target
            .request(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_FORM_URLENCODED)
            .post(Entity.form(form));
alexander
  • 1,191
  • 2
  • 20
  • 40
  • 1
    probably the http standard doesn't guarantee order, so the fact that it works with the jboss resteasy client is luck. the fact that the server relies on ordering is probably not conform with the specs. – Ant Kutschera Jan 08 '22 at 19:13

1 Answers1

1

It's works for me, see:

@POST
@Path(value = "/auth/realms/{realm}")
@Consumes(APPLICATION_FORM_URLENCODED_VALUE)
    AuthenticateResponse authenticate(@PathParam("realm") String realm, MultivaluedMap<String,?> params);

Try to use MultivaluedMap