Home » Archived » BIRT » Birt 2.5.1 Generating Reports inside other Webapplication
Birt 2.5.1 Generating Reports inside other Webapplication [message #514666] |
Tue, 16 February 2010 04:38  |
Eclipse User |
|
|
|
Hello everybody,
I am currently trying to integrate the BIRT ReportEngine to an existing Java Webapplication. Everything worked fine in an older version of the webapp, that used the same version of the libraries that were used within BIRT. My problem is that I need to migrate to a new version. Now, when I try to create a report with BIRT my application throws a LinkageError:
[appserver0] java.lang.LinkageError: loader constraints violated when linking org/w3c/dom/TypeInfo class
[appserver0] at org.apache.xerces.dom.CoreDocumentImpl.createElement(Unknown Source)
[appserver0] at org.eclipse.birt.report.engine.parser.HTMLTextParser.parseHT ML(HTMLTextParser.java:141)
[appserver0] at org.eclipse.birt.report.engine.parser.TextParser.parse(TextP arser.java:111)
[appserver0] at org.eclipse.birt.report.engine.layout.pdf.util.HTML2Content. processForeignData(HTML2Content.java:437)
[appserver0] at org.eclipse.birt.report.engine.layout.pdf.util.HTML2Content. html2Content(HTML2Content.java:418)
[appserver0] at org.eclipse.birt.report.engine.nLayout.LayoutEngine.startFor eign(LayoutEngine.java:627)
[appserver0] at org.eclipse.birt.report.engine.emitter.ContentEmitterUtil.st artContent(ContentEmitterUtil.java:77)
[appserver0] at org.eclipse.birt.report.engine.nLayout.LayoutEngine.visitCon tent(LayoutEngine.java:592)
[appserver0] at org.eclipse.birt.report.engine.nLayout.LayoutEngine.visitChi ldren(LayoutEngine.java:616)
[appserver0] at org.eclipse.birt.report.engine.nLayout.RegionLayoutEngine.la yout(RegionLayoutEngine.java:31)
[appserver0] at org.eclipse.birt.report.engine.nLayout.area.impl.PageArea.la youtFooter(PageArea.java:481)
[appserver0] at org.eclipse.birt.report.engine.nLayout.area.impl.PageArea.in itialize(PageArea.java:249)
[appserver0] at org.eclipse.birt.report.engine.nLayout.area.impl.RootArea.cr eateNewPage(RootArea.java:91)
[appserver0] at org.eclipse.birt.report.engine.nLayout.area.impl.RootArea.in itialize(RootArea.java:82)
[appserver0] at org.eclipse.birt.report.engine.nLayout.LayoutEngine.setConta iner(LayoutEngine.java:340)
[appserver0] at org.eclipse.birt.report.engine.nLayout.LayoutEngine._startCo ntainer(LayoutEngine.java:380)
[appserver0] at org.eclipse.birt.report.engine.nLayout.LayoutEngine.startCon tainer(LayoutEngine.java:334)
[appserver0] at org.eclipse.birt.report.engine.emitter.ContentEmitterAdapter .startPage(ContentEmitterAdapter.java:65)
[appserver0] at org.eclipse.birt.report.engine.nLayout.LayoutEngine.startPag e(LayoutEngine.java:502)
[appserver0] at org.eclipse.birt.report.engine.emitter.CompositeContentEmitt er.startPage(CompositeContentEmitter.java
:290)
[appserver0] at org.eclipse.birt.report.engine.emitter.ContentEmitterUtil.st artContent(ContentEmitterUtil.java:47)
[appserver0] at org.eclipse.birt.report.engine.layout.html.buffer.PageNode.s tart(PageNode.java:49)
[appserver0] at org.eclipse.birt.report.engine.layout.html.buffer.HTMLPageBu ffer.startContent(HTMLPageBuffer.java:113
)
[appserver0] at org.eclipse.birt.report.engine.layout.html.buffer.TableBreak Buffer.startContent(TableBreakBuffer.java
:286)
[appserver0] at org.eclipse.birt.report.engine.layout.html.HTMLLeafItemLM.st art(HTMLLeafItemLM.java:67)
[appserver0] at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.la yout(HTMLAbstractLM.java:136)
[appserver0] at org.eclipse.birt.report.engine.layout.html.HTMLBlockStacking LM.layoutNodes(HTMLBlockStackingLM.java:7
0)
[appserver0] at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout (HTMLPageLM.java:90)
[appserver0] at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutE ngine.layout(HTMLReportLayoutEngine.java:
99)
[appserver0] at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doR un(RunAndRenderTask.java:170)
[appserver0] at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run (RunAndRenderTask.java:75)
... (more)
As you can see the problem can be isolated to XML processing. My Web Application uses Axis2 and all libraries necessary, e.g. Xerces 2.8.1. However, I think the problem is, that there are 2 versions of the TypeInfo (and several other classes) in my classloading hierarchy, 1 from the webapp the other from the ReportEngine.
Does anybody have an idea how to fix this problem? I already played around a little with classloading but that did not lead to a solution
My BIRT Report Runtime Version is 2.5.1
Help is highly appreciated.
Regards
Ronny
|
|
| |
Re: Birt 2.5.1 Generating Reports inside other Webapplication [message #514772 is a reply to message #514755] |
Tue, 16 February 2010 10:31   |
Eclipse User |
|
|
|
Jason,
I downloaded the Birt 2.5.1. Runtime Release.
What I did is basically:
- unpacked the ReportEngine directory to a custom folder
- copy the libraries from ReportEngine/lib to my webapplication lib folder (so I can use the ReportEngine in the application)
- added a part in my webapplication where the ReportEngine Configuration is initialized from a property file. This basically sets the BIRT_HOME.
private void init()
{
File configFile =
new File(
FileUtils.getClusterConfigDirectory(),
"reportengine.properties"
);
this.config = new EngineConfig();
Properties configuration = new Properties();
try {
configuration.load(new FileInputStream(configFile));
for(Object key : configuration.keySet())
{
if(IPlatformConfig.BIRT_HOME.equals(key))
{
File home = new File(
FileUtils.getHomeDirectory(),
configuration.getProperty(key.toString())
);
if(home.exists() && home.canRead())
{
this.config.setEngineHome(home.getAbsolutePath());
}
else
{
Logger.error(this,
"ReportEngine root folder could not be initialized for folder "
+home.getAbsolutePath()
);
}
}
else if(key != null)
{
this.config.setProperty(
key.toString(),
configuration.getProperty(key.toString())
);
}
}
} catch (FileNotFoundException e) {
Logger.error(this, "Error reading report engine configuration", e);
} catch (IOException e) {
Logger.error(this, "Error reading report engine configuration", e);
}
}
- added a custom part in my Webapplication that loads the report, initializes the parameters, sets the output format (word, pdf, xls) and generates the report. The main part that does the report generation is:
class ReportExecutionCallable implements Callable<Void>
{
private final Report report;
private final Collection<ReportParameter> parameters;
private final ReportOutputFormat format;
private final OutputStream out;
public ReportExecutionCallable(Report report,
Collection<ReportParameter> parameters, ReportOutputFormat format,
OutputStream out)
{
if (report == null)
{
throw new IllegalArgumentException("Can't create report execution "
+ "callable for report = null.");
}
if (out == null)
{
throw new IllegalArgumentException("Can't create report execution "
+ "callable. The output stream that the report "
+ "should be written to is null.");
}
this.report = report;
this.parameters = (parameters == null) ? new ArrayList<ReportParameter>()
: parameters;
this.format = (format == null) ? report.getDefaultOutputFormat()
: format;
this.out = out;
}
public Void call() throws Exception
{
IReportEngine reportEngine = MyReportEngineConfig.getInstance()
.getReportEngine();
String reportFile = ReportingUtils.getReportFilePath(report);
IReportRunnable design = reportEngine.openReportDesign(reportFile);
IRunAndRenderTask task = reportEngine.createRunAndRenderTask(design);
RenderOption renderOption = new RenderOption();
renderOption.setOutputFormat(format.getFormatterName());
renderOption.setOutputStream(out);
task.setRenderOption(renderOption);
Map<String, Object> parametersMap = new HashMap<String, Object>();
Collection<ReportParameter> reportParameters = report
.getReportParameters();
addToParametersMap(reportParameters, parametersMap);
addToParametersMap(parameters, parametersMap);
task.setParameterValues(parametersMap);
if (!task.validateParameters())
{
throw new IllegalArgumentException(
"Report parameter validation failed.");
}
task.run();
task.close();
return null;
}
private void addToParametersMap(Collection<ReportParameter> parameters,
Map<String, Object> parametersMap)
{
for (ReportParameter parameter : parameters)
{
// TODO parameter value might not be a string
parametersMap.put(parameter.getName(), parameter.getValue());
}
}
}
Hope this helps to understand my problem.
Regards
Ronny
[Updated on: Tue, 16 February 2010 15:54] by Moderator
|
|
|
Re: Birt 2.5.1 Generating Reports inside other Webapplication [message #514797 is a reply to message #514772] |
Tue, 16 February 2010 11:40   |
Eclipse User |
|
|
|
Ronny,
You can also make the report engine as part of the web app.
Take a look at:
http://wiki.eclipse.org/Servlet_Example_%28BIRT%29_2.1
In your example can you try:
config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSL OADER_KEY,
whateverthenameofyourclassis.class.getClassLoader());
Jason
Ronny Karallus wrote:
> Jason,
>
> I downloaded the Birt 2.5.1. Runtime Release.
> What I did is basically:
> - unpacked the ReportEngine directory to a custom folder
> - copy the libraries from ReportEngine/lib to my webapplication lib
> folder (so I can use the ReportEngine in the application)
> - added a part in my webapplication where the ReportEngine Configuration
> is initialized from a property file. This basically sets the BIRT_HOME.
>
> private void init()
> {
> File configFile = new File(
> FileUtils.getClusterConfigDirectory(),
> "reportengine.properties"
> );
> this.config = new EngineConfig();
> Properties configuration = new Properties();
> try {
> configuration.load(new FileInputStream(configFile));
> for(Object key : configuration.keySet())
> {
> if(IPlatformConfig.BIRT_HOME.equals(key))
> {
> File home = new File(
> FileUtils.getHomeDirectory(),
> configuration.getProperty(key.toString())
> );
> if(home.exists() && home.canRead())
> {
> this.config.setEngineHome(home.getAbsolutePath());
> }
> else
> {
> Logger.error(this,
> "ReportEngine root folder could not be initialized for folder "
> +home.getAbsolutePath()
> );
> }
> }
> else if(key != null)
> {
> this.config.setProperty(
> key.toString(),
> configuration.getProperty(key.toString())
> );
> }
> }
> } catch (FileNotFoundException e) {
> Logger.error(this, "Error reading report engine
> configuration", e);
> } catch (IOException e) {
> Logger.error(this, "Error reading report engine
> configuration", e);
> }
> }
>
> - added a custom part in my Webapplication that loads the report,
> initializes the parameters, sets the output format (word, pdf, xls) and
> generates the report.
>
> class ReportExecutionCallable implements Callable<Void>
> {
> private final Report report;
>
> private final Collection<ReportParameter> parameters;
>
> private final ReportOutputFormat format;
>
> private final OutputStream out;
>
> public ReportExecutionCallable(Report report,
> Collection<ReportParameter> parameters, ReportOutputFormat
> format,
> OutputStream out)
> {
> if (report == null)
> {
> throw new IllegalArgumentException("Can't create report
> execution "
> + "callable for report = null.");
> }
>
> if (out == null)
> {
> throw new IllegalArgumentException("Can't create report
> execution "
> + "callable. The output stream that the report "
> + "should be written to is null.");
> }
>
> this.report = report;
> this.parameters = (parameters == null) ? new
> ArrayList<ReportParameter>()
> : parameters;
> this.format = (format == null) ? report.getDefaultOutputFormat()
> : format;
> this.out = out;
> }
>
> public Void call() throws Exception
> {
> IReportEngine reportEngine = MyReportEngineConfig.getInstance()
> .getReportEngine();
>
> String reportFile = ReportingUtils.getReportFilePath(report);
> IReportRunnable design = reportEngine.openReportDesign(reportFile);
>
> IRunAndRenderTask task =
> reportEngine.createRunAndRenderTask(design);
>
> RenderOption renderOption = new RenderOption();
> renderOption.setOutputFormat(format.getFormatterName());
> renderOption.setOutputStream(out);
>
> task.setRenderOption(renderOption);
>
> Map<String, Object> parametersMap = new HashMap<String, Object>();
>
> Collection<ReportParameter> reportParameters = report
> .getReportParameters();
>
> addToParametersMap(reportParameters, parametersMap);
> addToParametersMap(parameters, parametersMap);
>
> task.setParameterValues(parametersMap);
>
> if (!task.validateParameters())
> {
> throw new IllegalArgumentException(
> "Report parameter validation failed.");
> }
>
> task.run();
>
> task.close();
>
> return null;
> }
>
> private void addToParametersMap(Collection<ReportParameter> parameters,
> Map<String, Object> parametersMap)
> {
> for (ReportParameter parameter : parameters)
> {
> // TODO parameter value might not be a string
> parametersMap.put(parameter.getName(), parameter.getValue());
> }
> }
> }
>
> Hope this helps to unserstand my problem.
>
> Regards
> Ronny
|
|
| | | | | |
Goto Forum:
Current Time: Sun Jul 20 07:19:33 EDT 2025
Powered by FUDForum. Page generated in 0.04591 seconds
|