|
Re: Accessing http session attributes in report [message #365924 is a reply to message #365923] |
Wed, 12 November 2008 21:12 |
Eclipse User |
|
|
|
Originally posted by: jasonweathersby.alltel.net
Nicoloas,
Add this to your code:
task.getAppContext().put(
EngineContstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVLET_REQUEST, pRequest);
The example viewer does this, but if you write your own servlet you will
need to do it. BTW I assume this is not a servlet for production. Make
sure for production you only start the engine once.
Jason
Nicolas wrote:
> Hello,
>
> I don't manage to access http session attributes in my reports.
> I do the following in the beforeFactory method of my report (as advised
> in the tutorial):
>
> var request = reportContext.getHttpServletRequest();
> var session = request.getSession();
>
> and I get this error:
>
> TypeError: Cannot call method "getSession" of null
> (/report/method[@name="beforeFactory"]#2).
> at
> org.eclipse.birt.report.engine.executor.ExecutionContext.eva luate(ExecutionContext.java:639)
>
> at
> org.eclipse.birt.report.engine.script.internal.ScriptExecuto r.handleJSInternal(ScriptExecutor.java:60)
>
> at
> org.eclipse.birt.report.engine.script.internal.ScriptExecuto r.handleJS(ScriptExecutor.java:47)
>
> at
> org.eclipse.birt.report.engine.script.internal.ReportScriptE xecutor.handleBeforeFactory(ReportScriptExecutor.java:67)
>
> at
> org.eclipse.birt.report.engine.api.impl.EngineTask.startFact ory(EngineTask.java:1318)
>
> at
> org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doR un(RunAndRenderTask.java:90)
>
> at
> org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run (RunAndRenderTask.java:72)
>
> at test.BirtServlet.doGet(BirtServlet.java:45)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
> at
> com.ibm.ws.webcontainer.servlet.ServletWrapper.service(Servl etWrapper.java:989)
>
> at
> com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest (ServletWrapper.java:501)
>
> at
> com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleReque st(ServletWrapper.java:464)
>
> at
> com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.j ava:3276)
> at
> com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGro up.java:267)
> at
> com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContai ner.java:811)
> at
> com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebCont ainer.java:1455)
>
> at
> com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChanne lLink.java:113)
> at
> com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleD iscrimination(HttpInboundLink.java:454)
>
> at
> com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleN ewInformation(HttpInboundLink.java:383)
>
> at
> com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(H ttpInboundLink.java:263)
>
> at
> com.ibm.ws.ssl.channel.impl.SSLConnectionLink.determineNextC hannel(SSLConnectionLink.java:1002)
>
> at
> com.ibm.ws.ssl.channel.impl.SSLConnectionLink.readyInboundPo stHandshake(SSLConnectionLink.java:691)
>
> at
> com.ibm.ws.ssl.channel.impl.SSLConnectionLink.readyInbound(S SLConnectionLink.java:547)
>
> at
> com.ibm.ws.ssl.channel.impl.SSLConnectionLink.ready(SSLConne ctionLink.java:279)
>
> at
> com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback .sendToDiscriminators(NewConnectionInitialReadCallback.java: 214)
>
> at
> com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback .complete(NewConnectionInitialReadCallback.java:113)
>
> at
> com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.future Completed(AioReadCompletionListener.java:165)
>
> at
> com.ibm.io.async.AbstractAsyncFuture.invokeCallback(Abstract AsyncFuture.java:217)
>
> at
> com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(As yncChannelFuture.java:161)
>
> at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
> at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:1 95)
> at
> com.ibm.io.async.ResultHandler.runEventProcessingLoop(Result Handler.java:743)
>
> at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
> at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
> Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot call
> method "getSession" of null (/report/method[@name="beforeFactory"]#2)
> at
> org.mozilla.javascript.ScriptRuntime.constructError(ScriptRu ntime.java:3350)
>
> at
> org.mozilla.javascript.ScriptRuntime.constructError(ScriptRu ntime.java:3340)
>
> at
> org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime .java:3356)
> at
> org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntim e.java:3375)
> at
> org.mozilla.javascript.ScriptRuntime.undefCallError(ScriptRu ntime.java:3394)
>
> at
> org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis( ScriptRuntime.java:2026)
>
> at
> org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRun time.java:117)
> at
> org.mozilla.javascript.gen.c4._c0(/report/method[@name="beforeFactory "]:2)
> at
> org.mozilla.javascript.gen.c4.call(/report/method[@name="beforeFactory "])
> at
> org.mozilla.javascript.ContextFactory.doTopCall(ContextFacto ry.java:393)
> at
> org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime .java:2834)
> at
> org.mozilla.javascript.gen.c4.call(/report/method[@name="beforeFactory "])
> at
> org.mozilla.javascript.gen.c4.exec(/report/method[@name="beforeFactory "])
> at
> org.eclipse.birt.core.script.ScriptContext.eval(ScriptContex t.java:241)
> at
> org.eclipse.birt.report.engine.executor.ExecutionContext.eva luate(ExecutionContext.java:635)
>
> ... 34 more
>
> I wrote a small servlet to run my report and demonstrate my problem:
>
> public class BirtServlet extends HttpServlet {
>
> protected void doGet(HttpServletRequest pRequest, HttpServletResponse
> pResponse) throws ServletException, IOException {
>
> /*Make sure we have a session */
> pRequest.getSession(true);
> try {
> EngineConfig config = new EngineConfig();
> config.setEngineHome("");
> config.setPlatformContext(new PlatformServletContext(getServletContext()));
> Platform.startup(config);
>
> IReportEngineFactory factory = (IReportEngineFactory)
> Platform.createFactoryObject(IReportEngineFactory.EXTENSION_ REPORT_ENGINE_FACTORY);
>
> IReportEngine engine = factory.createReportEngine(config);
>
> IReportRunnable design =
> engine.openReportDesign(getServletContext().getResourceAsStr eam( "/MyReport.rptdesign"));
>
> IRunAndRenderTask task = engine.createRunAndRenderTask(design);
>
> HTMLRenderOption options = new HTMLRenderOption();
> options.setOutputStream(pResponse.getOutputStream());
> options.setOutputFormat("html");
> task.setRenderOption(options);
>
> task.run();
> task.close();
>
> engine.destroy();
> Platform.shutdown();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
>
> Can anyone help me on this?
>
> Note that I tested my report with the WebViewerExample from the BIRT
> runtime and it works fine in that case. So there must be something wrong
> in my servlet or with the configuration of my report engine.
>
> I am running the BIRT 2.3.0 runtime on Websphere 6.1, the plugins are
> located in the WEB-INF\platform directory of my WAR and the BIRT jars
> were copied into the WEB-INF\lib directory of the WAR.
>
> Here is my report design for convenience:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- Written by Eclipse BIRT 2.0 -->
> <report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.6"
> id="1">
> <property name="createdBy">Eclipse BIRT Designer Version
> 2.1.2.v20070205-1728 Build <20070205-1728></property>
> <property name="units">in</property>
> <property name="comments">Copyright (c) 2006 <<Your Company
> Name here>></property>
> <method name="beforeFactory"><![CDATA[var request =
> reportContext.getHttpServletRequest();
> var session = request.getSession();
> session.setAttribute("test", "hello");]]></method>
> <page-setup>
> <simple-master-page name="Simple MasterPage" id="2">
> <page-footer>
> <text id="3">
> <property name="contentType">html</property>
> <text-property name="content"><![CDATA[<value-of>new
> Date()</value-of>]]></text-property>
> </text>
> </page-footer>
> </simple-master-page>
> </page-setup>
> <body>
> <label id="4">
> <text-property name="text">MyReport</text-property>
> </label>
> <text-data id="5">
> <expression
> name="valueExpr">session.getAttribute("test")</expression >
> <property name="contentType">html</property>
> </text-data>
> </body>
> </report>
>
>
> Any help would be greatly appreciated!!!
> Nicolas
>
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03335 seconds