EventHandler Code not working when deployed

Hi team
I have an eventHandler (java code) that uses the openpdf library. It works correctly locally with CodeRunner, but when it is deployed it ends with a timeout.
After investigation I found that it blocks in the initialization of the PdfWriter.

logger.info(“Start PDF processing “);
Document document = new Document();
logger.info(” ByteArrayOutputStream”);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
logger.info(" Writer");
try {
PdfWriter writer = PdfWriter.getInstance(document, byteArrayOutputStream);
} catch (Exception e) {
logger.error(“Error writer :” + e.getMessage());
}

I’ve the same behavior in two applications (4F036E66-2926-B11C-FF1F-741011904C00 : Cloud9, E81A9468-7B95-85B1-FF02-6F5B032E7F00 : Springboard)

Thanks for your help

Hello,

I need to make your message public. Private messaging is reserved for licensees of our enterprise products. Please confirm.

Regards,
Mark

1 Like

Yes sure

Hello @Mkhafague

I’ve created an internal ticket BKNDLSS-24140 to investigate this issue

Regard, Viktor

Hi @viktor.liablin
Any update on this issue?
BTW, even if I deploy the code as service, I’m getting the same issue. It works using CodeRunner, but when deployed, the code is blocked at this line : writer = PdfWriter.getInstance(document, byteArrayOutputStream); until getting timeout (5 sec for eventhandler, and 15sec for service).
Below is the answer of the service:

400Bad Request, 15.12 s
{
“code”: 14004,
“message”: “Service invocation failed: Custom business logic execution has been terminated because it did not complete in permitted time - 15 seconds in BusinessLogicExecutionTimeoutException”,
“errorData”: {}
}

Kind regards

Hello,

Have you done any investigation on what could be getting blocked in PdfWriter?

Mark

Hi @mark-piller
The problem is that I’m not able to reproduce the issue in my IDE using CodeRunner, the pdf is generated in less than 2 sec.

Where does PdfWriter write the output? If it is local file system, it will not be able to because local file system is not accessible in the cloud code runner.

I’m using byteArrayOutputStream then I write the file using Backendless.Files.saveFile, please see the sample code below:

 public String testPDf(){

        System.out.println("Hello World");
        String url="";

        Document document = new Document();
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, byteArrayOutputStream);

            // step 3: we open the document
            document.open();
            // step 4: we add a paragraph to the document
            document.add(new Paragraph("Hello World"));

        document.close();
        logger.info("Writing file");
            Backendless.Files.saveFile("apps/arcolev/rapports/test_rapport.pdf", byteArrayOutputStream.toByteArray(), true);
            url =  BesFilesBaseUrl + "/files/apps/arcolev/rapports/test_rapport.pdf";
        } catch (Exception exe){
            logger.error(exe.getMessage());
        }
        return url;
    }

Hi @mark-piller
Do you think it’s doable in Backendless or do I need to find another solution? It’s a showstopper for my app.
Thanks for your help

Hello @Mkhafague

Unfortunately, I cannot give you an answer to this problem yet.
An internal ticket has been created already for this issue.
We will let you know when there are investigate results on this issue.
Sorry for the inconvenience.

Regard, Viktor

Hi @viktor.liablin
any progress on the ticket?
I’m deploying this feature on my own backend, which does not make any sense when we have Backendless!!
Thanks for your help^
Kind regards

Hello @Mkhafague

This ticket now in progress with high priority.

We notify you when it will be released, thanks for your patience.

Regards, Dima.

1 Like

Hi @Dima
Is there any way to follow this ticket?
Thanks for the update
Regards
MK

Hello @Mkhafague

Please check if it works for you now.

Hi @Volodymyr_Ialovyi
It is working in my SpringBoard app : E81A9468-7B95-85B1-FF02-6F5B032E7F00.

But I’m still getting the same errors in Prod (Cloud9) app 4F036E66-2926-B11C-FF1F-741011904C00

400 - Service invocation failed: Custom business logic execution has been terminated because it did not complete in permitted time - 15 seconds in BusinessLogicExecutionTimeoutException (14004)

Any advice?
Regards

Hello @Mkhafague

Please check again, it should work now.

Yep it works!! Thank you very much