Home
Analytics
unable to catch birt exception in java code
harsimran
Hi
I am using BIRT run time engine 2.6.2 to genarte my reports from web app.If path to birt-runtime-2_6_2 is not
correct or user permission problem
i am getting following error.But i am unable to catch as a BirtException inside my code.so these error appear in
tomcat catlaine logs.i want to catch this and want to populate proper error message inside my application log not
in tomcat cataline logs.Expecting help on this i am new to BIRT coding.
Oct 12, 2011 4:07:18 PM org.eclipse.birt.report.engine.api.ReportEngine <init>
SEVERE: error.CannotStartupOSGIPlatform
org.eclipse.birt.core.exception.BirtException: error.CannotStartupOSGIPlatform
at org.eclipse.birt.core.framework.Platform.startup(Platform.java:92)
at org.eclipse.birt.report.engine.api.ReportEngine.<init>(ReportEngine.java:59)
at com.nsn.ccsf.bam.reportService.generator.ReportGenerator.<clinit>(ReportGenerator.java:113)
at com.nsn.ccsf.bam.reportService.schedule.BamReportInstance.getInstance(BamReportInstance.java:65)
at com.nsn.ccsf.bam.reportService.schedule.BamReportInstance.startCCSFReportEngine(BamReportInstance.java:106)
at com.nsn.ccsf.bam.reportService.startup.ReportServletContextListener.contextInitialized
(ReportServletContextListener.java:69)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Find more posts tagged with
Comments
JasonW
Do you have a try catch around the platform startup?
Jason
harsimran
hi Jason
thanks for reply .Here is sample code which i am using to startup engine please have a look.But none of method here throw birt Exception.So i cant surronder try catch.i tried with catching simply Exception or Throwable object but no success.
but as per exception logs its throwing BirtException but we cant catch it and all logs going tomcat logs
private static EngineConfig engineConfig;
private static ReportEngine engine;
static {
engineConfig = new EngineConfig();
enginePath = System
.getProperty(ENGINE_PATH);
dateFormat = new SimpleDateFormat(pattern);
dateFolderFormat = new SimpleDateFormat(patterndateFolder);
engineConfig.setEngineHome(enginePath);
HTMLEmitterConfig hc = new HTMLEmitterConfig();
HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler();
hc.setImageHandler(imageHandler);
engineConfig.setEmitterConfiguration(
HTMLRenderOption.OUTPUT_FORMAT_HTML, hc);
Map xlsConfig = new HashMap();
// Check out constants in XlsEmitterConfig.java for more
// configuration detail.
xlsConfig.put("remove_empty_row", true);
xlsConfig.put("export_single_page", true);
xlsConfig.put("export_body_only", true);
xlsConfig.put("fixed_column_width", new Integer(50)); //$NON-NLS-1$
// Associate the configuration with the XLS output format.
engineConfig.setEmitterConfiguration(XLS_FORMAT, xlsConfig);
// Create the report engine itself. This engine can be used to run
// multiple reports.
engine = new ReportEngine(engineConfig);
logger.debug("Loaded BIRT Engine Startup Parameter");
}
CBR
Do you want to catch exceptions occured during report generation? (the one beeing printed out in red as last element of your report?)
You can't really catch these exceptions (as far as i know) but you can get them by using task.getErrors() on the task you have been using the generate the report.
JasonW
I think this may be both. I did not see in your code where you are starting up the engine. This error
SEVERE: error.CannotStartupOSGIPlatform
Implies the platform startup is not working, so the task will never be available.
Jason
harsimran
Hi
i am attaching class which i am using using to genrate reports.Please check if anything i missed or i am doing correctly.
I am Calling createReport(....) method to genrate reports.
please suggest for any change.also i want to catch all exceptions in my logs.
Thanks in advance!
JasonW
Take a look at the ReportRunner class from the source that is attached. You need to do a Platform.startup and if your process is going to continue to run after creating the report you should only start the platform once and use one engine to create all of your reports. A simple example would be like:
package REAPI;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.RenderOption;
public class RunAndRenderTaskXLS {
public void runReport() throws EngineException
{
IReportEngine engine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:\\birt\\birt-runtime-2_6_2\\ReportEngine");
config.setLogConfig("c:/temp/test", Level.FINEST);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
IReportRunnable design = null;
//Open the report design
design = engine.openReportDesign("Reports/customers.rptdesign");
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
RenderOption options = new RenderOption();
//options.setOutputFormat("doc");
//options.setOutputFileName("output/resample/customers.doc");
options.setOutputFormat("xls");
options.setOutputFileName("output/resample/customers.xls");
task.setRenderOption(options);
task.run();
task.close();
engine.destroy();
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
Platform.shutdown( );
System.out.println("Finished");
}
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
RunAndRenderTaskXLS ex = new RunAndRenderTaskXLS( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
In the above example it is assumed that the process does not continue to run. If the process where going to continue I would have created a singleton around getting/creating the birt engine and just re-used it. An example of that approach would be using the engine in a servlet as described here:
http://wiki.eclipse.org/Servlet_Example_(BIRT)_2.1
Jason
harsimran
Hi jason.
Yes my requirement is like process will keep on running for long period of time.Set of Reports will schduled and they will trigerred at any specific time.Other Set of reports are dynamic and they will genrate immediatly.As you suggest i will plan to migrate to second option but still i have few doubts.
1)wonder how my old code working smoothly without any issue?.
2)Can we catch BirtException and Engine Exception in our logs?
thanks for reply
Rgards
Harsimran