1

I am trying to fit my microprofile RestClient to make GET calls to an external API which expects the format of a date query in the following format:

https://some_uri/?query=date%3A%282022%5C-01%5C-01%29?&fmt=json

The above corresponds to a non-encoded uri of the form: date:(yyyy\-MM\-dd). I came across @Encoded for that purpose. I have defined my RestClient like so:

@RegisterRestClient
public interface MyService {

    @GET
    @Path("release/")
    @Encoded
    @Produces(MediaType.APPLICATION_FORM_URLENCODED)
    MyResponse getReleasesByQuery(
          @QueryParam("query") @Encoded String query,
          @QueryParam("fmt") String format
    );
}

which I invoke like this:

String encodeQuery(LocalDate date) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
    var formatted = formatter.format(date);
    var query = "date%3A%28" + formatted + "%29";  // corresponds to date:(yyyy-MM-dd)
    return query.replace("-", "%5C-");
}

myService.getReleasesByQuery(encodeQuery(Datetime.now()), "json")

However (when enabling the http logging) I see the following getting called instead:

GET /ws/2/service/?query=date%25253A%2525282022%255C-02%255C-12%252529&fmt=json

Which as far as I can tell does encode the % into the UTF counterpart (%25).

So essentially I want to disable the encoding and do it myself instead. Am I misusing or misunderstanding this somehow?

I am on Quarkus version 2.4.1.

jaivalis
  • 488
  • 4
  • 19
  • 2
    Does not `@Encoded` encode what you have just manually encoded? So would not simply removing the annotation (since you have already provided the encoded form) make it work? – Sıddık Açıl Feb 20 '22 at 16:34
  • You are actually right. Previously I was having issues with the backslash prior to the dashes. This seems to have been something else! – jaivalis Feb 20 '22 at 17:16

0 Answers0