SDK crashing when creating a document twice and to fast

Java, C++, C#, Delphi, ??? - Using the UNO bridges

SDK crashing when creating a document twice and to fast

Postby juliosmax » Wed Apr 10, 2019 9:17 pm

Hi , mi running a webservice that replace text in a docx template and then convet it to pdf.
Mi using ubuntu 18.04 and glassfish server for its deployment
when i made a single request for the service of converting everything is ok , but
when i made a double request too fast like a double clicking issue, i got this exception:

com.sun.star.lang.DisposedException
at com.sun.star.lib.uno.environments.remote.JobQueue.removeJob(JobQueue.java:201)
.
.
aused by: java.io.IOException: EOF reached - socket,host=localhost,port=8100,localHost=localhost,localPort=58494,peerHost=localhost,peerPort=8100
at com.sun.star.lib.uno.bridges.java_remote.XConnectionInputStream_Adapter.read(XConnectionInputStream_Adapter.java:50)


this is a portion of my code:
Code: Select all   Expand viewCollapse view
@Override
   public Response getFilePdf(Integer idqueja) {      
      try {
                 
                    // Initialise
       String oooExeFolder = "/opt/libreoffice6.1/program";
       XComponentContext xContext = BootstrapSocketConnector.bootstrap(oooExeFolder);
   //XComponentContext xContext = Bootstrap.bootstrap();
   
   XMultiComponentFactory xMCF = xContext.getServiceManager();
   
   Object oDesktop = xMCF.createInstanceWithContext(
        "com.sun.star.frame.Desktop", xContext);
   
   XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(
        XDesktop.class, oDesktop);

   // Load the Document
   String workingDir = "/home/somePath/";
   String myTemplate = workingDir + "template.docx";
   
   if (!new File(myTemplate).canRead()) {
      throw new RuntimeException("Cannotix load template:" + new File(myTemplate));
   }

   XComponentLoader xCompLoader = (XComponentLoader) UnoRuntime
      .queryInterface(com.sun.star.frame.XComponentLoader.class, xDesktop);

   String sUrl = "file:///" + myTemplate;
   
   PropertyValue[] propertyValues = new PropertyValue[0];
   
   propertyValues = new PropertyValue[1];
   propertyValues[0] = new PropertyValue();
   propertyValues[0].Name = "Hidden";
   propertyValues[0].Value = new Boolean(true);
   
   XComponent xComp = xCompLoader.loadComponentFromURL(
      sUrl, "_blank", 0, propertyValues);

   
   // Manipulate
   XReplaceDescriptor xReplaceDescr = null;
   XReplaceable xReplaceable = null;

   XTextDocument xTextDocument = (XTextDocument) UnoRuntime
         .queryInterface(XTextDocument.class, xComp);

   xReplaceable = (XReplaceable) UnoRuntime
         .queryInterface(XReplaceable.class,
               xTextDocument);

   xReplaceDescr = (XReplaceDescriptor) xReplaceable
         .createReplaceDescriptor();

       
        xReplaceDescr.setSearchString("<version>");
   xReplaceDescr.setReplaceString("1.x");
   xReplaceable.replaceAll(xReplaceDescr);
   // mail merge the date
   xReplaceDescr.setSearchString("<number>");
   xReplaceDescr.setReplaceString("12345677");
   xReplaceable.replaceAll(xReplaceDescr);
   

        OOoOutputStream output= new OOoOutputStream();
       
   // save as a PDF
   XStorable xStorable = (XStorable) UnoRuntime
         .queryInterface(XStorable.class, xComp);

   propertyValues = new PropertyValue[2];
   // Setting the flag for overwriting
   propertyValues[0] = new PropertyValue();
        propertyValues[1] = new PropertyValue();
       
   propertyValues[0].Name = "OutputStream";
   propertyValues[0].Value = output;
   // Setting the filter name
   
   propertyValues[1].Name = "FilterName";
   propertyValues[1].Value = "writer_pdf_Export";

   // Appending the favoured extension to the origin document name
   //String myResult = workingDir + "fileConverted.pdf";
   xStorable.storeToURL("private:stream", propertyValues);
       

   // shutdown
   xDesktop.terminate();

         ByteArrayInputStream inStream = new ByteArrayInputStream(output.toByteArray());

         
                   
                  ResponseBuilder response = Response.ok((Object) inStream);
                            response.header("Content-Disposition", "attachment;filename=queja.pdf");
                            return response.build();   
                   
                     
      } catch (Exception e) {
         e.printStackTrace();
                        ResponseBuilder response = Response.serverError();
                        return response.build();
      }      
   }



