0

We are using BIRT 3.7 api to generate dynamic PDF. We are setting up XML data source using below logic. In below snippet we provides XML string as data source. Strangely, since last week dynamic data is not getting populated from xml. It is not throwing any exception as such even in the FINEST log level. As we have not updated any jars so not able to figure out the changes which made this functionality to break. PDF are getting generated without dynamic values.

Is there something else I can try out to set xml data source in java to birt template.

String paramStr = readFileAsString(servletContext.getRealPath("/WEB-INF/classes")
+ "/resources/test.xml");

FileInputStream fis = new FileInputStream(servletContext.getRealPath("/WEB-INF/classes")
+ "/resources/BirtXmlDataTest.rptdesign");
IReportRunnable design = birtReportEngine.openReportDesign(fis);
DesignElementHandle designElementHandle = design.getDesignHandle();
ModuleHandle moduleHandle = designElementHandle.getModuleHandle();
ElementFactory designElementFactory = designElementHandle.getElementFactory();
OdaDataSourceHandle dataSourceHandle = designElementFactory.newOdaDataSource("Data Source",
"org.eclipse.birt.report.data.oda.xml");

moduleHandle.getDataSources().add(dataSourceHandle);

IRunAndRenderTask task = birtReportEngine
.createRunAndRenderTask(design);
PDFRenderOption options = new PDFRenderOption();
options.setSupportedImageFormats("JPG;PNG;BMP;SVG");
options.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);
options.setEmitterID(PDFRenderOption.OUTPUT_EMITTERID_PDF);
// options.setOutputStream(response.getOutputStream());
File file = new File("d:\\test" + File.separator + "file2.pdf");
FileOutputStream fos = new FileOutputStream(file);
// options.setOutputStream(response.getOutputStream());
options.setOutputStream(fos);

HashMap<String, Object> contextMap = new HashMap<String, Object>();
contextMap.put("org.eclipse.birt.report.data.oda.xml.inputStream",
new ByteArrayInputStream(paramStr.getBytes()));
contextMap.put(
"org.eclipse.birt.report.data.oda.xml.closeInputStream",
Boolean.TRUE);
task.setAppContext(contextMap);
task.setRenderOption(options);
task.run();
task.close();
Anupam Gupta
  • 1,591
  • 8
  • 36
  • 60

1 Answers1

0

Where are you setting your report parameters to the task? If you refer to that values as dynamic values that's what you need:

task.setParameterValue("param_name", value);

Just follow this model. Otherwise you'll obviously get a blank report, as no parameters are specified.

Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217
  • XML input stream is actual read in String "paramStr" which is put into context map as below. contextMap.put("org.eclipse.birt.report.data.oda.xml.inputStream", new ByteArrayInputStream(paramStr.getBytes())); contextMap.put( "org.eclipse.birt.report.data.oda.xml.closeInputStream", Boolean.TRUE); task.setAppContext(contextMap); It was actually working fine a week ago. – Anupam Gupta Jul 11 '13 at 11:55
  • So probably, if not changes made in the code the problem must be in the xml file. Have you done debugging and rechecked you're loading a correct file? – Aritz Jul 11 '13 at 12:12