I have a @GET method that takes a static query parameter called operation, but I also want to accept a variable number of other query parameters with arbitrary names. My initial approach:
`
``java
public Response get(
@QueryParam("operation") String operation,
@QueryParam("list") final List<String> list) {
// do stuff
}
requires requests like: ...?operation=logging&list=ABC&list=XYZ. I want something more flexible: ...?operation=logging&anything=ABC&something_else=XYZ.
I found an alternative using UriInfo:
@GET
public void gettest(@Context UriInfo ui) {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
String operation = queryParams.getFirst("operation");
for (String theKey[quote="Apurvaugale, post:1, topic:47242, full:true"]
I’m trying to call `waitForNetworkIdle` twice in my Puppeteer test, but the second call throws a `Timeout cleared` error. Here’s the function I’m using:
```javascript
private async clickEnterButton() {
this.logger('Clicando em entrar')
await this.page.waitForSelector('#submit-button')
await this.page.click('#submit-button')
await this.page.waitForNetworkIdle()
}
I’ve tried calling waitForNetworkIdle outside the function and also changing Node and Puppeteer versions, but the issue persists.
How can I call waitForNetworkIdle multiple times without hitting a timeout?
[/quote]:
queryParams.keySet()) {
System.out.println(queryParams.getFirst(theKey));
// handle other query params
}
}
Is using MultivaluedMap the recommended way to handle variable query parameter names, or is there a better approach?
Yes, using @Context UriInfo with getQueryParameters() is the standard way to handle dynamic or variable query parameters in JAX-RS:
@GET
public Response get(@Context UriInfo uriInfo) {
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
String operation = queryParams.getFirst("operation");
queryParams.forEach((key, values) -> {
System.out.println(key + " = " + values);
});
return Response.ok().build();
}
This gives you all query parameters, including unknown or variable ones, in a clean, iterable structure. I usually use this approach whenever query parameters aren’t fixed.
If you prefer working with a plain Map, you can convert MultivaluedMap to a normal Map<String, String> (or Map<String, List>) for easier handling:
@GET
public Response get(@Context UriInfo uriInfo) {
Map<String, List<String>> queryParams = uriInfo.getQueryParameters();
String operation = queryParams.getOrDefault("operation", List.of()).stream().findFirst().orElse(null);
queryParams.forEach((key, values) -> {
System.out.println(key + " = " + values);
});
return Response.ok().build();
}
This variation keeps the code readable and still allows you to handle any number of dynamic query parameters.
If you have some fixed query parameters (like operation) but also want dynamic ones, you can mix @QueryParam for known parameters and UriInfo for the rest:
@GET
public Response get(@QueryParam("operation") String operation, @Context UriInfo uriInfo) {
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
queryParams.entrySet().stream()
.filter(entry -> !entry.getKey().equals("operation"))
.forEach(entry -> System.out.println(entry.getKey() + " = " + entry.getValue()));
return Response.ok().build();
}
This approach makes your fixed parameters explicit in the method signature while still supporting variable parameters dynamically.
I use this pattern a lot because it keeps critical params clear but doesn’t block flexibility.