HTTP request with authentication: Migrate to new JSScripting

Hi all

I have already migrated all my rules to new ECMAScript-2021. But here I’m stuck:

var client = java.net.http.HttpClient.newBuilder().build();
function httpGet(uri) {
  try {
    var request = java.net.http.HttpRequest.newBuilder()
      .GET()
      .uri(java.net.URI.create(uri))
      .header("Authorization", "Bearer XXX")
      .header("Content-Type", "application/json")
      .build();
    var response = client.send(request, java.net.http.HttpResponse.BodyHandlers.ofString());
    // print(response.body());
    return response;
  } catch (e) {
    print(e);
  }
}

var result = JSON.parse(httpGet("https://XXX").body());

Example is from here:

This is the error I get in Log with 1:1 copy:

Failed to execute script:
org.graalvm.polyglot.PolyglotException: java.lang.IllegalStateException: java.lang.IllegalAccessException: access to public member failed: jdk.internal.net.http.HttpRequestBuilderImpl.GET[Ljava.lang.Object;@182b34d/invokeVirtual, from public Lookup

Any help is appreciated :slight_smile:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.