Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Birt 2.2 problem with loading ReportEngine in Tomcat
Birt 2.2 problem with loading ReportEngine in Tomcat [message #251450] Tue, 07 August 2007 12:23 Go to next message
Eclipse UserFriend
Originally posted by: khihlbe1.kekkonen.cs.hut.fi

Hello,

Sorry about the following post is a being a bit long, but I'm having
a huge problem with Birt 2.2 that I'm not able to fix.

I updated from Birt 2.1.1 to Birt 2.2 and I started getting the
following problem when viewing the reports on Tomcat server. It prints
on console "Can't load the report engine" and that causes a
NullPointerException later on my code when trying to call methods of
the report engine.

Because the "Can't load the report engine." print to console was
located in birt sourcecode I investigated it a bit. The "Can't load
the report engine" is printed from the class
org.eclipse.birt.report.engine.api.ReportEngine constructor and it
looks like the following.

<code>

public ReportEngine( EngineConfig config )
{
try
{
Platform.startup( config );
}
catch ( BirtException ex )
{
ex.printStackTrace( );
}
Object factory = Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
if ( factory instanceof IReportEngineFactory )
{
engine = ( (IReportEngineFactory) factory )
.createReportEngine( config );
}
if ( engine == null )
{
System.out.println( "Can't load the report engine" );
}
}

</code>

So, apparently the engine is null because it prints the "Can't load
the report engine". After a bit more investigation i found out, that
it never creates the engine because the if clause returns false in the
following part of the code.

if ( factory instanceof IReportEngineFactory )
{
engine = ( (IReportEngineFactory) factory )
.createReportEngine( config );
}

This is because the factory variable is also null. This is because the code

Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );

returns null. After a bit more investigation from the
org.eclipse.birt.core.framework.Platform class I found the root of the
problem there.

The startup method of the Platform class should create the Platform,
but for some reason it is left null. Here is the piece of code that
should create the platform.

<code>

try
{
launcher = new OSGILauncher( );
// startup the OSGi framework,
launcher.startup( config );
// the core plugins is loaded in the start up
// 1. platform should not be null any more.
// 2. the IFactoryService has been registed
// see
// org.eclipse.birt.core.plugin.CorePlugin#start(BundleContext
// context).
assert platform != null;
}
catch ( Exception ex )
{
platform = null;
throw new BirtException( "org.eclipse.birt.core", "Can't startup the OSGI framework",new Object[]{}, ex );
}

</code>

After debugging I found, that although the comments say that the
platform should not be null any more, it still is and I don't have any
idea what is wrong with that. I checked the logs from
"WEB-INF/platform/configuration" -folder and they say the following:

<logs>

!SESSION 2007-08-07 13:49:50.088 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.5.0_09
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=fi_FI

!ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.088
!MESSAGE Could not install bundle update@plugins/org.eclipse.emf.common_2.2.1.v200702131851.jar The activator org.eclipse.emf.common.CommonPlugin$Implementation for bundle org.eclipse.emf.common is invalid

!ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.104
!MESSAGE Could not install bundle update@plugins/org.eclipse.emf.ecore.xmi_2.2.2.v200702131851.jar The activator org.eclipse.emf.ecore.xmi.XMIPlugin$Implementation for bundle org.eclipse.emf.ecore.xmi is invalid

!ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.104
!MESSAGE Could not install bundle update@plugins/org.eclipse.emf.ecore_2.2.2.v200702131851.jar The activator org.eclipse.emf.ecore.plugin.EcorePlugin$Implementation for bundle org.eclipse.emf.ecore is invalid

</logs>

Here is also the code that I use to create the report engine. This is
mostly copied from examples from the book "Integrating and Extending
BIRT".

<code>

private static void initBirtEngine(ServletContext context) {
// Report _engine configuration
EngineConfig config = new EngineConfig();
config.setPlatformContext(new PlatformServletContext(context));

//Runs in the context
config.setEngineHome("");

//Set up image handler
HTMLEmitterConfig hc = new HTMLEmitterConfig();
hc.setImageHandler(new BirtImageHandler());

hc.setActionHandler(new BirtHTMLActionHandler());
config.setEmitterConfiguration(HTMLRenderOption.OUTPUT_FORMA T_HTML, hc);
try {
Platform.startup(config);
} catch(BirtException e) {
LOG.severe("Birt threw an Exception! " + e);
}
$engine = new ReportEngine(config);
LOG.info("Birt Engine initialized.");
}

</code>

Everything worked fine with Birt version 2.1.1 but with 2.2 it
doesn't. I still would like to use 2.2 because of the new features it
adds. Is this a bug with my code or Birt 2.2 source codes and how can
if fix this?

- Klaus Ihlberg
Re: Birt 2.2 problem with loading ReportEngine in Tomcat [message #251454 is a reply to message #251450] Tue, 07 August 2007 12:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: hmarmy.yahoo.com

Hi Klaus,

I think I faced the same problem.

I had to add in WEB-INF the "platform" directory (25 mb!!)

I do not think (or at least hope) that all this libs are mandatory.

So question for Birt Dev, which files/libs are *REALY* necessary to run
version 2.2 ??

Thanks
Hervé
Re: Birt 2.2 problem with loading ReportEngine in Tomcat [message #251539 is a reply to message #251450] Tue, 07 August 2007 18:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Did you replace all the libs in the web-inf/lib directory with the 2.2
libs and did you replace all the plugins in web-inf/platform/plugins
with the plugins from the 2.2 runtime download (not the designer download)?

Jason

Klaus Henrik Ihlberg wrote:
> Hello,
>
> Sorry about the following post is a being a bit long, but I'm having
> a huge problem with Birt 2.2 that I'm not able to fix.
>
> I updated from Birt 2.1.1 to Birt 2.2 and I started getting the
> following problem when viewing the reports on Tomcat server. It prints
> on console "Can't load the report engine" and that causes a
> NullPointerException later on my code when trying to call methods of
> the report engine.
>
> Because the "Can't load the report engine." print to console was
> located in birt sourcecode I investigated it a bit. The "Can't load
> the report engine" is printed from the class
> org.eclipse.birt.report.engine.api.ReportEngine constructor and it
> looks like the following.
>
> <code>
>
> public ReportEngine( EngineConfig config )
> {
> try
> {
> Platform.startup( config );
> }
> catch ( BirtException ex )
> {
> ex.printStackTrace( );
> }
> Object factory = Platform
> .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> if ( factory instanceof IReportEngineFactory )
> {
> engine = ( (IReportEngineFactory) factory )
> .createReportEngine( config );
> }
> if ( engine == null )
> {
> System.out.println( "Can't load the report engine" );
> }
> }
>
> </code>
>
> So, apparently the engine is null because it prints the "Can't load
> the report engine". After a bit more investigation i found out, that
> it never creates the engine because the if clause returns false in the
> following part of the code.
>
> if ( factory instanceof IReportEngineFactory )
> {
> engine = ( (IReportEngineFactory) factory )
> .createReportEngine( config );
> }
>
> This is because the factory variable is also null. This is because the code
>
> Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
>
> returns null. After a bit more investigation from the
> org.eclipse.birt.core.framework.Platform class I found the root of the
> problem there.
>
> The startup method of the Platform class should create the Platform,
> but for some reason it is left null. Here is the piece of code that
> should create the platform.
>
> <code>
>
> try
> {
> launcher = new OSGILauncher( );
> // startup the OSGi framework,
> launcher.startup( config );
> // the core plugins is loaded in the start up
> // 1. platform should not be null any more.
> // 2. the IFactoryService has been registed
> // see
> // org.eclipse.birt.core.plugin.CorePlugin#start(BundleContext
> // context).
> assert platform != null;
> }
> catch ( Exception ex )
> {
> platform = null;
> throw new BirtException( "org.eclipse.birt.core", "Can't startup the OSGI framework",new Object[]{}, ex );
> }
>
> </code>
>
> After debugging I found, that although the comments say that the
> platform should not be null any more, it still is and I don't have any
> idea what is wrong with that. I checked the logs from
> "WEB-INF/platform/configuration" -folder and they say the following:
>
> <logs>
>
> !SESSION 2007-08-07 13:49:50.088 -----------------------------------------------
> eclipse.buildId=unknown
> java.version=1.5.0_09
> java.vendor=Sun Microsystems Inc.
> BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=fi_FI
>
> !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.088
> !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.common_2.2.1.v200702131851.jar The activator org.eclipse.emf.common.CommonPlugin$Implementation for bundle org.eclipse.emf.common is invalid
>
> !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.104
> !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.ecore.xmi_2.2.2.v200702131851.jar The activator org.eclipse.emf.ecore.xmi.XMIPlugin$Implementation for bundle org.eclipse.emf.ecore.xmi is invalid
>
> !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.104
> !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.ecore_2.2.2.v200702131851.jar The activator org.eclipse.emf.ecore.plugin.EcorePlugin$Implementation for bundle org.eclipse.emf.ecore is invalid
>
> </logs>
>
> Here is also the code that I use to create the report engine. This is
> mostly copied from examples from the book "Integrating and Extending
> BIRT".
>
> <code>
>
> private static void initBirtEngine(ServletContext context) {
> // Report _engine configuration
> EngineConfig config = new EngineConfig();
> config.setPlatformContext(new PlatformServletContext(context));
>
> //Runs in the context
> config.setEngineHome("");
>
> //Set up image handler
> HTMLEmitterConfig hc = new HTMLEmitterConfig();
> hc.setImageHandler(new BirtImageHandler());
>
> hc.setActionHandler(new BirtHTMLActionHandler());
> config.setEmitterConfiguration(HTMLRenderOption.OUTPUT_FORMA T_HTML, hc);
> try {
> Platform.startup(config);
> } catch(BirtException e) {
> LOG.severe("Birt threw an Exception! " + e);
> }
> $engine = new ReportEngine(config);
> LOG.info("Birt Engine initialized.");
> }
>
> </code>
>
> Everything worked fine with Birt version 2.1.1 but with 2.2 it
> doesn't. I still would like to use 2.2 because of the new features it
> adds. Is this a bug with my code or Birt 2.2 source codes and how can
> if fix this?
>
> - Klaus Ihlberg
Re: Birt 2.2 problem with loading ReportEngine in Tomcat [message #251543 is a reply to message #251454] Tue, 07 August 2007 18:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

All are not required, but we do not specify a minimum. The reason for
this is that we can not know which functions of the runtime you are
going to use. For example if you do not require xls output or the xml
datasource these plugins can be removed.

Jason

Herve wrote:
> Hi Klaus,
>
> I think I faced the same problem.
>
> I had to add in WEB-INF the "platform" directory (25 mb!!)
>
> I do not think (or at least hope) that all this libs are mandatory.
>
> So question for Birt Dev, which files/libs are *REALY* necessary to run
> version 2.2 ??
>
> Thanks
> Hervé
>
>
>
>
Re: Birt 2.2 problem with loading ReportEngine in Tomcat [message #251628 is a reply to message #251539] Wed, 08 August 2007 06:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: khihlbe1.kekkonen.cs.hut.fi

Jason Weathersby <jasonweathersby@alltel.net> wrote:
> Did you replace all the libs in the web-inf/lib directory with the 2.2
> libs and did you replace all the plugins in web-inf/platform/plugins
> with the plugins from the 2.2 runtime download (not the designer download)?

Yes, I replaced the web-inf/platform/plugins folder with the
runtime-2.2 ReportEngine/plugins folder and also replaced all the libs
with the ReportEngine/lib .jar files.

> Klaus Henrik Ihlberg wrote:
> > Hello,
> >
> > Sorry about the following post is a being a bit long, but I'm having
> > a huge problem with Birt 2.2 that I'm not able to fix.
> >
> > I updated from Birt 2.1.1 to Birt 2.2 and I started getting the
> > following problem when viewing the reports on Tomcat server. It prints
> > on console "Can't load the report engine" and that causes a
> > NullPointerException later on my code when trying to call methods of
> > the report engine.
> >
> > Because the "Can't load the report engine." print to console was
> > located in birt sourcecode I investigated it a bit. The "Can't load
> > the report engine" is printed from the class
> > org.eclipse.birt.report.engine.api.ReportEngine constructor and it
> > looks like the following.
> >
> > <code>
> >
> > public ReportEngine( EngineConfig config )
> > {
> > try
> > {
> > Platform.startup( config );
> > }
> > catch ( BirtException ex )
> > {
> > ex.printStackTrace( );
> > }
> > Object factory = Platform
> > .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> > if ( factory instanceof IReportEngineFactory )
> > {
> > engine = ( (IReportEngineFactory) factory )
> > .createReportEngine( config );
> > }
> > if ( engine == null )
> > {
> > System.out.println( "Can't load the report engine" );
> > }
> > }
> >
> > </code>
> >
> > So, apparently the engine is null because it prints the "Can't load
> > the report engine". After a bit more investigation i found out, that
> > it never creates the engine because the if clause returns false in the
> > following part of the code.
> >
> > if ( factory instanceof IReportEngineFactory )
> > {
> > engine = ( (IReportEngineFactory) factory )
> > .createReportEngine( config );
> > }
> >
> > This is because the factory variable is also null. This is because the code
> >
> > Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> >
> > returns null. After a bit more investigation from the
> > org.eclipse.birt.core.framework.Platform class I found the root of the
> > problem there.
> >
> > The startup method of the Platform class should create the Platform,
> > but for some reason it is left null. Here is the piece of code that
> > should create the platform.
> >
> > <code>
> >
> > try
> > {
> > launcher = new OSGILauncher( );
> > // startup the OSGi framework,
> > launcher.startup( config );
> > // the core plugins is loaded in the start up
> > // 1. platform should not be null any more.
> > // 2. the IFactoryService has been registed
> > // see
> > // org.eclipse.birt.core.plugin.CorePlugin#start(BundleContext
> > // context).
> > assert platform != null;
> > }
> > catch ( Exception ex )
> > {
> > platform = null;
> > throw new BirtException( "org.eclipse.birt.core", "Can't startup the OSGI framework",new Object[]{}, ex );
> > }
> >
> > </code>
> >
> > After debugging I found, that although the comments say that the
> > platform should not be null any more, it still is and I don't have any
> > idea what is wrong with that. I checked the logs from
> > "WEB-INF/platform/configuration" -folder and they say the following:
> >
> > <logs>
> >
> > !SESSION 2007-08-07 13:49:50.088 -----------------------------------------------
> > eclipse.buildId=unknown
> > java.version=1.5.0_09
> > java.vendor=Sun Microsystems Inc.
> > BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=fi_FI
> >
> > !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.088
> > !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.common_2.2.1.v200702131851.jar The activator org.eclipse.emf.common.CommonPlugin$Implementation for bundle org.eclipse.emf.common is invalid
> >
> > !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.104
> > !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.ecore.xmi_2.2.2.v200702131851.jar The activator org.eclipse.emf.ecore.xmi.XMIPlugin$Implementation for bundle org.eclipse.emf.ecore.xmi is invalid
> >
> > !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.104
> > !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.ecore_2.2.2.v200702131851.jar The activator org.eclipse.emf.ecore.plugin.EcorePlugin$Implementation for bundle org.eclipse.emf.ecore is invalid
> >
> > </logs>
> >
> > Here is also the code that I use to create the report engine. This is
> > mostly copied from examples from the book "Integrating and Extending
> > BIRT".
> >
> > <code>
> >
> > private static void initBirtEngine(ServletContext context) {
> > // Report _engine configuration
> > EngineConfig config = new EngineConfig();
> > config.setPlatformContext(new PlatformServletContext(context));
> >
> > //Runs in the context
> > config.setEngineHome("");
> >
> > //Set up image handler
> > HTMLEmitterConfig hc = new HTMLEmitterConfig();
> > hc.setImageHandler(new BirtImageHandler());
> >
> > hc.setActionHandler(new BirtHTMLActionHandler());
> > config.setEmitterConfiguration(HTMLRenderOption.OUTPUT_FORMA T_HTML, hc);
> > try {
> > Platform.startup(config);
> > } catch(BirtException e) {
> > LOG.severe("Birt threw an Exception! " + e);
> > }
> > $engine = new ReportEngine(config);
> > LOG.info("Birt Engine initialized.");
> > }
> >
> > </code>
> >
> > Everything worked fine with Birt version 2.1.1 but with 2.2 it
> > doesn't. I still would like to use 2.2 because of the new features it
> > adds. Is this a bug with my code or Birt 2.2 source codes and how can
> > if fix this?
> >
> > - Klaus Ihlberg

--
Klaus Ihlberg | "I got a letter from the government the other day /
040 867 6180 | I opened and read it / It said they were suckers"
| -Public Enemy: Black Steel in the Hour of Chaos
Re: Birt 2.2 problem with loading ReportEngine in Tomcat [message #251674 is a reply to message #251628] Wed, 08 August 2007 14:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

This is a multi-part message in MIME format.
--------------090606040000000301050404
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

In 2.2 you do not need the Emiiter Config, but this should not be
causing this issue. Take a look at this example.

Jason

Klaus Henrik Ihlberg wrote:
> Jason Weathersby <jasonweathersby@alltel.net> wrote:
>> Did you replace all the libs in the web-inf/lib directory with the 2.2
>> libs and did you replace all the plugins in web-inf/platform/plugins
>> with the plugins from the 2.2 runtime download (not the designer download)?
>
> Yes, I replaced the web-inf/platform/plugins folder with the
> runtime-2.2 ReportEngine/plugins folder and also replaced all the libs
> with the ReportEngine/lib .jar files.
>
>> Klaus Henrik Ihlberg wrote:
>>> Hello,
>>>
>>> Sorry about the following post is a being a bit long, but I'm having
>>> a huge problem with Birt 2.2 that I'm not able to fix.
>>>
>>> I updated from Birt 2.1.1 to Birt 2.2 and I started getting the
>>> following problem when viewing the reports on Tomcat server. It prints
>>> on console "Can't load the report engine" and that causes a
>>> NullPointerException later on my code when trying to call methods of
>>> the report engine.
>>>
>>> Because the "Can't load the report engine." print to console was
>>> located in birt sourcecode I investigated it a bit. The "Can't load
>>> the report engine" is printed from the class
>>> org.eclipse.birt.report.engine.api.ReportEngine constructor and it
>>> looks like the following.
>>>
>>> <code>
>>>
>>> public ReportEngine( EngineConfig config )
>>> {
>>> try
>>> {
>>> Platform.startup( config );
>>> }
>>> catch ( BirtException ex )
>>> {
>>> ex.printStackTrace( );
>>> }
>>> Object factory = Platform
>>> .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
>>> if ( factory instanceof IReportEngineFactory )
>>> {
>>> engine = ( (IReportEngineFactory) factory )
>>> .createReportEngine( config );
>>> }
>>> if ( engine == null )
>>> {
>>> System.out.println( "Can't load the report engine" );
>>> }
>>> }
>>>
>>> </code>
>>>
>>> So, apparently the engine is null because it prints the "Can't load
>>> the report engine". After a bit more investigation i found out, that
>>> it never creates the engine because the if clause returns false in the
>>> following part of the code.
>>>
>>> if ( factory instanceof IReportEngineFactory )
>>> {
>>> engine = ( (IReportEngineFactory) factory )
>>> .createReportEngine( config );
>>> }
>>>
>>> This is because the factory variable is also null. This is because the code
>>>
>>> Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
>>>
>>> returns null. After a bit more investigation from the
>>> org.eclipse.birt.core.framework.Platform class I found the root of the
>>> problem there.
>>>
>>> The startup method of the Platform class should create the Platform,
>>> but for some reason it is left null. Here is the piece of code that
>>> should create the platform.
>>>
>>> <code>
>>>
>>> try
>>> {
>>> launcher = new OSGILauncher( );
>>> // startup the OSGi framework,
>>> launcher.startup( config );
>>> // the core plugins is loaded in the start up
>>> // 1. platform should not be null any more.
>>> // 2. the IFactoryService has been registed
>>> // see
>>> // org.eclipse.birt.core.plugin.CorePlugin#start(BundleContext
>>> // context).
>>> assert platform != null;
>>> }
>>> catch ( Exception ex )
>>> {
>>> platform = null;
>>> throw new BirtException( "org.eclipse.birt.core", "Can't startup the OSGI framework",new Object[]{}, ex );
>>> }
>>>
>>> </code>
>>>
>>> After debugging I found, that although the comments say that the
>>> platform should not be null any more, it still is and I don't have any
>>> idea what is wrong with that. I checked the logs from
>>> "WEB-INF/platform/configuration" -folder and they say the following:
>>>
>>> <logs>
>>>
>>> !SESSION 2007-08-07 13:49:50.088 -----------------------------------------------
>>> eclipse.buildId=unknown
>>> java.version=1.5.0_09
>>> java.vendor=Sun Microsystems Inc.
>>> BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=fi_FI
>>>
>>> !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.088
>>> !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.common_2.2.1.v200702131851.jar The activator org.eclipse.emf.common.CommonPlugin$Implementation for bundle org.eclipse.emf.common is invalid
>>>
>>> !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.104
>>> !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.ecore.xmi_2.2.2.v200702131851.jar The activator org.eclipse.emf.ecore.xmi.XMIPlugin$Implementation for bundle org.eclipse.emf.ecore.xmi is invalid
>>>
>>> !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.104
>>> !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.ecore_2.2.2.v200702131851.jar The activator org.eclipse.emf.ecore.plugin.EcorePlugin$Implementation for bundle org.eclipse.emf.ecore is invalid
>>>
>>> </logs>
>>>
>>> Here is also the code that I use to create the report engine. This is
>>> mostly copied from examples from the book "Integrating and Extending
>>> BIRT".
>>>
>>> <code>
>>>
>>> private static void initBirtEngine(ServletContext context) {
>>> // Report _engine configuration
>>> EngineConfig config = new EngineConfig();
>>> config.setPlatformContext(new PlatformServletContext(context));
>>>
>>> //Runs in the context
>>> config.setEngineHome("");
>>>
>>> //Set up image handler
>>> HTMLEmitterConfig hc = new HTMLEmitterConfig();
>>> hc.setImageHandler(new BirtImageHandler());
>>>
>>> hc.setActionHandler(new BirtHTMLActionHandler());
>>> config.setEmitterConfiguration(HTMLRenderOption.OUTPUT_FORMA T_HTML, hc);
>>> try {
>>> Platform.startup(config);
>>> } catch(BirtException e) {
>>> LOG.severe("Birt threw an Exception! " + e);
>>> }
>>> $engine = new ReportEngine(config);
>>> LOG.info("Birt Engine initialized.");
>>> }
>>>
>>> </code>
>>>
>>> Everything worked fine with Birt version 2.1.1 but with 2.2 it
>>> doesn't. I still would like to use 2.2 because of the new features it
>>> adds. Is this a bug with my code or Birt 2.2 source codes and how can
>>> if fix this?
>>>
>>> - Klaus Ihlberg
>

--------------090606040000000301050404
Content-Type: java/*;
name="BirtEngine.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="BirtEngine.java"



import java.io.InputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;

import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.IReportEngine;
import javax.servlet.*;
import org.eclipse.birt.core.framework.PlatformServletContext;
import org.eclipse.birt.core.framework.IPlatformContext;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.ReportEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.IDesignEngine;
//import my.plugin.IMyFactory;

public class BirtEngine {

private static IReportEngine birtEngine = null;
private static IDesignEngine birtDesignEngine = null;
//private static IMyFactory myFactory = null;

private static Properties configProps = new Properties();

private final static String configFile = "BirtConfig.properties";


/* public static synchronized String getMyFactory(ServletContext sc){

String rtn = null;

Object myFactory = Platform.createFactoryObject("my.plugin.MyFactory");

if( myFactory == null){
System.out.println("BAdd factory");
}

if ( myFactory instanceof IMyFactory )
{
rtn = ( (IMyFactory) myFactory ).getMyString();
}else{
System.out.println("No Instance");
}

System.out.println( "FactoryClass = " + myFactory.getClass().toString());
System.out.println( myFactory.getClass().getClassLoader().toString());
System.out.println( "Imyfactory interface " + IMyFactory.class.getClassLoader().toString());

//IMyFactory testMyFactory = null;// = (IMyFactory)objMyFact;

return rtn;

}*/
public static synchronized void initBirtConfig() {
loadEngineProps();
}

public static synchronized IReportEngine getBirtEngine(ServletContext sc) {
if (birtEngine == null)
{
//System.setProperty("java.io.tmpdir", "c:/temp/pp");
//System.setProperty("javax.servlet.context.tempdir", "c:/temp/myplat");
EngineConfig config = new EngineConfig();
//config.setOSGiArguments(arguments);
if( configProps != null){
String logLevel = configProps.getProperty("logLevel");
Level level = Level.OFF;
if ("SEVERE".equalsIgnoreCase(logLevel))
{
level = Level.SEVERE;
} else if ("WARNING".equalsIgnoreCase(logLevel))
{
level = Level.WARNING;
} else if ("INFO".equalsIgnoreCase(logLevel))
{
level = Level.INFO;
} else if ("CONFIG".equalsIgnoreCase(logLevel))
{
level = Level.CONFIG;
} else if ("FINE".equalsIgnoreCase(logLevel))
{
level = Level.FINE;
} else if ("FINER".equalsIgnoreCase(logLevel))
{
level = Level.FINER;
} else if ("FINEST".equalsIgnoreCase(logLevel))
{
level = Level.FINEST;
} else if ("OFF".equalsIgnoreCase(logLevel))
{
level = Level.OFF;
}

config.setLogConfig(configProps.getProperty("logDirectory"), level);
}

config.setBIRTHome("");
IPlatformContext context = new PlatformServletContext( sc );
config.setPlatformContext( context );


//Create the report engine
//birtEngine = new ReportEngine( config );
//ReportEngine engine = new ReportEngine( null );


try
{
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
birtEngine = factory.createReportEngine( config );
}
catch ( Exception e )
{
e.printStackTrace( );
}
}
return birtEngine;
}

public static synchronized void destroyBirtEngine() {
if (birtEngine == null) {
return;
}
birtEngine.destroy();
Platform.shutdown();
birtEngine = null;
}

public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}

private static void loadEngineProps() {
try {
//Config File must be in classpath
ClassLoader cl = Thread.currentThread ().getContextClassLoader();
InputStream in = null;
in = cl.getResourceAsStream (configFile);
configProps.load(in);
in.close();


} catch (IOException e) {
e.printStackTrace();
}

}

}

--------------090606040000000301050404
Content-Type: java/*;
name="DynamicReport.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="DynamicReport.java"


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

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.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException ;
import org.eclipse.birt.report.model.api.elements.structures.Comput edColumn;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
//import my.plugin.*;

public class DynamicReport extends HttpServlet {

/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor of the object.
*/
private IReportEngine birtReportEngine = null;
protected static Logger logger = Logger.getLogger( "org.eclipse.birt" );

public DynamicReport() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy();
BirtEngine.destroyBirtEngine();
}


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

//get report name and launch the engine
resp.setContentType("text/html");
//resp.setContentType( "application/pdf" );
//resp.setHeader ("Content-Disposition","inline; filename=test.pdf");
String reportName = req.getParameter("ReportName");
String[] cols = (String[])req.getParameterMap().get("dyna1");
ServletContext sc = req.getSession().getServletContext();
this.birtReportEngine = BirtEngine.getBirtEngine(sc);

//String myFactory = BirtEngine.getMyFactory(sc);
//if( myFactory == null){
// System.out.println("Bad Factory Object");
//}
//System.out.println("My factory string " + myFactory);


logger.log( Level.FINE, "image directory " + sc.getRealPath("/images"));
System.out.println("stdout image directory " + sc.getRealPath("/images"));


IReportRunnable design;
try
{
//Open report design
design = birtReportEngine.openReportDesign( sc.getRealPath("/Reports")+"/"+reportName );
ReportDesignHandle report = (ReportDesignHandle) design.getDesignHandle( );
buildReport( cols, report );

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

//PDFRenderOption options = new PDFRenderOption();
HTMLRenderOption options = new HTMLRenderOption();

options.setOutputFormat("html");
//options.setImageDirectory("c:/temp/images");


//ImageHandlerTest
//options.setImageHandler(new MyImageHandler());
options.setImageHandler(new HTMLServerImageHandler());
options.setImageDirectory(sc.getRealPath("/images"));
options.setBaseImageURL(req.getContextPath()+"/images");

//resp.setHeader(
// "Content-Disposition", "inline; filename=\"test.pdf\"" );
//resp.setContentType( "application/pdf" );
//
options.setOutputStream(resp.getOutputStream());
task.setRenderOption(options);

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

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

public void buildReport(String[] cols, ReportDesignHandle designHandle){


try{
ElementFactory designFactory = designHandle.getElementFactory( );

buildDataSource(designFactory, designHandle);


//ArrayList cols = new ArrayList();
//cols.add("OFFICECODE");
//cols.add("CITY");
//cols.add("COUNTRY");

buildDataSet(cols, "From Offices", designFactory, designHandle);

TableHandle table = designFactory.newTableItem( "table", cols.length );
table.setWidth( "100%" );
table.setDataSet( designHandle.findDataSet( "ds" ) );


PropertyHandle computedSet = table.getColumnBindings( );
ComputedColumn cs1 = null;

for( int i=0; i < cols.length; i++){
cs1 = StructureFactory.createComputedColumn();
cs1.setName((String)cols[i]);
cs1.setExpression("dataSetRow[\"" + (String)cols[i] + "\"]");
computedSet.addItem(cs1);
}


// table header
RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );


for( int i=0; i < cols.length; i++){
LabelHandle label1 = designFactory.newLabel( (String)cols[i] );
label1.setText((String)cols[i]);
CellHandle cell = (CellHandle) tableheader.getCells( ).get( i );
cell.getContent( ).add( label1 );
}

// table detail
RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
for( int i=0; i < cols.length; i++){
CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );
DataItemHandle data = designFactory.newDataItem( "data_"+(String)cols[i] );
data.setResultSetColumn( (String)cols[i]);
cell.getContent( ).add( data );
}



designHandle.getBody( ).add( table );
}catch(Exception e){
e.printStackTrace();
}

}

void buildDataSource( ElementFactory designFactory, ReportDesignHandle designHandle ) throws SemanticException
{

OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
"Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
dsHandle.setProperty( "odaDriverClass",
"org.eclipse.birt.report.data.oda.sampledb.Driver" );
dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
dsHandle.setProperty( "odaUser", "ClassicModels" );
dsHandle.setProperty( "odaPassword", "" );

designHandle.getDataSources( ).add( dsHandle );

}

void buildDataSet(String[] cols, String fromClause, ElementFactory designFactory, ReportDesignHandle designHandle ) throws SemanticException
{

OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select ";
for( int i=0; i < cols.length; i++){
qry += " " + cols[i];
if( i != (cols.length -1) ){
qry += ",";
}

}
qry += " " + fromClause;

dsHandle.setQueryText( qry );

designHandle.getDataSets( ).add( dsHandle );


}


/**
* The doPost method of the servlet. <br>
*
*/
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();
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
BirtEngine.initBirtConfig();

}

}


