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());

}
}
}
}
}









share|improve this question




























    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());

    }
    }
    }
    }
    }









    share|improve this question


























      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());

      }
      }
      }
      }
      }









      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 9:14









      Elham Esmaeeli

      795




      795










      asked Nov 9 at 7:54









      Nyleve

      11




      11





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Landwehr

          Reims

          Schenkenzell