Home
Analytics
use Spring beans inside a BIRT report
EmaAlina
Hi guys,
I have a problem related to the BIRT reports.
The problem is that my application uses spring, and the objects can
not be instantiated directly. Instead they have to be accessed through the
web application context like -
///////////////////////////////////////////////
WebApplicationContext wapp =
WebApplicationContextUtils.getRequiredWebApplicationContext(getServletConfig().servletContext());
return wapp .getBean(name);
///////////////////////////////////////////////
If I could get servletContext somehow in BIRT, this could be used.
However, I could not find the way to do this and I would need to find a way to access it from the BIRT report.
If you have any ideas, please let me know.
Find more posts tagged with
Comments
JasonW
You can get the servlet context in script like:
reportContext.getHttpServletRequest().getSession().getServletContext()
BTW have you read this article?
http://www.springsource.org/BusinessIntelligenceWithSpringAndBIRT
Jason
EmaAlina
Hi Jason,
I have read the article and I try to use the information from it in my Birt repot but when I call the method getSession() I receive an error as : "Cannot call method "getSession" of null".
Below is the code that I added in the report :
<method name="initialize"><!<CDATA[
importPackage(Packages.org.springframework.web.context);
importPackage(Packages.org.springframework.context);
importPackage(Packages.org.springframework.web.context.support);
var sc = reportContext.getHttpServletRequest().getSession().getServletContext();
springWebAppContext = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
var service = springWebAppContext.getBean("myBean");
]]></method>
Is there something wrong?
Thank you for the help,
Ema
JasonW
How are you running BIRT? Are you using the BIRT Viewer?
Jason
EmaAlina
<blockquote class='ipsBlockquote' data-author="'JasonW'" data-cid="101253" data-time="1337806735" data-date="23 May 2012 - 01:58 PM"><p>
How are you running BIRT? Are you using the BIRT Viewer?<br />
<br />
Jason<br /></p></blockquote>
Hi Jason,<br />
<br />
I run the Birt in a web application using the web server Tomcat 5.5.<br />
So, I have a Spring bean in my webapp, in WEB-INF/MyConfig folder. I would need to find a way to access it from the BIRT report. <br />
<br />
Thank you for the help,<br />
<br />
Ema
EmaAlina
Hi Jason,
I don?t have the HttpServletRequest object available within a deployed report.The IReportContext has the method getHttpSerlvetRequest() but for me that always returns null. Is this a bug of the BIRT report?
How can I fix that bug?
Thanks,
Ema
JasonW
No this is not a bug. If you are using the engine you have to load the request object into the appcontext. The Birt Viewer does this by using something similar to:
//task like run or render
task.getAppContext().put(EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST, yourrequestobject);
Jason
vartika
Hi Jason,
I am using IRenderOption and even after setting this
iRenderTask.getAppContext().put( EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST, request )
I am getting error TypeError: Cannot call method "getSession" of null.
If you have any idea please let me know.
Vartika
JasonW
Generally that command is entered on a run task not a render task. Where are you calling the getSession?
Jason