Announcement

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

    is it possible to use export API entirely server side?

    Hello, I'm using SmartClient 10.0 Enterprise and my use case is: generate two or more csv export files, then zip and download the zip file.

    I don't know if I could use the SmartClient export feature entirely server side, i.e.:

    Code:
            DSRequest exportRequest = new DSRequest("MY_DS", DataSource.OP_FETCH, rpcManager);
            exportRequest.setExportAs("csv");
            DSResponse exportResponse = exportRequest.execute();
    If yes, then how could I access the exported file as a stream to put it in a zip?
    Using getExportObject ? Or using setExportTo ?

    #2
    Hello, any hint for this use case?

    Comment


      #3
      Did you already try with exportRequest.setExportTo()?
      I think it will depend on your zipping tool if you need files on the filesystem or not.

      Best regards
      Blama

      Comment


        #4
        Originally posted by Blama View Post
        Did you already try with exportRequest.setExportTo()?
        I think it will depend on your zipping tool if you need files on the filesystem or not.
        well, I tried your suggestion but I get an empty file.

        Comment


          #5
          Hi,

          did you have a look if there is data in the stream in the debugger?

          Best regards
          Blama

          Comment


            #6
            yes, I did: no data.

            Comment


              #7
              Ok, then I don't know and you'll have to wait for Isomorphic, best with exact version and code sample.

              Best regards
              Blama

              Comment


                #8
                SmartClient Version: v10.1p_2016-01-27/Enterprise Development Only (built 2016-01-27)

                Code:
                           
                DSRequest exportRequest = new DSRequest("JTK_TITOLARI", DataSource.OP_FETCH);
                exportRequest.setExportAs("csv");
                FileOutputStream exportOutputStream = new FileOutputStream("test.csv");
                exportRequest.setExportTo(exportOutputStream);
                DSResponse exportResponse = exportRequest.execute();
                System.out.println(exportResponse.getTotalRows()); // 265 rows
                exportOutputStream.flush();
                exportOutputStream.close();
                this sample creates test.csv but it's empty.

                Comment


                  #9
                  This is fixed now and will be available for download since Feb 2 (tomorrow). Please see updated docs for setExportTo and setExportToFilesystem. Calling setExportTo will automatically set exportToFilesystem flag to true, without that data is not written into exportTo outputStream.

                  Meanwhile you may setExportToFilesystem(true) on your DSRequest manually. Note this will no longer be necessary after the fix.

                  Comment


                    #10
                    Thank you very much.
                    And what about exporting to a ByteArrayOutputStream, i.e.:
                    Code:
                            DSRequest exportRequest = new DSRequest("JTK_TITOLARI", DataSource.OP_FETCH);
                            exportRequest.setExportAs("csv");
                            ByteArrayOutputStream exportOutputStream = new ByteArrayOutputStream();
                            exportRequest.setExportTo(exportOutputStream);
                            DSResponse exportResponse = exportRequest.execute();
                            System.out.println(exportResponse.getTotalRows()); // 265 rows
                            exportOutputStream.flush();
                            exportOutputStream.close();
                    this too seems to create an empty outputStream

                    Comment


                      #11
                      This would work as well, for example:
                      Code:
                      DSRequest exportRequest = new DSRequest("JTK_TITOLARI", DataSource.OP_FETCH);
                      exportRequest.setExportAs("csv");
                      ByteArrayOutputStream exportOutputStream = new ByteArrayOutputStream();
                      exportRequest.setExportTo(exportOutputStream);
                      [b][i]exportRequest.setExportToFilesystem(true); // NOTE THIS LINE WON'T BE NECESSARY AFTER THE FIX[/i][/b]
                      DSResponse exportResponse = exportRequest.execute();
                      System.out.println(exportResponse.getTotalRows()); // 265 rows
                      [b][i]System.out.println("exportOutputStream.toByteArray().length: " + exportOutputStream.toByteArray().length);[/i][/b]

                      Comment


                        #12
                        SmartClient Version: v10.1p_2016-02-02/Enterprise Deployment (built 2016-02-02)

                        I can confirm it's working, thank you very much.

                        Comment

                        Working...
                        X