Home
Analytics
Cant startup the OSGI framework starting the Platform from a servlet
rali
Hi,<br />
<br />
i'm trying to create a report from a servlet but i keep getting:<br />
<em class='bbc'>org.eclipse.birt.core.exception.BirtException: Cant startup the OSGI framework<br />
at org.eclipse.birt.core.framework.Platform.startup(Platform.java:91)<br />
at test.SingleReport.doGet(SingleReport.java:61)<br />
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)<br />
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)<br />
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)<br />
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)<br />
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)<br />
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)<br />
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)<br />
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)<br />
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)<br />
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)<br />
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)<br />
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)<br />
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)<br />
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)<br />
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)<br />
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)<br />
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)<br />
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)<br />
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)<br />
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)<br />
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)<br />
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)<br />
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)<br />
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)<br />
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)<br />
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)<br />
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)<br />
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)<br />
Caused by: org.eclipse.birt.core.exception.BirtException: Can not start up OSGI - {0}<br />
at org.eclipse.birt.core.framework.osgi.OSGILauncher.startup(OSGILauncher.java:169)<br />
at org.eclipse.birt.core.framework.Platform.startup(Platform.java:79)<br />
... 29 more<br />
</em><br />
<br />
at the end I left only the part of the code that starts the Platform and i keep getting exactly the same error:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
import java.io.IOException;
import java.util.logging.Logger;
import javax.servlet.http.*;
import javax.servlet.*;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.*;
import java.util.logging.Level;
public class SingleReport extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
IReportEngine engine = null;
EngineConfig config = null;
try {
config = new EngineConfig();
config.setBIRTHome("c:/eclipse/birt-runtime/ReportEngine/");
config.setLogConfig("c:/birt/log", Level.ALL);
Platform.startup(config);
} catch (Exception ex) {
Logger.getLogger(SingleReport.class.getName()).log(Level.SEVERE, null, ex);
response.getOutputStream().println("qualcosa non va");
}
}
}
</pre> <br />
<br />
What's wrong? In a simple Java Application works perfectly. And there is no problem with the directory permissions.<br />
<br />
Regards<br />
Rali
Find more posts tagged with
Comments
bhanley
The issue is that the JVM cannot find the framework libraries. Just add an environment variable pointing to the "platform" directory under your BIRT installation. Call this variable "birthome";<br />
<br />
So your JVM (Tomcat for example) should get an additional parameter at startup like this:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>–Dbirthome="C:PROGRA~1ACTUAT~1JarBIRTplatform"</pre>
<br />
Good luck.
rali
Hi bhanley,<br />
<br />
actually i tried to restart the server and the first time i called the servlet everything worked perfectly. <br />
Without changing anything, i refreshed the page and got <br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
10-feb-2009 16.50.22 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet test di single report threw exception
java.lang.IllegalStateException
at org.mozilla.javascript.ContextFactory.initGlobal(ContextFactory.java:207)
at org.eclipse.birt.report.engine.api.impl.ReportEngine.<clinit>(ReportEngine.java:194)
at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory.createReportEngine(ReportEngineFactory.java:13)
at test.SingleReport.doGet(SingleReport.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:857)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
at java.lang.Thread.run(Unknown Source)
</pre>
<br />
then i refreshed once again the page and got:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
10-feb-2009 16.52.30 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet test di single report threw exception
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.birt.report.engine.api.impl.ReportEngine
at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory.createReportEngine(ReportEngineFactory.java:13)
at test.SingleReport.doGet(SingleReport.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:857)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
at java.lang.Thread.run(Unknown Source)
</pre>
<br />
The first log is from the catalina file, the second from the localhost file.<br />
<br />
How come the first time i invoke it everything works perfectly. I'm surely doing something wrong.
<br />
<br />
Oh by the way, the servlet is:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
package test;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.logging.Logger;
import javax.servlet.http.*;
import javax.servlet.*;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.*;
import java.util.logging.Level;
public class SingleReport extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
IReportEngine engine = null;
EngineConfig config = null;
try {
config = new EngineConfig();
config.setBIRTHome("c:/eclipse/birt-runtime/ReportEngine/");
config.setLogConfig("c:/birt/log", Level.ALL);
Platform.startup(config);
} catch (Exception ex) {
Logger.getLogger(SingleReport.class.getName()).log(Level.SEVERE, null, ex);
response.getOutputStream().println("qualcosa non va");
return;
}
HashMap param = new HashMap();
Enumeration token = request.getParameterNames();
while (token.hasMoreElements()) {
String name = (String) token.nextElement();
String[] param_value = request.getParameterValues(name);
param.put(name, param_value[0]);
}
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
IReportRunnable design = null;
try {
design = engine.openReportDesign("d:/eclipse/workspace/Designs/"+(String) param.get("reportDesign")+".rptdesign");
} catch (EngineException ex) {
Logger.getLogger(SingleReport.class.getName()).log(Level.SEVERE, null, ex);
return;
}
IRunTask runTask = engine.createRunTask(design);
runTask.setParameterValues(param);
try {
runTask.run("c:/birt/test.rptdocument");
} catch (EngineException ex) {
Logger.getLogger(SingleReport.class.getName()).log(Level.SEVERE, null, ex);
return;
}
IReportDocument reportDocument = null;
try {
reportDocument = engine.openReportDocument("c:/birt/test.rptdocument");
} catch (EngineException ex) {
Logger.getLogger(SingleReport.class.getName()).log(Level.SEVERE, null, ex);
return;
}
IRenderTask renderTask = engine.createRenderTask(reportDocument);
PDFRenderOption options = new PDFRenderOption();
options.setOutputFileName("c:/birt/test1.pdf");
options.setOutputFormat("pdf");
renderTask.setRenderOption(options);
try {
renderTask.render();
} catch (EngineException ex) {
Logger.getLogger(SingleReport.class.getName()).log(Level.SEVERE, null, ex);
return;
}
reportDocument.close();
engine.destroy();
Platform.shutdown();
}
}
</pre>
<br />
Thank you for your help. I really have no idea what to do
<br />
<br />
Regards<br />
<br />
Rali
bhanley
This likely has to do with the shard nature of Servlets. The app server tries to keep them in memory and re-use them for a small period of time to realize better overall performance. Yet your code is trying to instantiate the engine each and everytime the servlet is invoked.<br />
<br />
Try creating a class supporting your servlet that implements a Singleton pattern. This way you can leverage the same instance of the reporting engine over and over. Not only will the servlet not hit this issue, but you will be able to use this in other spots as well throughout your application. <br />
<br />
The following code is for a class that can get you an available instance of the engine. If it is not already created, then the create routine is invoked.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>public class BIRTEngineFactory {
private static final String DEFAULT_BIRT_HOME_PATH = "C:Program FilesActuate10Jarbirtplatform";
private static IReportEngine reportEngine = null;
public static IReportEngine getReportEngine() throws BirtException {
if (reportEngine == null)
createEngineInstance();
return reportEngine;
}
private static void createEngineInstance() throws BirtException {
EngineConfig engineConfig = new EngineConfig();
engineConfig.setEngineHome(getBIRTHome());
Platform.startup(engineConfig);
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
reportEngine = factory.createReportEngine(engineConfig);
}
}</pre>
<br />
The above code is not perfect, but it does the simple job your servlet needs.
rali
Hi bhanley,
now everything works. I thought that the engine.destroy instruction that i was using at the end of the code was destroying it everytime.
It is quite obvious that this is my first servlet. :$
Thank you very much!!!
Regards
Rali
kanya
Can u please explain me how and where to set the additional parameter in Tomcat startup... Am also having BIRTException. Can't Startup OSGI framework.. I don't know how to resolve this...<br />
<br />
> <blockquote class='ipsBlockquote' data-author="'bhanley'" data-cid="43058" data-time="1234279429" data-date="10 February 2009 - 08:23 AM"><p>
> The issue is that the JVM cannot find the framework libraries. Just add an environment variable pointing to > the "platform" directory under your BIRT installation. Call this variable "birthome";<br />
<br />
> So your JVM (Tomcat for example) should get an additional parameter at startup like this:<br />
<br />
> <pre class='_prettyXprint _lang-auto _linenums:0'>?Dbirthome="C:PROGRA~1ACTUAT~1JarBIRTplatform"</pre>
<br />
> Good luck.<br />
></p></blockquote>