xdocreport failed to process template and generate PDF

1.3k views Asked by At

I have problem with generating pdf from odt file using opensagres/xdocreport library. process() method call fails with NPE. Short research shows that there is not template engine in XDocReportEscapeReference.setRuntimeServices(). Can anyone help me to understand what is wrong with this code and can recommend me other simple library to generate pdf from template?

ITemplateEngine templateEngine = (ITemplateEngine) rs.getProperty( VELOCITY_TEMPLATE_ENGINE_KEY );

Here is my test project:

        IXDocReport template = XDocReportRegistry.getRegistry().loadReport(resource.getInputStream(), TemplateEngineKind.Velocity);
        Options options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.ODFDOM);

        IContext context = template.createContext();
        context.put("a", "test A");
        context.put("b", "test B);

        template.convert(context, options, stream);

Error msg:

fr.opensagres.xdocreport.core.XDocReportException: java.lang.NullPointerException
at fr.opensagres.xdocreport.template.velocity.internal.VelocityTemplateEngine.initializeVelocityEngine(VelocityTemplateEngine.java:136)
at fr.opensagres.xdocreport.template.velocity.internal.VelocityTemplateEngine.getVelocityEngine(VelocityTemplateEngine.java:118)
at fr.opensagres.xdocreport.template.velocity.internal.VelocityTemplateEngine.processWithCache(VelocityTemplateEngine.java:96)
at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:112)
at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:83)
at fr.opensagres.xdocreport.document.AbstractXDocReport.processTemplateEngine(AbstractXDocReport.java:775)
at fr.opensagres.xdocreport.document.AbstractXDocReport.convert(AbstractXDocReport.java:703)
at ee.maksekeskus.backoffice.services.impl.ReportServiceImpl.generateMerchantContactReport(ReportServiceImpl.java:47)
at ee.maksekeskus.backoffice.services.impl.ReportServiceImlTest.testReportGeneration(ReportServiceImlTest.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)

Caused by: java.lang.NullPointerException at fr.opensagres.xdocreport.template.velocity.internal.XDocReportEscapeReference.setRuntimeServices(XDocReportEscapeReference.java:56) at org.apache.velocity.runtime.RuntimeInstance.initializeSpecificEventHandler(RuntimeInstance.java:712) at org.apache.velocity.runtime.RuntimeInstance.initializeEventHandlers(RuntimeInstance.java:626) at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:243) at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:534) at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:144) at fr.opensagres.xdocreport.template.velocity.internal.VelocityTemplateEngine.initializeVelocityEngine

0

There are 0 answers