I am using WebTarget to send a GET request with query params.
This is my expected request that I need to generate:
{{host}}/svc/lookupservice/v2/findItems?filter=creationdate:[2020-05-01T00:08:17.000Z..]&limit=25&offset=0&userType=seller&userid=11234567
But using webtarget as follows:
import javax.ws.rs.client.Client;
...
...
class A {
private Client client;
public void apiCall(String userId, String startDate, String endDate) {
String endpoint = (String)this.client.getConfiguration().getProperty("jaxrs.client.endpointuri");
WebTarget webTarget = this.client.target(endpoint).path("/lookupservice/v2/findItems")
.queryParam("userType", new Object[]{"seller"})
.queryParam("sort", new Object[]{"creationdate"})
.queryParam("limit", new Object[]{150})
.queryParam("offset", new Object[]{0})
.queryParam("filter", new Object[]{"creationdate:[" + startDate + ".." + endDate + "]"})
.queryParam("userid", new Object[]{userId});
...
}
...
}
class B {
main(..) {
Date endDate = new Date();
Date startDate = new Date(endDate.getTime() - Duration.ofDays(30).toMillis());
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
sDate = formatter.format(startDate);
eDate = formatter.format(endDate);
new A().apiCall(userId, sDate, eDate);
}
}
And this above generates webTarget url as
JerseyWebTarget { https://svc1.abc.qa.def.com/svc/lookupservice/v2/findItems?userType=seller&sort=creationdate&limit=150&offset=0&filter=creationdate%3A%5B2022-03-08T15%3A26%3A35.951Z..2022-04-07T16%3A26%3A35.951Z%5D&userid=1005732584 }
It encodes :[
in creation date.
How can I avoid it?
Figured out by not using webTarget's .queryParams()
and instead passing URI with query.
String query = "?userType=seller&limit=25&offset=0&userid=" + userId + "&filter=creationdate:[" + startDate + ".." + endDate + "]";
URI uri = URI.create(endpoint + "/lookupservice/v2/findItems"+ query);
WebTarget webTarget = client.target(uri);