4PointSolutions / FluentFormsAPI

Fluent API for Adobe AEM Forms
Apache License 2.0
6 stars 8 forks source link

Unable to find form when calling AEM server on Linux from a Windows client #32

Open rmcdouga opened 2 years ago

rmcdouga commented 2 years ago

The following code snippets fail when calling AEM from a Windows client when AEM is running on a Linux machine.

        URL formPath = new URL("file:/home/aem_user/u000/AEM/Forms/RUNTIME/Invoices/EN/Invoice_GB_PD.xdp");
        Document pdfResult =  underTest.generatePDFOutput()
                               .executeOn(formPath, null);
        Path contentPath = Paths.get("\\","home", "aem_user", "u000","AEM","Forms","RUNTIME","Invoices","EN");
        Path formPath = Paths.get("Invoice_GB_PD.xdp");
        Document pdfResult =  underTest.generatePDFOutput()
                               .setContentRoot(contentPath)
                               .executeOn(formPath, null);

They return the following error: 400 Bad request parameter while rendering PDF (Unable to find template (\\home\aem_user\u000\AEM\Forms\RUNTIME\Invoices\EN/Invoice_GB_PD.xdp).).

It appears that the Windows backslashes in the filepath are not being translated to the unix forward slashes.

rmcdouga commented 2 years ago

There are a couple of potential workarounds:

1) Run a copy of AEM locally and use that for development This is the preferred option because it means that each developer is independent of other developers (and so if you’re examining the logs, you know whose requests are causing errors in the logs). This is the way we typically develop here at 4Point. 2) Use a file: URL instead of a Path The executeOn() method is overloaded to accept a variety of different types of arguments. java.nio.file.Path objects are one option but java.net.URL objects are another one. The following code worked for me:

        URL formPath = new URL("file:/home/aem_user/u000/AEM/Forms/RUNTIME/Invoices/EN/Invoice_GB_PD.xdp");
        Document pdfResult =  underTest.generatePDFOutput()
                               .executeOn(formPath, null);

This second approach may not work in the long term if you want to use setContentRoot() in the call. This is the most common use case where you specify a root directory under which all your forms (and fragments) are located and then you use a relative path in the executeOn() call.