Bug 123705 ClassCastException when trying to cast IReportContext.getHttpServletRequest() to HttpServletRequest
When scripting in Java, I try to get the http servlet request. IReportContext.getHttpServletRequest() returns an object, which by inspection seems to implement javax.servlet.HttpServletRequest. But I get a ClassCastException when trying to cast the object to a HttpServletRequest. The java project with the event handler class has $ECLIPSE_HOME/plugins/org.eclipse.tomcat_4.1.30.1/servlet.jar on the build path. I'm guessing there might be a class loader problem? Here is the code: public void onCreate(IImageInstance image, IReportContext reportContext) { Object o = reportContext.getHttpServletRequest(); Class[] interfaces = o.getClass().getInterfaces(); for (int i = 0; i < interfaces.length; i++) System.out.println(interfaces[i]); HttpServletRequest request = (HttpServletRequest)reportContext.getHttpServletRequest(); } The printout of the System.out is: interface javax.servlet.http.HttpServletRequest The exception is: Error0 : Error.UnhandledScriptError ( 1 time(s) ) detail : org.eclipse.birt.report.engine.api.EngineException: Unhandled exception when executing script at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.addException(ScriptExecutor.java:204) at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.addException(ScriptExecutor.java:194) at org.eclipse.birt.report.engine.script.internal.ImageScriptExecutor.handleOnCreate(ImageScriptExecutor.java:62) at org.eclipse.birt.report.engine.executor.ImageItemExecutor.execute(ImageItemExecutor.java:120) at org.eclipse.birt.report.engine.executor.ReportExecutorVisitor.visitImageItem(ReportExecutorVisitor.java:203) at org.eclipse.birt.report.engine.ir.ImageItemDesign.accept(ImageItemDesign.java:91) at org.eclipse.birt.report.engine.executor.ReportExecutor.execute(ReportExecutor.java:121) at org.eclipse.birt.report.engine.executor.ReportExecutor.execute(ReportExecutor.java:87) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:175) at org.eclipse.birt.report.services.ReportEngineService.runAndRenderReport(ReportEngineService.java:442) at org.eclipse.birt.report.viewer.aggregation.layout.EngineFragment.doService(EngineFragment.java:100) at org.eclipse.birt.report.viewer.aggregation.BaseFragment.service(BaseFragment.java:156) at org.eclipse.birt.report.viewer.servlet.ViewerServlet.doGet(ViewerServlet.java:172) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.eclipse.tomcat.internal.EclipseErrorReportValve.invoke(EclipseErrorReportValve.java:153) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:534)Caused by: java.lang.ClassCastException at ImageImpl.onCreate(ImageImpl.java:22) at org.eclipse.birt.report.engine.script.internal.ImageScriptExecutor.handleOnCreate(ImageScriptExecutor.java:59) ... 44 more
engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/executor/ExecutionContext.java
design = ( ReportItemDesign ) content.getGenerateBy( );
			handle = design == null ? null : design.getHandle( );
		} else
			handle = getHandle( );
		addException( handle, ex );
	}
	protected HashMap elementExceptions = new HashMap( );
	public void addException( DesignElementHandle element, BirtException ex )
	{
		ElementExceptionInfo exInfo = ( ElementExceptionInfo ) elementExceptions
				.get( element );
		if ( exInfo == null )
		{
			exInfo = new ElementExceptionInfo( element );
			if ( reportContent != null )
				reportContent.getErrors( ).add( exInfo );
			else
				onPrepareErrors.add( exInfo );
			elementExceptions.put( element, exInfo );
		}
		exInfo.addException( ex );
	}
	/**
	 * report object is the script object used in the script context.
	 * 
	 * All infos can get from this object.
	 * 
	 * 
	 */
	private class ReportObject