Click HERE to see how Saviynt Intelligence is transforming the industry. |
08/14/2024 08:52 PM - edited 08/14/2024 08:55 PM
Hi Team,
I have created a custom jar .. followed the document steps added it in under "External Jar" section
created a "invoke jar job. Currently as a test i am just trying to get the access token from my saviynt environment (that is not the complete use case)
I code see below statement getting executed in logs but nothing else and also gives no error
obj.info("testworkjarexecute");
Code-
import java.util.Base64;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.logging.*;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
//import com.google.gson.JsonObject;
//import com.google.gson.Gson;
public class Classcall {
public static void main(String[] args) throws Exception {
String accessToken = "";
try {
Logger obj= Logger.getLogger(Classcall.class.getName());
URL url = new URL("URL");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
obj.info("testworkjarexecute");
String requestBody = "{\"username\": \"username\", \"password\": \"password\"}";
byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
OutputStream os = conn.getOutputStream();
os.write(input, 0, input.length);
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
obj.info("--connresponsecode--"+conn.getResponseCode());
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output;
StringBuilder responseBuilder = new StringBuilder();
while ((output = br.readLine()) != null) {
responseBuilder.append(output);
}
br.close();
obj.info("executed till here");
obj.info("--Entering into main method of class ZipExtractor--"+responseBuilder.toString());
//accessToken = response.getAccessToken();
//System.out.println("token---------->" + accessToken);
conn.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}
FYI- I haven't added any saviynt certification in certificate management.
Could someone please help me out with this
Thanks
08/14/2024 09:26 PM
Share logs
08/14/2024 09:29 PM
@rushikeshvartak , logs consist of only 3 lines
Start externaljar job
Print statment testjarexecute
End job
That it..
08/14/2024 09:31 PM
Try below code.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.logging.*;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
public class Classcall {
public static void main(String[] args) throws Exception {
String accessToken = "";
Logger obj = Logger.getLogger(Classcall.class.getName());
try {
URL url = new URL("URL");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
obj.info("Connection initialized");
String requestBody = "{\"username\": \"username\", \"password\": \"password\"}";
byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
OutputStream os = conn.getOutputStream();
os.write(input, 0, input.length);
obj.info("Request body sent");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
obj.info("HTTP response code: " + conn.getResponseCode());
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output;
StringBuilder responseBuilder = new StringBuilder();
while ((output = br.readLine()) != null) {
responseBuilder.append(output);
}
br.close();
obj.info("Response received and read");
obj.info("Response: " + responseBuilder.toString());
conn.disconnect();
} catch (Exception e) {
obj.log(Level.SEVERE, "Exception occurred", e);
}
}
}
08/14/2024 10:23 PM
@rushikeshvartak , thanks .. have done a restart will update you .. in another 15-20 mins.
2) while importing I am having error in moduleinfo.java file and not importing that.. as jar is getting executed and I can see some details in logs i believe it should be alright.
08/15/2024 08:54 AM
Hi @rushikeshvartak ,
Trying to fetch response data so i have used JSONObject class and obviously added dependency in pom.xml file, can't we add Maven project in Saviynt External jar.. if not what is the is an alternative way.
08/15/2024 08:55 AM
08/15/2024 09:20 AM - edited 08/15/2024 10:13 AM
@rushikeshvartak just to clarify if I need to use jsonobject class so you mean I can't use it or I need to download seperate dependency file club it into the executable Java file and make one jar file?
@rushikeshvartak , if you can please guide me .. your help us much appreciated 🙂
Update: if we upload the dependency file as in jsonobject class jar file seperately will it work??
08/15/2024 10:16 AM
It will work
08/15/2024 10:22 AM
@rushikeshvartak , sorry what will work didn't get you ?
08/29/2024 06:01 PM
09/01/2024 10:44 PM
Hi @rushikeshvartak , let me try it.
08/16/2024 08:57 AM
Hello @NM ,
Try this :
There is no certificate needed for this.
Regards,
Rahul
Please accept this as solution & give kudos if it resolves your issue.