I'am trying to send a request to a REST interface implemented with javax.ws.rs and give it some query params, but the query params do not reach the interface.
The sending side is implemented as folowing:
WebTarget target = webTarget.path("test").path("Testuser");
target.queryParam("a","a");
System.out.println(target.getUri());
Response response = target.request().get();
The interface:
@GET
@Path("test/{username}")
public void test(
@PathParam("username") String username,
@QueryParam("a") String a) {
System.out.println("TEST here!");
System.out.println("username: " username);
System.out.println("a: " a);
}
The output on the sender side is the plain URL without any query parameter.
The output on the interface side is
TEST here!
username: Testuser
a: null
I'am not able to see, where my error is, and why the a is not recived in the interface.
CodePudding user response:
You're ignoring the result of the queryParam method. The method doesn't modify the existing instance - it returns a new one, just like path does. From the docs:
Create a new WebTarget instance by configuring a query parameter on the URI of the current target instance.
Just change your code to:
WebTarget target = webTarget.path("test").path("Testuser").queryParam("a", "a");
