Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DMI - inject generated new File

    hi,
    how can I insert a new file in the DSRequest during a DMI Call.

    Usecase:
    1) The user loads a file to the server using UploadItem.
    2) A Java method (DMI) for custom processing is called.
    2a) The file (XMLFILE) is technically validated and ...
    2c) ... the result (= pdf report) should be stored in the same database table. (field report)

    How can I realize the point 2c?
    I've already tried unsuccessfully DSRequest.setAttribute("report", ISCFileItem). I have no method DSRequest.setUploadFiles, or similarly found!

    SQL - Datasource (extract):
    <field name="XMLFILE" hidden="true" type="binary"/>
    <field name="report" type="binary"/>

    Thanks,
    tmoes

    SmartGWT EE eval, from 20100717

    #2
    dsRequest.setFieldValue("XMLFile", InputStream) then dsRequest.execute()

    Comment


      #3
      Hi I have now added the following code but I get an sql exception.

      Code:
      Document document = new Document();
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      PdfWriter.getInstance(document, baos);
      document.open();
      document.add(new Paragraph("Hello World!"));
      document.close();
      
      dsRequest.setFieldValue("report", new ByteArrayInputStream(baos.toByteArray()));
      dsRequest.setFieldValue("report_filename", "report.pdf");
      dsRequest.setFieldValue("report_filesize", 50);
      dsRequest.setFieldValue("report_date_created", new Date());
      
      dsResponse = dsRequest.execute();
      com.mysql.jdbc.JDBC4PreparedStatement@2e8be7c7: INSERT INTO upload.XMLUPLOAD (XMLFILE_date_created, USERDEFINEDFIELDS4, report_filename, report_date_created, USERDEFINEDFIELDS1, XMLFILE_filesize, XMLFILE_filename, report, CONTAINERTYP, CLEARINGTYPSELECTITEM, XMLFILE, report_filesize) VALUES ('2010-07-18 18:43:26.165', '2010-07-11 00:00:00.0', 'report.pdf', '2010-07-18 18:43:36.042', 'sdfsdf', 8284, 'scf.xml', ** STREAM DATA **, 'ICF', 'EBA', ** NOT SPECIFIED **, 50)

      === 2010-07-18 18:43:38,147 [l0-8] INFO SQLDriver - [builtinApplication.DSXmlUpload_add] Execute of update: INSERT INTO upload.XMLUPLOAD (XMLFILE_date_created, USERDEFINEDFIELDS4, report_filename, report_date_created, USERDEFINEDFIELDS1, XMLFILE_filesize, XMLFILE_filename, report, CONTAINERTYP, CLEARINGTYPSELECTITEM, XMLFILE, report_filesize) VALUES ('2010-07-18 18:43:26.165', '2010-07-11 00:00:00.0', 'report.pdf', '2010-07-18 18:43:36.042', 'sdfsdf', 8284, 'scf.xml', ?, 'ICF', 'EBA', ?, 50) on db: Mysql threw exception: java.sql.SQLException: No value specified for parameter 2 - assuming stale connection and retrying update.


      java.sql.SQLException: No value specified for parameter 2

      For me, it looks as if the user's file "XMLFILE" missing from the PreparedStatement.

      RPCRequest:
      Code:
      === 2010-07-18 18:43:26,165 [l0-8] DEBUG RPCManager - Request #1 (DSRequest) payload: {
          values:{
              CLEARINGTYPSELECTITEM:"EBA",
              CONTAINERTYP:"ICF",
              USERDEFINEDFIELDS1:"sdfsdf",
              USERDEFINEDFIELDS4:new Date(1278799200000),
              XMLFILE:"scf.xml",
              XMLFILE_date_created:new Date(1279471406165),
              XMLFILE_filesize:8284,
              XMLFILE_filename:"scf.xml"
          },
          operationConfig:{
              dataSource:"DSXmlUpload",
              operationType:"add"
          },
          componentId:"isc_DynamicForm_4",
          appID:"builtinApplication",
          operation:"DSXmlUpload_add",
          oldValues:{
              CLEARINGTYPSELECTITEM:"EBA"
          },
          criteria:{
          }
      }
      Did I miss something?

      Thanks,
      tmoes
      Last edited by tmoes; 19 Jul 2010, 01:10.

      Comment


        #4
        Hello Isomorphic, is there already news to this bug/problem? Is there a workaround for this problem?
        Thanks,

        Comment


          #5
          Hi Isomorphic,
          your proposal (dsRequest.setFieldValue ("XMLFile" Input Stream) then dsRequest.execute() ) does not work for me.

          Is there another way?

          Code:
          ava.sql.SQLException: No value specified for parameter 2
          	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
          	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
          	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
          	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
          	at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2549)
          	at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2525)
          	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2372)
          	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2316)
          	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2301)
          	at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
          	at com.isomorphic.sql.SQLDriver.doUpdate(SQLDriver.java:450)
          	at com.isomorphic.sql.SQLDriver.update(SQLDriver.java:422)
          	at com.isomorphic.sql.SQLDriver.executeUpdate(SQLDriver.java:506)
          	at com.isomorphic.sql.SQLDataSource.executeNativeUpdate(SQLDataSource.java:345)
          	at com.isomorphic.sql.SQLDataSource.SQLExecute(SQLDataSource.java:1196)
          	at com.isomorphic.sql.SQLDataSource.execute(SQLDataSource.java:249)
          	at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:721)
          	at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:658)
          	at com.isomorphic.application.AppBase.execute(AppBase.java:491)
          	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1336)
          Thanks for the info

          Comment


            #6
            Hi tmoes,

            We've looked into this and there is a problem preventing the setFieldValue() approach from working, which will be fixed.

            A short-term hack would be to call dsRequest.setUploadedFiles() with a List containing a single ISCFileItem where you have subclassed ISCFileItem and overriden getInputStream() to return your stream. These are undocumented unsupported APIs but would work for a hack.

            Comment


              #7
              Hi Isomorphic,

              thanks, that sounds good.

              I prefer to wait on a fix, because the hack does not work. I get an NPE when calling dsRequest.execute() with my subclassed ISCFileItem.

              Let me know if it is in the nightly build to test.

              Code:
              === 2010-07-23 20:44:17,023 [l0-6] DEBUG DataSourceDMI - Invocation threw exception
              java.lang.NullPointerException
              	at com.isomorphic.servlet.ISCFileItem.getErrors(ISCFileItem.java:201)
              	at com.server.ds.ISCReportFileItem.getErrors(ISCReportFileItem.java:27)
              	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1257)
              	at com.server.ds.XMLUpload.xmlUpload(XMLUpload.java:172)
              	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              	at java.lang.reflect.Method.invoke(Method.java:597)
              Cheers,
              Tmoes

              Comment


                #8
                Since you've already started on the hack, you should be able to have your subclass override getErrors() and return null to get past this problem.

                Comment


                  #9
                  I have also tried, but then I get the same exception as with the original ISCFileItem and setFieldValue.

                  I can wait a couple of days, that with the "Hack" is not a problem.

                  Comment


                    #10
                    In the next nightly you should find that setFieldValue with an InputStream will work to replace the uploaded file with your own stream.

                    Comment

                    Working...
                    X