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

Support for multi valued query parameter expressed as q=1&q=2&q=3 #67

Closed
natros opened this issue Mar 6, 2021 · 7 comments
Closed

Support for multi valued query parameter expressed as q=1&q=2&q=3 #67

natros opened this issue Mar 6, 2021 · 7 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@natros
Copy link

natros commented Mar 6, 2021

Using this example

@RequestFactory
@Path("/users")
@Produces("application/json")
@Consumes("application/json")
public interface UserResource {
  @GET
  List<UserDto> getUsers(@QueryParam("type") List<UserType> userType);
}

where UserType is declared as

enum UserType {
  TYPE_A,
  TYPE_B
}

Domino-Rest encodes this as http://localhost/api/users?userType=[TYPE_A,TYPE_B] that cannot be handled by RestEasy (my backend). For reference how RestEasy handle multivalued query parameters https://docs.jboss.org/resteasy/docs/3.6.0.Final/userguide/html/StringConverter.html#d4e1570 (28.4 and 28.4.1)

RestyGwt translates this to http://localhost/api/users?userType=TYPE_A&userType=TYPE_B that works perfectly with RestEasy

@vegegoku vegegoku self-assigned this Mar 24, 2021
@vegegoku vegegoku added the bug Something isn't working label Mar 24, 2021
@vegegoku vegegoku added this to the 1.0 milestone Mar 24, 2021
@vegegoku
Copy link
Member

fixed in 25b5b68

@vegegoku
Copy link
Member

@natros If you can please test this on the latest HEAD-SNAPSHOT and confirm it is working we can start working on pushing a new release

@natros
Copy link
Author

natros commented Mar 24, 2021

Hi,

I did some tests, but there is one thing that is not working properly

Taking the following case

@RequestFactory
@Path("auth")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface AuthResource {
  @PUT
  @Nullable
  UserDto becomeUser(String login);
}

when calling AuthResourceFactory.INSTANCE.becomeUser("foo").onSuccess(callback).send(), the server gets ""foo"" instead of "foo"

Is there any flag that changes this or it's a bug?

With firefox
image
image

Google chrome:
image
image

@vegegoku
Copy link
Member

Can you please share the generated request class for that interface?

@vegegoku
Copy link
Member

After some research and trying with different clients I had the following observations :

  • "foo" is the correct representation of the string value as a JSON
    image
    this was observed in more than one JSON (de)serialization tool.

  • Tested with different REST clients and any client that would try to serialize the string as a JSON well end up with the same results as domino-rest, and any client that will just dump the text without verifying it is a valid JSON will end up with the same result as restygwt.

  • If the server is expecting a JSON and received foo instead of "foo" it is supposed to fail to parse it.

  • To send the value as is foo and not "foo" MediaType.TEXT_PLAIN should be used instead of the MediaType.APPLICATION_JSON

Note : We still don't support Consumes/Produce on interface level, but it should be trivial to add, should work on this very soon

@natros
Copy link
Author

natros commented Mar 24, 2021

With domino-rest

curl 'http://localhost:7021/docs/api/auth' \
  -X 'PUT' \
  -H 'Connection: keep-alive' \
  -H 'sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"' \
  -H 'Accept: application/json' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4457.0 Safari/537.36' \
  -H 'Content-type: application/json' \
  -H 'Origin: http://localhost:7021' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Referer: http://localhost:7021/docs/' \
  -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \
  -H 'Cookie: JSESSIONID=node01uksar4qqu6w01vce7ygh3q3z70.node0' \
  --data-raw '"filipe"' \
  --compressed

and with restygwt using the same interface

curl 'http://localhost:7021/docs/api/auth' \
  -X 'PUT' \
  -H 'Connection: keep-alive' \
  -H 'sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"' \
  -H 'Accept: application/json' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4457.0 Safari/537.36' \
  -H 'X-HTTP-Method-Override: PUT' \
  -H 'Content-Type: application/json' \
  -H 'Origin: http://localhost:7021' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Referer: http://localhost:7021/docs/' \
  -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \
  -H 'Cookie: JSESSIONID=node02wq7sgn5dnnv22qkbm8w1ifl0.node0' \
  --data-raw 'filipe' \
  --compressed

the server code remains unchanged.

@vegegoku
Copy link
Member

With domino-rest

curl 'http://localhost:7021/docs/api/auth' \
  -X 'PUT' \
  -H 'Connection: keep-alive' \
  -H 'sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"' \
  -H 'Accept: application/json' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4457.0 Safari/537.36' \
  -H 'Content-type: application/json' \
  -H 'Origin: http://localhost:7021' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Referer: http://localhost:7021/docs/' \
  -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \
  -H 'Cookie: JSESSIONID=node01uksar4qqu6w01vce7ygh3q3z70.node0' \
  --data-raw '"filipe"' \
  --compressed

and with restygwt using the same interface

curl 'http://localhost:7021/docs/api/auth' \
  -X 'PUT' \
  -H 'Connection: keep-alive' \
  -H 'sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"' \
  -H 'Accept: application/json' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4457.0 Safari/537.36' \
  -H 'X-HTTP-Method-Override: PUT' \
  -H 'Content-Type: application/json' \
  -H 'Origin: http://localhost:7021' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Referer: http://localhost:7021/docs/' \
  -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \
  -H 'Cookie: JSESSIONID=node02wq7sgn5dnnv22qkbm8w1ifl0.node0' \
  --data-raw 'filipe' \
  --compressed

the server code remains unchanged.

What I am saying is that what is domino-rest doing not wrong, it is making sure that since you are sending a json it should be valid json and encode the request accordingly, restygwt does check for valid json, this means that restygwt is expecting the server to understand that the not JSON body is a son, so this might depend on the server implementation. and might fail for some servers that does not accept a non-valid json. e.g : vertx HttpServer

If the String method argument is a josn then you need to write to the body as a String without encoding it as a JSON, you can do this by providing a @RequestWriter to the method, we already have a built in one org.dominokit.rest.shared.request.StringWriter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants