IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

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
Expand all | Collapse all

Excel File Upload Via DSP

  • 1.  Excel File Upload Via DSP

    Posted Mon May 29, 2017 05:59 AM

    Hi Team,

    I am trying to upload an excel file from a DSP page and then parse the file using Apache POI jars and insert the data in DB. The issue is the excel content is not getting passed to the IS service from the DSP page. Below is the DSP code.

    Welcome To The Excel File Upload Page .

    <form name="connectForm" id="connectForm" action="fileStatus.dsp" enctype="multipart/form-data" method="POST">
    
    
    <table>
    
    <tr>
    <td><b><font color="red">Select Input File (.xlsx)</font></b></td>
    <td>
    <input type="file" name="fileData" id="fileData" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
    </td>
    </tr>
    <tr>
    <td></td>
    </tr>
    <tr>
    <td></td>
    </tr>
    <tr>
    <td><input type="image" src="images/submit-button.png" width="95" height="20"/></td>
    </tr>
    </table>
    <br/>
    <br/>
    
    </form>
    </BODY>
    </HTML>
    

    This dsp is routing it to the “fileStatus.dsp” where I am calling a flow service. Please see the HTML below.

    File Status

    %invoke excelUtility.flowServices.dsp:readExcelWrapper%
    
    %ifvar fileReadStatus equals('success')%
    
    <table border="1">
    <tr>
    <td>File Status</td><td>File uploaded successfully</td>
    </tr>
    
    </table>
    
    %endinvoke%
    
    
    
    </BODY>
    </HTML>
    

    Kindly please help.

    Regards
    Abir Banerjee


    #webMethods-General
    #webMethods
    #Integration-Server-and-ESB


  • 2.  RE: Excel File Upload Via DSP

    Posted Tue May 30, 2017 11:03 AM

    Hi Team,

    The issue is primarily resolved. The data is coming to the flow service from browser. However , the InputStream data is getting corrupted during transfer.
    This is mainly happening for excel files. The code works fine for pdf,txt,jpg files. Anyone if you have faced this please share your inputs on this.

    Regards
    Abir


    #Integration-Server-and-ESB
    #webMethods-General
    #webMethods


  • 3.  RE: Excel File Upload Via DSP

    Posted Tue May 30, 2017 11:54 AM

    Hi Abir,

    might it be that an Excel file contains some characters which are not valid for transport at this place.

    There is a Sample in the Samples Section of TechCommunity.
    You might to check it out to see if this one can handle Excel files correctly.

    Regards,
    Holger


    #Integration-Server-and-ESB
    #webMethods
    #webMethods-General


  • 4.  RE: Excel File Upload Via DSP

    Posted Tue May 30, 2017 12:36 PM

    Hi Holger,

    Thanks for your response. Are you referring to the below sample?

    http://techcommunity.softwareag.com/ecosystem/communities/public/webmethods/products/esb_and_integration/codesamples/2595931b-b1d4-11e4-8d00-cd8d7ef22065/?title=Saving+file%2Fattachment+from+a+HTTP+Post+based+on+file+size+restrictions

    Well I have tried this one also. When I am doing a http post using “pub.client:http” by passing the excel file , it is working file , the excel is getting successfully written in the receiver server and I am able to open the file. The issue is when I use the HTML page to pass the file to the receiver server. I even added the below mime type in the settings (Resources>Mime Types), still the InputStream gets corrputed. Sending from browser seems to be the issue. The same dsp successfully uploads pdf,txt,jpg files , but not xlsx.

    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx

    Please find the dsp code.

    Welcome To The Excel File Upload Page .

    <form name="connectForm" id="connectForm" action="/invoke/excelUtility.flowServices.dsp:readExcelWrapper" enctype="multipart/form-data" method="POST">
    
    
    
    <table>
    
    <tr>
    
    <td><b><font color="red">Select Input File (.xlsx)</font></b></td>
    <td>
    <input type="file" name="fileData" id="fileData" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
    
    
    </td>
    </tr>
    
    <tr>
    <td></td>
    </tr>
    <tr>
    <td></td>
    </tr>
    <tr>
    <td><input type="image" src="images/submit-button.png" width="95" height="20"/></td>
    </tr>
    </table>
    <br/>
    <br/>
    
    </form>
    
    
    
    </BODY>
    </HTML>
    

    The receiving service has “contentStream” as input and I am writing the stream to a file in disk. The snapshot of the code is provided as attachment.

    Regards
    Abir Banerjee

    Capture.JPG


    #webMethods
    #webMethods-General
    #Integration-Server-and-ESB


  • 5.  RE: Excel File Upload Via DSP

    Posted Tue May 30, 2017 03:56 PM

    Hi Abir,

    as trying to point out earlier, Excel (xslx) files might contain characters which cause the stream to get closed during transmission before the file is complete.

    Regards,
    Holger


    #Integration-Server-and-ESB
    #webMethods-General
    #webMethods


  • 6.  RE: Excel File Upload Via DSP

    Posted Wed May 31, 2017 06:27 AM

    Hi Holger,

    I am trying a very simple excel file.There are no special characters in the file. I am attaching the same.
    Kindly take a look.

    Regards
    Abir
    test123.zip (5.73 KB)


    #webMethods
    #webMethods-General
    #Integration-Server-and-ESB


  • 7.  RE: Excel File Upload Via DSP

    Posted Wed May 31, 2017 12:51 PM

    Hi Abir,

    the problem is not with the visible data you enter in the Excel file, instead it is intrinsic caused by th fiile format xlax.

    When opening the file with an editor which can display control charactes (like Notepad++) you will see the culprit.
    There are some control characters among them which cause the stream to be closed before the file is transferred completey.

    Regards,
    Holger


    #webMethods-General
    #Integration-Server-and-ESB
    #webMethods


  • 8.  RE: Excel File Upload Via DSP

    Posted Wed May 31, 2017 01:27 PM

    Hi Holger,

    Is there any workaround/solution for this? As the scenario is working fine when I am using pub.client:http service to send the data. Only when browser is involved , I am seeing this issue and that too for excel files. For pdf , txt ,jpg its working absolutely fine. Is there any content-type/content-handler setting that I can do to correct this?

    Regards
    Abir Banerjee


    #Integration-Server-and-ESB
    #webMethods-General
    #webMethods


  • 9.  RE: Excel File Upload Via DSP

    Posted Wed February 28, 2018 03:54 AM

    Hi Abir,

    You may try using “.xls” excel file in the DSP page while uploading.

    Regards,
    AG


    #webMethods-General
    #Integration-Server-and-ESB
    #webMethods


  • 10.  RE: Excel File Upload Via DSP

    Posted Mon December 03, 2018 07:52 AM

    As I have been searching for this … and I couldn’t find good solution - I’ll give you my example.

    The DSP page:

    Choose file:

    The webMethods part:

    1. pub.flow:getTransportInfo
    2. pub.mime:mergeHeaderAndBody
      map contentStream to body/stream and transport/http/requestHdrs to headerLines
    3. pub.mime:createMimeData
      map stream to input
    4. pub.mime:getNumParts
    5. pub.mime:getBodyPartHeader
      from there you can take mimeHeader/Content-Disposition and parse it to get file name
    6. pub.mime:getBodyPartContent
      index 0 will give you content of the file
    7. write steam into the file. That I’ve written in Java.

    Java service:
    String fileName = IDataUtil.getString( pipeline.getCursor(), “filename” );
    InputStream in = (InputStream) IDataUtil.get( pipeline.getCursor(), “data” );
    // pipeline
    try {
    OutputStream out = new FileOutputStream(fileName);
    // Transfer bytes from in to out
    byte buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    }
    in.close();
    out.close();
    }
    catch (Exception e) {throw new ServiceException(e);}

    Hope it will help something in future :slight_smile:

    Regards,
    ?ukasz Konkol


    #webMethods-General
    #webMethods
    #Integration-Server-and-ESB