Error during REST API call in Sailpoint using JDK17

Which IIQ version are you inquiring about?

Version 8.4

Share all details related to your problem, including any error messages you may have received.

I’m doing REST API call via a rule using the below code for it:

import java.net.URLConnection;
import java.net.HttpURLConnection;
import java.net.URL;

String urlString = “https:///hcmRestApi/resources/11.13.18.05/areasOfResponsibility”;
URL url = new URL(urlString);
// Open connection
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(“GET”);
String username = “”;
String password = “”;
String credentials = username + “:” + password;
String base64Credentials = Base64.getEncoder().encodeToString(credentials.getBytes());
connection.setRequestProperty(“Authorization”, "Basic " + base64Credentials);
int responseCode = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
connection.disconnect();
return responseCode;

I’m getting below error when I run the above rule.

Exception running rule: BeanShell script error: bsh.EvalError: Sourced file: inline evaluation of: import java.util.List; import sailpoint.tools.Util; import java.io.Buffered . . . '' : Error in method invocation: Cannot access method setRequestMethod(java.lang.String) in 'class sun.net. www.protocol.https.HttpsURLConnectionImpl' :java.lang.IllegalAccessException: class bsh.Reflect cannot access class sun.net. www.protocol.https.HttpsURLConnectionImpl (in module java.base) because module java.base does not export sun.net. www.protocol.https to unnamed module @5e46ca49 : at Line: 75 : in file: inline evaluation of: import java.util.List; import sailpoint.tools.Util; import java.io.Buffered . . . ‘’ : connection .setRequestMethod ( “GET” )

I noticed this error when we upgraded Java JDK11 to Java JDK17. The same rule was working fine when we were using Java JDK11.
Any suggestion on this error will be very helpful. Thanks in advance.

@LalithyaReddy
Try using below code and check if everything is working fine

import javax.net.ssl.HttpsURLConnection;


    String urlString = "Sample URL";
    URL url = new URL(urlString);
    // Open connection
    HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    String username = "";
    String password = "";
    String credentials = username + ":" + password;
    String base64Credentials = Base64.getEncoder().encodeToString(credentials.getBytes());
    connection.setRequestProperty("Authorization", "Basic " + base64Credentials);
    int responseCode = connection.getResponseCode();
    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String inputLine;
    StringBuilder response = new StringBuilder();
    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();
    connection.disconnect();
    return responseCode;

Error you are seeing is mostly due to change in JDK’s module system. Java introduced a module system that restricts access to internal APIs. The class sun.net.www.protocol.https.HttpsURLConnectionImpl you’re trying to access is an internal API, hence the access restriction.

Check if above works with JDK17 and let me know if still any help needed.

adding following to your application server/tomcat java options should resolve this issue

–add-opens=java.base/sun.net.www.protocol.https=ALL-UNNAMED

1 Like

Hi @iamksatish,

I tried using the code you mentioned but no luck. But adding –add-opens=java.base/sun.net.www.protocol.https=ALL-UNNAMED to Tomcat Java options solved my issue.

Thanks

Thank you @abhishek_chowdhury … adding “–add-opens=java.base/sun.net.www.protocol.https=ALL-UNNAMED” to Tomcat Java options solved my issue.

@LalithyaReddy
What is the error you got with the code

Using --add-opens may work but that’s not recommended approach as you are bypassing the restrictions of the Java module system for sun.net.www.protocol.https. It’s subject to change without notice, and using it can result in your code breaking when you upgrade Java.

Anyhow glad it worked for you with this for now, if possible let me know the error you encountered with the code, will try to assist

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