use Spring beans inside a BIRT report
#1
Posted 23 May 2012 - 06:11 AM
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.
#2
Posted 23 May 2012 - 06:25 AM
reportContext.getHttpServletRequest().getSession().getServletContext()
BTW have you read this article?
http://www.springsou...thSpringAndBIRT
Jason
#3
Posted 23 May 2012 - 07:02 AM
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
#5
Posted 23 May 2012 - 10:46 PM
JasonW, on 23 May 2012 - 01:58 PM, said:
Jason
Hi Jason,
I run the Birt in a web application using the web server Tomcat 5.5.
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.
Thank you for the help,
Ema
#7
Posted 24 May 2012 - 08:54 AM
//task like run or render
task.getAppContext().put(EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST, yourrequestobject);
Jason
#8
Posted 16 July 2012 - 05:04 AM
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





MultiQuote



