webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Not able to read file using java service

    Posted Thu November 12, 2020 04:11 AM

    Hi All,

    I need to replace a csv file on unix with xlsx file. I have created a java service and I am using opencsv to read the csv file. I am able to read the file locally and convert it to xlsx but when I give the complete unix path, it gives me an error that the system cannot find the path specified.

    Below are the 3 approaches I have tried separately. csvFilePath is a string variable that has the path /home/file/abc.csv

    1. BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(csvFilePath)));
    2. FileReader fileReader= new FileReader(csvFilePath);
    3. I used pub.file:getFile to get the csv data in stream and then used pub.io:stringToReader to convert the stream in InputStreamReader object and passed this object to java service. This is how I am trying to fetch:

    InputStreamReader inputStreamReader = (InputStreamReader)IDataUtil.get( pipelineCursor, “reader” );

    I don’t want to mix flow service and java service and just want to do this job using one java service. Can anyone please tell me what wrong I am doing here?


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 2.  RE: Not able to read file using java service

    Posted Thu November 12, 2020 11:54 AM

    Hi Akshay,

    can you provide a more detailed outline of your processing please?

    CSV files can be read in by using FlatFile handling feature built-in to the IS.
    Which API are you using to create the xlsx files?

    What is your IS version?

    Regards,
    Holger


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 3.  RE: Not able to read file using java service

    Posted Thu November 12, 2020 02:21 PM

    I think you have to configure the IS so that it can read files in the desired directory via file:getFile. With a custom java service you can read any directory.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 4.  RE: Not able to read file using java service

    Posted Fri November 13, 2020 08:35 AM

    This will be the fileAccessControl.cnf in the WmPublic/config folder under the packages directory of the instance.

    Remember to reload the WmPublic-package after editing the CNF-Files under WmPublic/config-folder.

    Regards,
    Holger


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 5.  RE: Not able to read file using java service

    Posted Fri November 13, 2020 04:47 AM

    Thank you all for your suggestions. I am using WM 9.10 version. Earlier I was creating a csv file from json but now I need to send an xlsx file. My input is json that I get from calling a third party API. So I have been asked to keep everything same and convert the final csv file to xlsx file and delete the csv file. I want a single java service to do this rather than a combination of flow service and java service to read csv and write xlsx file. For this I am using apache poi for excel and opencsv jar to read csv.

    Today I am able to progress on reading the file.

    I used Path class from java.nio.file.Paths; package and converted it to path object
    Path path = Paths.get(csvFilePath);
    csvReader = new CSVReader(new FileReader (path.toString()));

    Now I am stuck at writing the excel file.
    Workbook workBook = new SXSSFWorkbook();
    SXSSFSheet sheet = (SXSSFSheet) workBook.createSheet(“Sheet”);----> giving null pointer exception

    This works fine on local and is successfully writing data to xlsx file however on unix filesystem I am getting null pointer exception.

    I used Workbook workBook = new XSSFWorkbook();-----> still it didn’t work
    but when I used Workbook workBook = new HSSFWorkbook();
    it worked and I was able to create xls file on server. However I need xlsx format

    As per the suggestion on xlsx - Apache POI SXSSFWorkbook createSheet() return NullPointerException - Stack Overflow
    I believe I need to install Microsoft fonts on unix server however network team has put an ACL and I cant install it.

    Do you think If I get the approval to install font, it will resolve my issues? Does anybody has any better approach for example script? I am not able to understand why xls file gets created but not xlsx. I have imported all correct jars and classes of apache poi framework.

    import org.apache.poi.xssf.usermodel.*;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.ss.usermodel.CreationHelper;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.xssf.streaming.SXSSFSheet;
    import org.apache.poi.xssf.streaming.SXSSFWorkbook;

    Thanks in advance


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 6.  RE: Not able to read file using java service

    Posted Sat November 14, 2020 06:12 AM

    Thanks Holger.

    I am able to read file. For the xlsx issue I will open a new thread.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB