File Upload Automation to IBM Security Identity Governance and Intelligence
up vote
0
down vote
favorite
I trying to write a javascript that will automatically upload the CSV file using the application rest API service. I have tested the API using Postman and it works, the file is successfully uploaded to the application. However, it doesn't seem to be working when I tried to compile and execute the program in java eclipse. Can anyone please give me advice if the issue is with my code or there is something else that I am missing?
Postman testing screenshot:
enter image description here
Below is the java script:
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
public class Main_Class {
public static void main(String args)
{
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
{
System.out.println("The abs path of the file is"+file);
while(true) //checking the file status for arrival of big file size
{
String f = file.toString();
File file1 = new File(f);
if ( file1.exists())
{
RandomAccessFile statusCheck = null;
try
{
statusCheck = new RandomAccessFile(file1,"r");
if(statusCheck != null)
{
//start here <------
System.out.println("New file detected. Intiating IGI REST API call...");
statusCheck.close();
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("multipart/form-data");
String bodystr = "------WebKitFormBoundary7MA4YWxkTrZu0gW"
//content of the csv place into this mediaType
+ "Content-Disposition: form-data; name="uploadedFiles"; filename="C:\Downloads\SampleCSVFile.csv""
+ "Content-Type: text/csv"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="name""
+ "SampleCSVFile.csv"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="type""
+ "file"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="relativePath""
+ "connectors/CSV/"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW--";
//create mediatype
//this is api request body
RequestBody body = RequestBody.create(mediaType, bodystr);
Request request = new Request.Builder()
.url("https://192.168.0.125:9443/v1/customfiles")
.post(body)
.addHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW")
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Basic YWRtaW46UGFzc3cwcmQh")
//.addHeader("Cache-Control", "no-cache")
//.addHeader("Postman-Token", "81299ae7-0ed5-4365-8003-65162ae118b1")
.build();
Response response = client.newCall(request).execute();
System.out.println("RESPONSE CODE:" + response.toString());
if(response.toString().contains("200"))
{
Path path = Paths.get("C:\Downloads\SampleCSVFile.csv");
Files.delete(path);
System.out.println("Successfully deleted the processed file");
}
}
break;
}catch(Exception e)
{
System.out.println("In processing : " + e.getMessage());
}
}
}
}
}
java file-upload automation
add a comment |
up vote
0
down vote
favorite
I trying to write a javascript that will automatically upload the CSV file using the application rest API service. I have tested the API using Postman and it works, the file is successfully uploaded to the application. However, it doesn't seem to be working when I tried to compile and execute the program in java eclipse. Can anyone please give me advice if the issue is with my code or there is something else that I am missing?
Postman testing screenshot:
enter image description here
Below is the java script:
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
public class Main_Class {
public static void main(String args)
{
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
{
System.out.println("The abs path of the file is"+file);
while(true) //checking the file status for arrival of big file size
{
String f = file.toString();
File file1 = new File(f);
if ( file1.exists())
{
RandomAccessFile statusCheck = null;
try
{
statusCheck = new RandomAccessFile(file1,"r");
if(statusCheck != null)
{
//start here <------
System.out.println("New file detected. Intiating IGI REST API call...");
statusCheck.close();
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("multipart/form-data");
String bodystr = "------WebKitFormBoundary7MA4YWxkTrZu0gW"
//content of the csv place into this mediaType
+ "Content-Disposition: form-data; name="uploadedFiles"; filename="C:\Downloads\SampleCSVFile.csv""
+ "Content-Type: text/csv"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="name""
+ "SampleCSVFile.csv"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="type""
+ "file"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="relativePath""
+ "connectors/CSV/"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW--";
//create mediatype
//this is api request body
RequestBody body = RequestBody.create(mediaType, bodystr);
Request request = new Request.Builder()
.url("https://192.168.0.125:9443/v1/customfiles")
.post(body)
.addHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW")
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Basic YWRtaW46UGFzc3cwcmQh")
//.addHeader("Cache-Control", "no-cache")
//.addHeader("Postman-Token", "81299ae7-0ed5-4365-8003-65162ae118b1")
.build();
Response response = client.newCall(request).execute();
System.out.println("RESPONSE CODE:" + response.toString());
if(response.toString().contains("200"))
{
Path path = Paths.get("C:\Downloads\SampleCSVFile.csv");
Files.delete(path);
System.out.println("Successfully deleted the processed file");
}
}
break;
}catch(Exception e)
{
System.out.println("In processing : " + e.getMessage());
}
}
}
}
}
java file-upload automation
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I trying to write a javascript that will automatically upload the CSV file using the application rest API service. I have tested the API using Postman and it works, the file is successfully uploaded to the application. However, it doesn't seem to be working when I tried to compile and execute the program in java eclipse. Can anyone please give me advice if the issue is with my code or there is something else that I am missing?
Postman testing screenshot:
enter image description here
Below is the java script:
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
public class Main_Class {
public static void main(String args)
{
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
{
System.out.println("The abs path of the file is"+file);
while(true) //checking the file status for arrival of big file size
{
String f = file.toString();
File file1 = new File(f);
if ( file1.exists())
{
RandomAccessFile statusCheck = null;
try
{
statusCheck = new RandomAccessFile(file1,"r");
if(statusCheck != null)
{
//start here <------
System.out.println("New file detected. Intiating IGI REST API call...");
statusCheck.close();
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("multipart/form-data");
String bodystr = "------WebKitFormBoundary7MA4YWxkTrZu0gW"
//content of the csv place into this mediaType
+ "Content-Disposition: form-data; name="uploadedFiles"; filename="C:\Downloads\SampleCSVFile.csv""
+ "Content-Type: text/csv"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="name""
+ "SampleCSVFile.csv"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="type""
+ "file"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="relativePath""
+ "connectors/CSV/"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW--";
//create mediatype
//this is api request body
RequestBody body = RequestBody.create(mediaType, bodystr);
Request request = new Request.Builder()
.url("https://192.168.0.125:9443/v1/customfiles")
.post(body)
.addHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW")
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Basic YWRtaW46UGFzc3cwcmQh")
//.addHeader("Cache-Control", "no-cache")
//.addHeader("Postman-Token", "81299ae7-0ed5-4365-8003-65162ae118b1")
.build();
Response response = client.newCall(request).execute();
System.out.println("RESPONSE CODE:" + response.toString());
if(response.toString().contains("200"))
{
Path path = Paths.get("C:\Downloads\SampleCSVFile.csv");
Files.delete(path);
System.out.println("Successfully deleted the processed file");
}
}
break;
}catch(Exception e)
{
System.out.println("In processing : " + e.getMessage());
}
}
}
}
}
java file-upload automation
I trying to write a javascript that will automatically upload the CSV file using the application rest API service. I have tested the API using Postman and it works, the file is successfully uploaded to the application. However, it doesn't seem to be working when I tried to compile and execute the program in java eclipse. Can anyone please give me advice if the issue is with my code or there is something else that I am missing?
Postman testing screenshot:
enter image description here
Below is the java script:
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
public class Main_Class {
public static void main(String args)
{
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
{
System.out.println("The abs path of the file is"+file);
while(true) //checking the file status for arrival of big file size
{
String f = file.toString();
File file1 = new File(f);
if ( file1.exists())
{
RandomAccessFile statusCheck = null;
try
{
statusCheck = new RandomAccessFile(file1,"r");
if(statusCheck != null)
{
//start here <------
System.out.println("New file detected. Intiating IGI REST API call...");
statusCheck.close();
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("multipart/form-data");
String bodystr = "------WebKitFormBoundary7MA4YWxkTrZu0gW"
//content of the csv place into this mediaType
+ "Content-Disposition: form-data; name="uploadedFiles"; filename="C:\Downloads\SampleCSVFile.csv""
+ "Content-Type: text/csv"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="name""
+ "SampleCSVFile.csv"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="type""
+ "file"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW"
+ "Content-Disposition: form-data; name="relativePath""
+ "connectors/CSV/"
+ "------WebKitFormBoundary7MA4YWxkTrZu0gW--";
//create mediatype
//this is api request body
RequestBody body = RequestBody.create(mediaType, bodystr);
Request request = new Request.Builder()
.url("https://192.168.0.125:9443/v1/customfiles")
.post(body)
.addHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW")
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Basic YWRtaW46UGFzc3cwcmQh")
//.addHeader("Cache-Control", "no-cache")
//.addHeader("Postman-Token", "81299ae7-0ed5-4365-8003-65162ae118b1")
.build();
Response response = client.newCall(request).execute();
System.out.println("RESPONSE CODE:" + response.toString());
if(response.toString().contains("200"))
{
Path path = Paths.get("C:\Downloads\SampleCSVFile.csv");
Files.delete(path);
System.out.println("Successfully deleted the processed file");
}
}
break;
}catch(Exception e)
{
System.out.println("In processing : " + e.getMessage());
}
}
}
}
}
java file-upload automation
java file-upload automation
edited Nov 9 at 9:14
Elham Esmaeeli
795
795
asked Nov 9 at 7:54
Nyleve
11
11
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53221752%2ffile-upload-automation-to-ibm-security-identity-governance-and-intelligence%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown