In sending HTTPS request using Javax webtarget client, how to avoid encoding of query params that contain ":["?

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 { } 

It encodes :[ in creation date.

How can I avoid it?

1 Answer

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); 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like