Report engine fails to initialize html emitter.

Dewangan
edited February 11, 2022 in Analytics #1
Can anybody help me?
I am getting following error while running birt report:-
Report engine can not create html emitter.
org.eclipse.birt.report.engine.api.EngineException: Report engine fails to initi
alize html emitter, please make sure required libraries for this emitter are ins
talled.
at org.eclipse.birt.report.engine.api.impl.EngineTask.createContentEmitt
er(EngineTask.java:1111)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAnd
RenderTask.java:88)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRe
nderTask.java:68)
at com.emptoris.app.reports.helper.BirtReportServlet.doGet(BirtReportSer
vlet.java:106)

My java file is:-


package com.emptoris.app.reports.helper;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.logging.Level;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.birt.core.framework.IPlatformContext;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.core.framework.PlatformFileContext;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;
import org.eclipse.birt.report.engine.api.HTMLEmitterConfig;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
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.RenderOptionBase;
import org.eclipse.birt.report.engine.api.ReportEngine;


public class BirtReportServlet extends HttpServlet {

private EngineConfig config = null;
private IReportEngine engine = null;

public BirtReportServlet() {
super();
}

/**
* Destruction of the servlet.
*/
public void destroy() {
super.destroy();

}


/**
* The doGet method of the servlet.
*
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

//get report name and launch the engine
resp.setContentType("text/html");
ServletContext sc = req.getSession().getServletContext();
IReportRunnable design;
try
{
String designName = "C:BirtRptFilessample.rptdesign";
//Open report design
design = engine.openReportDesign( designName);

HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setBaseImageURL("C:Images");
renderContext.setImageDirectory("C:Images");
HashMap<String, HTMLRenderContext> contextMap = new HashMap<String, HTMLRenderContext>();
contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );

//create task to run and render report
IRunAndRenderTask task = engine.createRunAndRenderTask( design );
task.setAppContext( contextMap );

HTMLRenderOption options = new HTMLRenderOption();
//set the image handler to a HTMLServerImageHandler if you plan on using the base image url.
options.setImageHandler(new HTMLServerImageHandler());
String output = designName.replaceFirst( ".rptdesign", ".html" );
options.setOutputFileName( output );
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
task.setRenderOption(options);

//run report
task.run();
task.close();
}catch (Exception e){

e.printStackTrace();
throw new ServletException( e );
}
}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.println(" Post Not Supported");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}


public void init() throws ServletException {

try{
config = new EngineConfig( );
config.setEngineHome( "D:software_dBIRT2birt-runtime-2_2_2ReportEngine" );
HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler( );
HTMLEmitterConfig hc = new HTMLEmitterConfig( );
hc.setImageHandler( imageHandler );
config.setEmitterConfiguration( RenderOptionBase.OUTPUT_FORMAT_HTML, hc );
engine = new ReportEngine( config );

config.setLogConfig("c:temp", Level.FINE);
Platform.startup( config ); //If using RE API in Eclipse/RCP application this is not needed.
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
engine.changeLogLevel( Level.WARNING );


}catch( Exception ex){
ex.printStackTrace();

}

}

}



Application is failing while running task:-

task.run();

Thanks,
Bhushan

Comments

  • cypherdj
    edited December 31, 1969 #2
    Hi Bhushan,<br />
    <br />
    to start with, I would remove the following line from your init method:<br />
    <pre class='_prettyXprint _lang-auto _linenums:0'>
    engine = new ReportEngine( config );
    </pre>
    <br />
    secondly, since you are running the report within a servlet, you need to set the platform context, which tells the report engine where to find the various plugins (for instance, it won't find your DB driver since you need to place it in WEB-INFplatformpluginsorg.eclipse.birt.report.data.oda.jdbc_2.2.2.r22x_v20071206drivers). To do so, you will need to add the following to your init method:<br />
    <br />
    <pre class='_prettyXprint _lang-auto _linenums:0'>
    IPlatformContext context = new PlatformServletContext(servletConfig.getServletContext());
    config.setPlatformContext(context);
    </pre>
    <br />
    where servletConfig is a parameter of the init method. <br />
    See <a class='bbc_url' href='http://java.sun.com/products/servlet/2.1/api/javax.servlet.GenericServlet.html#init(javax.servlet.ServletConfig'>http://java.sun.com/products/servlet/2.1/api/javax.servlet.GenericServlet.html#init(javax.servlet.ServletConfig</a>)<br />
    <br />
    I tried removing the PlatformServletContext from my code and introducing your HTMLEmitterConfig which I didn't have before (it is deprecated), but could not reproduce your problem.<br />
    <br />
    Did you check that you have the coreapi.jar and engineapi.jar (at the very least) in WEB-INF/lib?