EGL Development User Group

EGL Development User Group

EGL Development User Group

The EGL Development User Group is dedicated to sharing news, knowledge, and insights regarding the EGL language and Business Developer product. Consisting of IBMers, HCL, and users, this community collaborates to advance the EGL ecosystem.

 View Only
Expand all | Collapse all

File Upload to IFS

Discussion Topic

Discussion TopicThu February 19, 2015 08:19 AM

Discussion Topic

Discussion TopicMon April 20, 2015 03:32 PM

  • 1.  File Upload to IFS

    Posted Tue February 17, 2015 08:19 AM

    Hi,

    is there an easy way to upload a File to the IFS with EGL?

    Our environment is :

    RBD 9.1

    WAS 8.5.5

    Power 7 / 8 with IBM I

     

    Thanks in advance

    Marcel-D


  • 2.  Re: File Upload to IFS

    Posted Thu February 19, 2015 08:19 AM

    Does anybody have an idea?

    Marcel-D


  • 3.  Re: File Upload to IFS

    Posted Thu February 19, 2015 12:56 PM

    You'll have to be more specific. Do you mean from a batch job, web service, web application? Rich UI? What's the application design?

    Dan

    dan_darnell


  • 4.  Re: File Upload to IFS

    Posted Thu February 19, 2015 03:59 PM

    I have created a drag and drop html5 Rich UI component to upload files to a servlet on Websphere.

    The servlet then calls a web service to add a record in the database (file id, description fields, upload date, ...) and stores the file on the filesystem.
    It returns the id of the file added to the database so the rich ui handler can take action on the file if needed.
    We chose not to allow the users to access the files directly, so there is a second servlet to return the file by the file id if neccssary.

    The widget has some other features like a progress bar, dropping multiple files and image preview (if an image is dropped of course).

    It is not that easy to set up, but when it's done it is realy easy to use in rich ui applications.
     

    It has been a great step forward for us to be able to store unstructured data in our ERP software. (images, documents, cad drawings, ...). This along with the user interface were the main selling point for migrating from our aging RPG3 code to EGL.

    I can provide further details and code examples if you are interested.

     

    Kind regards. 

    Bram_Callewaert


  • 5.  Re: File Upload to IFS

    Posted Fri February 20, 2015 02:04 AM

    Hi Dan,

    i mean from the Rich UI.

    Thanks Bram, but that is to complex!

    I just want to chose a file from the local file system with the Rich UI and upload it to the IFS.

    I have a File Dialog Widget but i dont know how to upload the selected file...

    Marcel-D


  • 6.  Re: File Upload to IFS

    Posted Fri February 20, 2015 08:25 AM

    Rui generates javascript which runs on the clients browser, and does not have access to write to the filesystem directly. It might be possible with javascript, but I think it would conflict with most browsers security settings.

    That's why we had to go through a web server to have file upload capabilities.

    If you find an easier way I am very interested in hearing about it.

    Kind regards,

    Bram_Callewaert


  • 7.  Re: File Upload to IFS

    Posted Fri February 20, 2015 08:32 AM

    Hi Bram,

    do you have an example for me?

    Kind regards.

    Marcel-D


  • 8.  Re: File Upload to IFS

    Posted Mon February 23, 2015 05:06 AM

    Hi Marcel,

    I have made some notes and added most of the code to the attached pdf.

    It's not a complete step by step tutorial, but I believe all the relevant code is there.

    Please let me know if you need me to go deeper into detail.

     

    Kind regards, 

     

    Bram

    Bram_Callewaert


  • 9.  Re: File Upload to IFS

    Posted Tue February 24, 2015 03:15 AM

    Hi Bram,

    thank you for the turorial.

    I have some problems with the 'BestandService'

    I created a SOAP service named 'BestandService' but the Java Servlet can't find the SOAP service...

    Screenshots attached...

    Marcel-D


  • 10.  Re: File Upload to IFS

    Posted Tue February 24, 2015 03:28 AM

    Hi Marcel,

    Bestandservice is a soap service to handle the business logic when adding a file to our ERP system. It is implemented in a web services project which generates a WSDL file. The service returns the ID and the path where the file is to be stored.

    In the separate servlet project you can then use this wsdl to add a web service client (file - new - web service client), which should create all the required classes to access the web service.

    If you don't require the business logic and database file data, you can ommit the service call in the servlet, and just store the file where you want on the IFS. This will simplify the project, but will remove some safety. (duplicate file names...)

    Bram

    Bram_Callewaert


  • 11.  Re: File Upload to IFS

    Posted Tue February 24, 2015 05:01 AM

    Hi Marcel,

    all our users have a personal folder on the IFS. This folder is mapped to a drive-letter when they login to Windows.
    That way users can save files on the IFS in a easy way, and our EGL (backend) application can access the files.

    Greetings Jeroen
    amITs

     

    Jerrycan


  • 12.  Re: File Upload to IFS

    Posted Tue February 24, 2015 07:12 AM

    Hi Jerry,

    yes that is the easiest way, but not the nicest...

    Thank you again Bram for your tutorial but your solution is to difficult and to complex for us.

     

    Greetings Marcel

    Marcel-D


  • 13.  Re: File Upload to IFS

    Posted Tue February 24, 2015 07:47 AM

    Indeed not the nicest way. But without access to the the local filesystem there are just a few options.

    We also use a servlet option for some local filesystem information, but such a servlet needs a certificate to be
    trusted for example.

    The nicest way i have seen is the way Synology (NAS) handles it.
    https://www.synology.com/en-global/dsm/5.1/live_demo

    I
    n the filestation system, there is a local tree where you can select multiple files to upload.
    But also in this professional solution, it is done with a Java servlet. 
     

    Jerrycan


  • 14.  Re: File Upload to IFS

    Posted Tue February 24, 2015 08:03 AM

    I searched for something like this:

    to upload one file to a fixed folder in the IFS

    Marcel-D

    Attachments



  • 15.  Re: File Upload to IFS

    Posted Tue February 24, 2015 08:45 AM

    That is basically how my solution started out. A simple form and an upload to a servlet.

    The servlet got more complex because I wanted to store information in the database.

    The Rui side got more complex because I wanted

    • to have feedback on progress of the file upload
    • to have feedback the id added to the database
    • to have drag and drop with multiple files

    If you want to I can try to make a bare-metal example. Just let me know if this is of any interest.

    Bram_Callewaert


  • 16.  Re: File Upload to IFS

    Posted Tue February 24, 2015 08:52 AM

    That would be very nice!

    Marcel-D


  • 17.  Re: File Upload to IFS

    Posted Tue February 24, 2015 03:11 PM

    Hi Marcel,

    I have attached a zip file containing two projects:

    • FileUploadRui (Rui project)
    • FileUploadServlet (Web project containing the servlet)

    I have simplified the servlet so it doesn't require the webservice. You should only need to adapt the path variable to where the files should be stored on the IFS.

    The Rui side has been slightly simplified. You will have to adapt the UPLOAD_SERVLET_LINK constant in FileUploaderMulti to refer to your servlet address.

    Just let me know if you encounter any issues.

    Kind regards,

     

    Bram

    Bram_Callewaert

    Attachments



  • 18.  Re: File Upload to IFS

    Posted Wed February 25, 2015 12:31 PM

    Thank you very much Bram !!!!

    You are the best !

    Marcel-D


  • 19.  Re: File Upload to IFS

    Posted Thu February 26, 2015 04:00 AM

    Hi Bram,

    i have an other question.

    I Can't upload files larger than 6 or 7 MB.

    At the moment it's not necessary for me, but maybe for the future.

    Do you know why ?

    [26.02.15 09:49:20:652 CET] 000000a6 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service Uncaught service() exception thrown by servlet UploadFile: java.lang.OutOfMemoryError at java.io.FileInputStream.read(FileInputStream.java:216) at org.apache.commons.fileupload.disk.DiskFileItem.get(DiskFileItem.java:344) at com.molcy.java.servlets.fileupload.UploadFile.doPost(UploadFile.java:52) at javax.servlet.http.HttpServlet.service(HttpServlet.java:595) at javax.servlet.http.HttpServlet.service(HttpServlet.java:668) at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1230) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478) at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178) at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1111) at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87) at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:914) at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662) at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316) at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88) at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:558) at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:608) at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:985) at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1074) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1865)

    Marcel-D


  • 20.  Re: File Upload to IFS

    Posted Thu February 26, 2015 04:37 AM

    Hi Marcel,

    The servlet was set up to take the entire file into memory and then flush it to disk.

    I have modified the servlet and tested it with a 1.5 GB file and it seems to work.

    Here's my modified code:

    package com.molcy.java.servlets.fileupload;import java.io.File;import java.io.IOException;import java.io.PrintWriter;import java.util.Iterator;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.commons.fileupload.FileItem;import org.apache.commons.fileupload.FileUploadException;import org.apache.commons.fileupload.disk.DiskFileItemFactory;import org.apache.commons.fileupload.servlet.ServletFileUpload;public class UploadFile extends HttpServlet {    private static final long serialVersionUID = 1L;           public UploadFile() {        super();    }        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        }        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {                try {                        response.setContentType("text/html");                        boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);                        if (!isMultipartContent) {                                return;                        }                        ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());                        List<FileItem> fileItemsList = servletFileUpload.parseRequest(request);                        Iterator<FileItem> it = fileItemsList.iterator();                        String description = ""; // not used at the moment                        while(it.hasNext()){                                FileItem fileItem = (FileItem) it.next();                                if(fileItem.isFormField()){                                        if (fileItem.getFieldName().equals("description")) { // omschrijving = description                                                description = fileItem.getString();                                        }                                } else {                                        String origFilename = fileItem.getName();                                        String path = "/testupload/" + origFilename;                                        System.out.println("Writing to path " + path);                                         File fOut = new File(path);                                         fileItem.write(fOut);                                         PrintWriter out = response.getWriter();                                        out.println("{ \"path\": \"" + path + "\", \"waarde2\": \"value2\" }");                                        out.flush();                                         out.close();                                 }                        }                } catch (FileUploadException e) {                        System.out.println(e.getMessage());                } catch (Exception ex) {                        System.out.println("general exception: " + ex.getMessage());                 }        }}

     

    Bram_Callewaert


  • 21.  Re: File Upload to IFS

    Posted Thu February 26, 2015 07:18 AM

    Thank you very much !

    Marcel-D


  • 22.  Re: File Upload to IFS

    Posted Tue February 24, 2015 03:14 PM

    Hi Bram,

    I would interested in seeing your bere-metal example.  This could make for a good blog post, too.

    Thank you,

    Daron

    canutri


  • 23.  Re: File Upload to IFS

    Posted Mon April 20, 2015 12:12 PM

    I am learning a lot from this example.

    But I am running into a small problem with authorization.

    I have this servlet secured in a web project and I am getting prompted for authorization the first time unlike the services that are embedded in the same project.

    How do I send authorization to the servlet so that the user is not presented with a signon request.

     

    Rick Gentner

     

     

     

    RickGentner


  • 24.  Re: File Upload to IFS

    Posted Mon April 20, 2015 03:03 PM

    Is authentication on the servlet a requirement?

    In my implementation the servlet resides in a separate application on the server...

    I quickly searched google and found that the <auth-method> tag in your web.xml might be responsible for the authentication dialog. If this is the case you can set the authentication type per url pattern and have a separate authentication for the fileupload servlet.

    Bram_Callewaert


  • 25.  Re: File Upload to IFS

    Posted Mon April 20, 2015 03:17 PM

    To not have security on it would be a big no-no.

    Leaving it unsecured would allow unauthenticated users the ability to upload anything including viruses and other malicious programs.

    While the antivirus should catch it, I don't want to take the chance.

    The web project (Services) already has the security working, I just can't seem to get by the dialog box via programming like in EGL when we use setProxyBasicAuthentication and setHTTPBasicAuthentication.

    I have tried sending hardcoded credentials as a test in the open request, adding an authorization header with hard coded credentials and tried using the withCredentials flag. All of these methods do not appear to be working.

    I think I want it work like the EGL proxy works but have no idea where to look.

     

     

     

    RickGentner


  • 26.  Re: File Upload to IFS

    Posted Mon April 20, 2015 03:29 PM

    I believe the EGL proxy is a bit more complex than my simple example above. I don't know how to implement this.

    Perhaps the authentication is possible through Javascript, but I have not found it immediately.

    In the original program, I do add the username as a parameter to the servlet for tracability, but that's not the same as authentication.

     

    If you find a solution I would be very interested. We currently only use our application on premise and only secure our RUI application on the frontend.

    In the future I would like to implement security on the services as well...

    Bram_Callewaert


  • 27.  Re: File Upload to IFS

    Posted Mon April 20, 2015 03:32 PM

    If I figure it out, I will post the solution here.

    RickGentner


  • 28.  Re: File Upload to IFS

    Posted Fri April 24, 2015 10:04 AM

    I have figured out what needs to be done to access a servlet in a secured web project.

    You need to add an Authorization request  header. In my case we use Basic Authentication over a SSL pipe so the following code is added after the oReq.open("POST" operation but before the oReq.send operation

    var encodedString = Base64.encode(uid + ':' + cred);
    oReq.setRequestHeader("Authorization","Basic " + encodedString);

    You will need to pass the uid and cred into the uploadFile function and will also need a javascript function to do the base64 encoding

     

     

     

    RickGentner


  • 29.  Re: File Upload to IFS

    Posted Fri April 24, 2015 07:18 PM

    Thank you very much for sharing the information. I'm sure it will come in handy.

    Bram_Callewaert