i build this guided by examples, i am a begginer in OO , i saw the line of the exception was poiting to xDesktop.terminate(); , so i made an experiment and remove that statement , so now there is no raising of the exception , but as i mention i am a begginer so i am not sure what the xDesktop.terminate(); does and what is the consequences of removing it?

So this webservice method is planned to serve documents to a LOT of users, so if i got petition at the same time or too consecutive it will raise the exception unless i remove the xDesktop.terminate(); but i dont know if it will have further consequences like overriding the memory or things like that

thanks for your help in advance
libreoffice 6.1 on ubuntu 18.04 ,
juliosmax
 
Posts: 3
Joined: Wed Apr 03, 2019 2:17 am

Re: SDK crashing when creating a document twice and to fast

Postby robleyd » Thu Apr 11, 2019 1:31 am

Same question asked at AskLibreOffice
Cheers
David
Apache OpenOffice 420m2(Build:9821) - Slackware 14.2 - 64 bit
LibreOffice 6.0.7.3 - Slackware 14.2 - 64 bit
Apache OpenOffice 4.1.4 - Windows 7 Virtual machine
User avatar
robleyd
Moderator
 
Posts: 3035
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: SDK crashing when creating a document twice and to fast

Postby JeJe » Thu Apr 11, 2019 9:53 am

I only know Basic - but there are easy ways to ensure a sub isn't called again before you want it to be.

In basic... if you don't want the code to be called while its running

Code: Select all   Expand viewCollapse view

dim busy as boolean

sub whatever()
if busy then exit sub
busy = true

'do whatever whatever does

busy = false
end sub


You might also use GetSystemTicks to make sure a set interval of time has elapsed before you allow the code to run again.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 611
Joined: Wed Mar 09, 2016 2:40 pm

Re: SDK crashing when creating a document twice and to fast

Postby RoryOF » Thu Apr 11, 2019 10:00 am

JeJe's suggestions were my thoughts also. If this is code for a website, you might need to queue new applicants for the routine when it is busy, so that they are permitted access it in their turn when it is once more available.
Apache OpenOffice 4.1.7 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29767
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: SDK crashing when creating a document twice and to fast

Postby juliosmax » Thu Apr 11, 2019 6:47 pm

JeJe wrote:I only know Basic - but there are easy ways to ensure a sub isn't called again before you want it to be.

In basic... if you don't want the code to be called while its running

Code: Select all   Expand viewCollapse view

dim busy as boolean

sub whatever()
if busy then exit sub
busy = true

'do whatever whatever does

busy = false
end sub


You might also use GetSystemTicks to make sure a set interval of time has elapsed before you allow the code to run again.



thanks , i know the basics too , but there is an equivalent to java for the code you suggest?
libreoffice 6.1 on ubuntu 18.04 ,
juliosmax
 
Posts: 3
Joined: Wed Apr 03, 2019 2:17 am

Re: SDK crashing when creating a document twice and to fast

Postby JeJe » Thu Apr 11, 2019 8:30 pm

The first bit is just setting a boolean and Java has a boolean data type.

https://www.luismajano.com/blog/Java%20 ... lliseconds
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 611
Joined: Wed Mar 09, 2016 2:40 pm

Re: SDK crashing when creating a document twice and to fast

Postby UnklDonald418 » Fri Apr 12, 2019 5:35 am

I doubt there are many Java programmers that visit here, I'm certainly not one. But, the API for OO / LO is language independent.
On page 275 of "OpenOffice.org Macros Explained 4.0" by Andrew Pitonyak is a discussion of what the terminiate() method might do.
http://www.pitonyak.org/oo.php
That discussion indicates that there might be a listener that could be used to determine when the pdf object has closed.

Chapter 4 of "Java LibreOffice Programming" by Dr. Andrew Davison covers listeners.
http://fivedots.coe.psu.ac.th/~ad/jlop/
Chapters 2 and 44 discuss ways of closing documents.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1239
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: SDK crashing when creating a document twice and to fast

Postby juliosmax » Fri Apr 12, 2019 8:56 pm

UnklDonald418 wrote:I doubt there are many Java programmers that visit here, I'm certainly not one. But, the API for OO / LO is language independent.
On page 275 of "OpenOffice.org Macros Explained 4.0" by Andrew Pitonyak is a discussion of what the terminiate() method might do.
http://www.pitonyak.org/oo.php
That discussion indicates that there might be a listener that could be used to determine when the pdf object has closed.

Chapter 4 of "Java LibreOffice Programming" by Dr. Andrew Davison covers listeners.
http://fivedots.coe.psu.ac.th/~ad/jlop/
Chapters 2 and 44 discuss ways of closing documents.


wow , thats documentation looks promising , thanks !
libreoffice 6.1 on ubuntu 18.04 ,
juliosmax
 
Posts: 3
Joined: Wed Apr 03, 2019 2:17 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 2 guests