I need to have Docmosis running in a web application. I am sure there are articles and help files somewhere, but I have not been able to find them.
All the examples run with no problem. So Docmosis is working and appears to be configured correctly (at least for the examples).
The problem I am getting is when I run a web application that tries to generate a pdf. When I do I get an error when the application tries to get the template:
14:03:13,431 INFO [SystemManager] Docmosis initialised in 230 ms
14:03:13,446 INFO [ReportRenderer] Template(s) loaded into store
14:03:13,446 INFO [ReportRenderer] Performing a test render
14:03:13,453 ERROR [ReportRenderer] working template not found: exampleTemplate.doc
14:03:13,454 ERROR [STDERR] com.docmosis.template.TemplateNotFoundException: working template not found: exampleTemplate.doc
Since the examples work in isoation, I am guessing the problem is with my web app and the location/configuration of docmosis.properties, converterPoolConfig.xml, and the template store.
This is what I have done so far:
I started a converter using ./runConverter.sh as I did for the examples. It starts up fine.
I have no idea where docmosis.properties and converterPoolConfig.xml belong. I am assuming they go in myWebProject/src (the source root).
Moving on. Now where do I place the templates? Assuming my config files are in the right place, and they are configured correctly, I just need to place the template next to the java class (just like in the examples).
No dice.
DropStoreHelper storeHelper = new DropStoreHelper(TemplateStoreFactory.getStore());
storeHelper.process(new File("."), false);
ByteArrayOutputStream streamTo = new ByteArrayOutputStream();
log.info("Performing a test render");
TemplateIdentifier templateId = new TemplateIdentifier("exampleTemplate.doc");
ConversionInstruction instruction = new ConversionInstruction();
instruction.setConversionFormats(new ConversionFormat[] {
ConversionFormat.FORMAT_ODT,
ConversionFormat.FORMAT_WORD,
ConversionFormat.FORMAT_PDF,
});
instruction.setOutputFileName("exampleTemplate");
try {
long start = System.currentTimeMillis();
//File template = new File("exampleTemplate.doc");
DocumentProcessor.renderDoc(templateId, dp, instruction, streamTo);
log.info("documents.zip generated in " + (System.currentTimeMillis() - start) + " milliseconds (including wait time)");
} finally {
FileUtilities.close(streamTo);
}
Help?
Changed the code to the following and it now works:
DropStoreHelper storeHelper = new DropStoreHelper(TemplateStoreFactory.getStore());
URL templateFolder = ReportRenderer.class.getClassLoader().getResource("docmosisTemplates");
//storeHelper.process(new File("."), false);
storeHelper.processResource(templateFolder, null, true);
// ...
ByteArrayOutputStream streamTo = new ByteArrayOutputStream();
log.info("Performing a test render");
TemplateIdentifier templateId = new TemplateIdentifier("exampleTemplate.doc");
ConversionInstruction instruction = new ConversionInstruction();
instruction.setConversionFormats(new ConversionFormat[] {
ConversionFormat.FORMAT_PDF
});
instruction.setOutputFileName("exampleTemplate");
try {
long start = System.currentTimeMillis();
DocumentProcessor.renderDoc(templateId, dp, instruction, streamTo);
log.info("documents.zip generated in " + (System.currentTimeMillis() - start) + " milliseconds (including wait time)");
} finally {
FileUtilities.close(streamTo);
}
Thanks to the post that shows how to specify your own template store location: http://www.docmosis.com/node/75
I still do not know why the original way did not work. At this point I really don't care. :) If someone who knows why and cares to elaborate, go ahead.
Hi Rustyspoone.
Your solution was spot on (using the different DropStoreHelper method to register/store the templates. The previous version didn't work since it was looking for templates in the "working dir" of the application within the web server - and that almost certainly wouldn't be where your templates resided.
Putting the templates into a resource folder as you have done ("docmosisTemplates") with your codebase, then using the class loader to locate the URL, then getting Docmosis to load from there is precisely what you needed to do - and probably the only portable option.
