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
  • 1.  Display a blob in RichUI

    Posted Thu May 04, 2017 03:15 AM

    Hi,

    does anyone know how to display a blob in RichUi?

    I can select the blob in the Java generated service but I can't return the record to the JavaScript UI.

    (Blob is not supported for JavaScript)

    Is there a trick?

     

    RBD 9.5.1

    DB2

    Websphere 8.5.5

     

    Kind Regards!

    Marcel-D


  • 2.  Re: Display a blob in RichUI

    Posted Mon May 08, 2017 04:09 AM

    Hi,

    I've solved it with a java servlet.

    But if someone knows a nicer way please notify me.

     

     

    package servlet;import java.io.IOException;import java.io.InputStream;import java.sql.Blob;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.servlet.ServletException;import javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class BlobServlet extends HttpServlet {        public void doGet(HttpServletRequest request, HttpServletResponse response)                        throws IOException, ServletException {                request.setCharacterEncoding("UTF-8");                Blob photo = null;                Connection conn = null;                Statement stmt = null;                ResultSet rs = null;                final String sql_script = request.getParameter("sql");                System.out.println("SQL Script: " + sql_script);                String query = sql_script;                ServletOutputStream out = response.getOutputStream();                try {                        DriverManager                                        .registerDriver(new com.ibm.as400.access.AS400JDBCDriver());                        conn = DriverManager.getConnection("jdbc:as400:172.17.1.6",                                        "xxx", "xxx");                } catch (Exception e) {                        response.setContentType("text/html");                        out.println("<body><h1>Database Connection Problem.</h1></body></html>");                        return;                }                try {                        stmt = conn.createStatement();                        rs = stmt.executeQuery(query);                        if (rs.next()) {                                photo = rs.getBlob(1);                        } else {                                response.setContentType("text/html");                                out.println("<body><h1>No photo found for id= 001 </h1></body></html>");                                return;                        }                        response.setContentType("image/gif");                        InputStream in = photo.getBinaryStream();                        int length = (int) photo.length();                        int bufferSize = 1024;                        byte[] buffer = new byte[bufferSize];                        while ((length = in.read(buffer)) != -1) {                                System.out.println("writing " + length + " bytes");                                out.write(buffer, 0, length);                        }                        in.close();                        out.flush();                } catch (SQLException e) {                        response.setContentType("text/html");                        out.println("<body><h1>Error=" + e.getMessage()                                        + "</h1></body></html>");                        return;                } finally {                        try {                                rs.close();                                stmt.close();                                conn.close();                        } catch (SQLException e) {                                e.printStackTrace();                        }                }        }}

     

     

    Kind Regards!

    Marcel-D


  • 3.  Re: Display a blob in RichUI

    Posted Mon March 25, 2019 08:39 AM

    Marcel ...

    About your article "Display a blob in RichUI" ...

    I need to work with BLOB in RUI. After research I came to the same conclusion. BLOB is not supported in RUI .. Well, you solved this with the Java Servlet ..

    I will expose my situation to see if colleagues guide me the best way ..

    In my case .. I am writing the images (photos) to database (DB2), with column of type BLOB. So far so good.
    To recover them, in egl-service, also okay ..
    Now what I need is, get this BLOB and throw it to RUI .. and I've been thinking to do the same as you ..
    But how ??
    I saw that you access the database in your Servlet ... (which I do not like) ..
    What I would need would be to send the Blob to the Servlet and get an Image back.
    Would it be possible ? How to capture the image in your example, in EGL-Service?

     

    Thank you very much for your attention !!

     

    would it be something like that ??

     

     

    package servlet;import java.io.IOException;import java.io.InputStream;import java.sql.Blob;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.servlet.ServletException;import javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class BlobServlet extends HttpServlet {        public void doGet(HttpServletRequest request, HttpServletResponse response)                        throws IOException, ServletException {                request.setCharacterEncoding("UTF-8");                Blob photo = null;                ServletOutputStream out = response.getOutputStream();                try {                       // photo = rs.getBlob(1); what ?                        response.setContentType("image/gif");                        InputStream in = photo.getBinaryStream();                        int length = (int) photo.length();                        int bufferSize = 1024;                        byte[] buffer = new byte[bufferSize];                        while ((length = in.read(buffer)) != -1) {                                System.out.println("writing " + length + " bytes");                                out.write(buffer, 0, length);                        }                        in.close();                        out.flush();                } catch (SQLException e) {                        response.setContentType("text/html");                        out.println("<body><h1>Error=" + e.getMessage()                                        + "</h1></body></html>");                        return;                } finally {                        }                }        }}

     

    ojomenezes


  • 4.  Re: Display a blob in RichUI

    Posted Tue March 26, 2019 03:13 AM

    Hi,

    in my example I have an Image widget inside the rui.

    I call the Servlet with a SQL Script as Parameter, the Servlet returns the Image from the Blob.

     

    You cann call it like this:

     

                Image_Widget.src = "http://192.168.190.1:80/WebApp/BlobServlet?sql=select BLOB from DB.TABLE where KEY = 12345";

     

     

    Marcel-D


  • 5.  Re: Display a blob in RichUI

    Posted Tue March 26, 2019 07:35 AM

    I understand..
    I will check with our support if they allow this type of operation ..
    Grateful

    ojomenezes


  • 6.  Re: Display a blob in RichUI

    Posted Tue March 26, 2019 07:43 AM

    Would http://192.168.190.1:80/WebApp/BlobServlet?sql=delete * from DB.TABLE also work? 

     
    Bram_Callewaert


  • 7.  Re: Display a blob in RichUI

    Posted Tue March 26, 2019 08:10 AM

    Yes, I think this would work.

    It's just an example and has to be modified for production use.

     

    To pass just the KEY value would be one way.

    Marcel-D