--------------090606040000000301050404--
Re: Birt 2.2 problem with loading ReportEngine in Tomcat [message #251834 is a reply to message #251674] Thu, 09 August 2007 09:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: khihlbe1.kekkonen.cs.hut.fi

Jason Weathersby <jasonweathersby@alltel.net> wrote:
> In 2.2 you do not need the Emiiter Config, but this should not be
> causing this issue. Take a look at this example.

I checked the examples and changed my code to open report designs that
way and that seems to work ok. Thanks for the help.

- Klaus


> Klaus Henrik Ihlberg wrote:
> > Jason Weathersby <jasonweathersby@alltel.net> wrote:
> >> Did you replace all the libs in the web-inf/lib directory with the 2.2
> >> libs and did you replace all the plugins in web-inf/platform/plugins
> >> with the plugins from the 2.2 runtime download (not the designer download)?
> >
> > Yes, I replaced the web-inf/platform/plugins folder with the
> > runtime-2.2 ReportEngine/plugins folder and also replaced all the libs
> > with the ReportEngine/lib .jar files.
> >
> >> Klaus Henrik Ihlberg wrote:
> >>> Hello,
> >>>
> >>> Sorry about the following post is a being a bit long, but I'm having
> >>> a huge problem with Birt 2.2 that I'm not able to fix.
> >>>
> >>> I updated from Birt 2.1.1 to Birt 2.2 and I started getting the
> >>> following problem when viewing the reports on Tomcat server. It prints
> >>> on console "Can't load the report engine" and that causes a
> >>> NullPointerException later on my code when trying to call methods of
> >>> the report engine.
> >>>
> >>> Because the "Can't load the report engine." print to console was
> >>> located in birt sourcecode I investigated it a bit. The "Can't load
> >>> the report engine" is printed from the class
> >>> org.eclipse.birt.report.engine.api.ReportEngine constructor and it
> >>> looks like the following.
> >>>
> >>> <code>
> >>>
> >>> public ReportEngine( EngineConfig config )
> >>> {
> >>> try
> >>> {
> >>> Platform.startup( config );
> >>> }
> >>> catch ( BirtException ex )
> >>> {
> >>> ex.printStackTrace( );
> >>> }
> >>> Object factory = Platform
> >>> .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> >>> if ( factory instanceof IReportEngineFactory )
> >>> {
> >>> engine = ( (IReportEngineFactory) factory )
> >>> .createReportEngine( config );
> >>> }
> >>> if ( engine == null )
> >>> {
> >>> System.out.println( "Can't load the report engine" );
> >>> }
> >>> }
> >>>
> >>> </code>
> >>>
> >>> So, apparently the engine is null because it prints the "Can't load
> >>> the report engine". After a bit more investigation i found out, that
> >>> it never creates the engine because the if clause returns false in the
> >>> following part of the code.
> >>>
> >>> if ( factory instanceof IReportEngineFactory )
> >>> {
> >>> engine = ( (IReportEngineFactory) factory )
> >>> .createReportEngine( config );
> >>> }
> >>>
> >>> This is because the factory variable is also null. This is because the code
> >>>
> >>> Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> >>>
> >>> returns null. After a bit more investigation from the
> >>> org.eclipse.birt.core.framework.Platform class I found the root of the
> >>> problem there.
> >>>
> >>> The startup method of the Platform class should create the Platform,
> >>> but for some reason it is left null. Here is the piece of code that
> >>> should create the platform.
> >>>
> >>> <code>
> >>>
> >>> try
> >>> {
> >>> launcher = new OSGILauncher( );
> >>> // startup the OSGi framework,
> >>> launcher.startup( config );
> >>> // the core plugins is loaded in the start up
> >>> // 1. platform should not be null any more.
> >>> // 2. the IFactoryService has been registed
> >>> // see
> >>> // org.eclipse.birt.core.plugin.CorePlugin#start(BundleContext
> >>> // context).
> >>> assert platform != null;
> >>> }
> >>> catch ( Exception ex )
> >>> {
> >>> platform = null;
> >>> throw new BirtException( "org.eclipse.birt.core", "Can't startup the OSGI framework",new Object[]{}, ex );
> >>> }
> >>>
> >>> </code>
> >>>
> >>> After debugging I found, that although the comments say that the
> >>> platform should not be null any more, it still is and I don't have any
> >>> idea what is wrong with that. I checked the logs from
> >>> "WEB-INF/platform/configuration" -folder and they say the following:
> >>>
> >>> <logs>
> >>>
> >>> !SESSION 2007-08-07 13:49:50.088 -----------------------------------------------
> >>> eclipse.buildId=unknown
> >>> java.version=1.5.0_09
> >>> java.vendor=Sun Microsystems Inc.
> >>> BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=fi_FI
> >>>
> >>> !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.088
> >>> !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.common_2.2.1.v200702131851.jar The activator org.eclipse.emf.common.CommonPlugin$Implementation for bundle org.eclipse.emf.common is invalid
> >>>
> >>> !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.104
> >>> !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.ecore.xmi_2.2.2.v200702131851.jar The activator org.eclipse.emf.ecore.xmi.XMIPlugin$Implementation for bundle org.eclipse.emf.ecore.xmi is invalid
> >>>
> >>> !ENTRY org.eclipse.update.configurator 2007-08-07 13:49:50.104
> >>> !MESSAGE Could not install bundle update@plugins/org.eclipse.emf.ecore_2.2.2.v200702131851.jar The activator org.eclipse.emf.ecore.plugin.EcorePlugin$Implementation for bundle org.eclipse.emf.ecore is invalid
> >>>
> >>> </logs>
> >>>
> >>> Here is also the code that I use to create the report engine. This is
> >>> mostly copied from examples from the book "Integrating and Extending
> >>> BIRT".
> >>>
> >>> <code>
> >>>
> >>> private static void initBirtEngine(ServletContext context) {
> >>> // Report _engine configuration
> >>> EngineConfig config = new EngineConfig();
> >>> config.setPlatformContext(new PlatformServletContext(context));
> >>>
> >>> //Runs in the context
> >>> config.setEngineHome("");
> >>>
> >>> //Set up image handler
> >>> HTMLEmitterConfig hc = new HTMLEmitterConfig();
> >>> hc.setImageHandler(new BirtImageHandler());
> >>>
> >>> hc.setActionHandler(new BirtHTMLActionHandler());
> >>> config.setEmitterConfiguration(HTMLRenderOption.OUTPUT_FORMA T_HTML, hc);
> >>> try {
> >>> Platform.startup(config);
> >>> } catch(BirtException e) {
> >>> LOG.severe("Birt threw an Exception! " + e);
> >>> }
> >>> $engine = new ReportEngine(config);
> >>> LOG.info("Birt Engine initialized.");
> >>> }
> >>>
> >>> </code>
> >>>
> >>> Everything worked fine with Birt version 2.1.1 but with 2.2 it
> >>> doesn't. I still would like to use 2.2 because of the new features it
> >>> adds. Is this a bug with my code or Birt 2.2 source codes and how can
> >>> if fix this?
> >>>
> >>> - Klaus Ihlberg
> >

> [-- application/octet-stream, encoding 7bit, 156 lines, name: BirtEngine.java --]

> [-- application/octet-stream, encoding 7bit, 264 lines, name: DynamicReport.java --]


--
Klaus Ihlberg | "I got a letter from the government the other day /
040 867 6180 | I opened and read it / It said they were suckers"
| -Public Enemy: Black Steel in the Hour of Chaos
Re: Birt 2.2 problem with loading ReportEngine in Tomcat [message #253223 is a reply to message #251834] Wed, 22 August 2007 10:04 Go to previous message
Eclipse UserFriend
Originally posted by: suryakant.in.ibm.com

Hello.,
I am also facing the same situation. I am using a scripted data source.
Could you please help in sorting out my problem. where shd the jar files
of the data source be placed and where shd i be putting the report design
and where should i be copying my java file which will be generating report
and which i will be calling in my java web application
Thank you
surya
Previous Topic:Does Word emitter in BIRT 2.2M6 generate TOC?
Next Topic:Empty report using scripted datasource - BIRT 2.1.3
Goto Forum:
  


Current Time: Thu Apr 25 19:09:05 GMT 2024

Powered by FUDForum. Page generated in 0.03641 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top