Skip to main content



      Home
Home » Archived » BIRT » Report Engine's exported files are never written and are locked until weblogic is shut down
Report Engine's exported files are never written and are locked until weblogic is shut down [message #202312] Tue, 21 November 2006 20:20
Eclipse UserFriend
Originally posted by: jeff.scott.rationalsystems.com

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

Hi, well my subject does a pretty good job outlining my situation. I've
got a function that takes in a created .rptdesign file and tries to
export it to pdf. When this function is run as part of an application
is goes along swimmingly.

However, when part of an ejb running on weblogic it doesn't. The file
gets created (opened and locked) but no data is ever sent into it and
even after the task.close() method is run, the pdf remains locked until
weblogic is shut down. It may just be when the app is shut down, i
don't know if I ever checked that difference now that I think about it.

I've attached the BirtAction which creates the .rptdesign and works
correctly when i look at it in eclipse. The executeReport() is the
function that has the problem, but only in an ejb.

Another thing of note, I've appended
c:\birt-runtime-2_1_1/ReportEngine/lib/js.jar to the beginning of
weblogic's application classpath so it doesn't use the old version
that's built in. The rest of the birt imports come later in the
classpath, though I don't see why that could be an issue.

Any ideas why the report engine might function differently in weblogic?
Thanks, Jeff

--------------070308080003000204090201
Content-Type: text/plain;
name="BirtAction.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="BirtAction.java"

package com.rbs.core.reporting.server.actions.custom;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
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.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IRenderOption;
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.IRunTask;
import org.eclipse.birt.report.engine.api.PDFRenderContext;
import org.eclipse.birt.report.engine.api.RenderOptionBase;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.GridHandle;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.SlotHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.TableHandle;

import com.ibm.icu.util.ULocale;
import com.rbs.core.common.RBSCodeValue;
import com.rbs.core.logging.common.LogManager;
import com.rbs.core.logging.common.RBSLogger;
import com.rbs.core.reporting.common.vo.PanelReportVO;
import com.rbs.core.reporting.common.vo.ReportingColumnData;

public class BirtAction {

private String rdlLocation = ".\\reportfiles\\temp\\";
private String birtRuntimeDir = "C:\\birt-runtime-2_1_1";

ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
StructureFactory structFactory = null;
IDesignEngine designEngine = null;
IReportEngine reportEngine= null;
DesignConfig designConfig = null;
EngineConfig reportConfig = null;
IDesignEngineFactory DeFactory = null;
IReportEngineFactory ReFactory = null;

private static RBSLogger log = LogManager.getLogger(BirtAction.class.getName());


public BirtAction() {
super();
log.debug("got to action");
//Configure the Engine and start the Platform
designConfig = new DesignConfig( );

designConfig.setProperty("BIRT_HOME", birtRuntimeDir + "\\ReportEngine");
try{


Platform.startup( designConfig );
IDesignEngineFactory DeFactory = (IDesignEngineFactory) Platform.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
designEngine = DeFactory.createDesignEngine( designConfig );

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




}

public ReportDesignHandle createRdl(PanelReportVO prVO) {
Calendar cal = new GregorianCalendar();
String inputRPT = ".\\reportfiles\\temp\\blank.rptdesign";
//String outputRDL = "c:\\workspaceBirt\\BirtTutorial1\\output.rptdesign";
String outputRDL = rdlLocation + "output" + cal.get(Calendar.HOUR) + cal.get(Calendar.MINUTE) + cal.get(Calendar.SECOND) + ".rptdesign";
log.debug("create RDL: " + outputRDL + " from: " + inputRPT);

//Connect to empty rdl for appending to it
try{

SessionHandle session = designEngine.newSessionHandle( ULocale.ENGLISH ) ;
//open a design or a template

//tmpDescignHandle = session.createDesign("temp");


designHandle = session.openDesign(inputRPT);
designFactory = designHandle.getElementFactory( );
}
catch (Exception e){
e.printStackTrace();
}

//Create add to actual rdl
try {
/** TITLE */
//GridHandle gridTitle = designFactory.newGridItem("title",1,1);



// table header

ArrayList cols = ((ArrayList)prVO.getMHeaders().get(0)); //array of ReportingColumnData
ArrayList rows = ((ArrayList)prVO.getMData().get(0));






//now with grids
GridHandle grid = designFactory.newGridItem("myGrid", cols.size(), rows.size()+1);

grid.setWidth("100%");


//initialize the title

RowHandle row = (RowHandle) grid.getRows().get(0);

//keep approximately the same table size as on the screen
int totalWidth = 0;
for (int j = 0; j<grid.getColumnCount(); j++)
totalWidth += ((ReportingColumnData)cols.get(j)).getWidth();

// now create the labels and input the data
ReportingColumnData rcd = new ReportingColumnData();
for (int i=0; i<cols.size(); i++) {
rcd = ((ReportingColumnData)cols.get(i));

LabelHandle label = designFactory.newLabel(rcd.getTitle().replace('.', ' ') );
label.setText( rcd.getTitle() );
//label.setName( rcd.getName() );
String width = 100*((double)rcd.getWidth())/totalWidth + "%";
label.setWidth(width);
CellHandle cell = (CellHandle)row.getCells().get(i);
cell.getContent().add(label);

}

//end title

//start data
for (int i=0; i<rows.size(); i++) { //row
ArrayList dataRow = (ArrayList)rows.get(i);
RowHandle gridRow = (RowHandle) grid.getRows().get(i+1);

for (int j=0; j<cols.size(); j++ ) {
rcd = ((ReportingColumnData)cols.get(j));
String name = ((String)rcd.getTitle() + i).replace('.', ' ');
LabelHandle label = designFactory.newLabel(name); //label names cannot have '.' in them
label.setText( ojbectToString(dataRow.get(j), "toFillIn, table names",rcd.getTitle()));
label.setName(name);
CellHandle cell = (CellHandle)gridRow.getCells().get(j);
cell.getContent().add(label);
}
}




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


/* SlotHandle sh = new SlotHandle(grid, 0);
for (int i=0; i < grid.getY().getAbsoluteValue().getMeasure() ; i++) { //row
for (int j=0; j < grid.getX().getAbsoluteValue().getMeasure() ; j++) { //col
sh = (SlotHandle)grid.getRows().getContents().get(j);
sh.get(i).addElement(designFactory.newLabel((String)cols.get (j)), 0);
sh = new SlotHandle(grid,1);
}
*/


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

//designHandle.getBody().add(gridTitle);
designHandle.getBody().add(grid);



/** Tables */

//designFactory = designHandle.getElementFactory( );

//buildDataSource();
//buildDataSet(cols, fromClause);

// TableHandle table = designFactory.newTableItem( "table", 4 );
// //table.setWidth( "100%" );
// //table.setDataSet( designHandle.findDataSet( "ds" ) );
//
// GridHandle grid = designFactory.newGridItem("grid", cols, 8);
// grid.setWidth("100%");

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

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


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


for( int i=0; i < cols.size(); i++){
LabelHandle label1 = designFactory.newLabel( (String)cols.get(i) );
label1.setText((String)cols.get(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.size(); i++){
CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );
DataItemHandle data = designFactory.newDataItem( "data_"+(String)cols.get(i) );
data.setResultSetColumn( (String)cols.get(i));
cell.getContent( ).add( data );
}
*/
//designHandle.getBody( ).add( table );
// designHandle.getBody().add(gridTitle);

// Save the design and close it.

designHandle.saveAs( outputRDL ); //$NON-NLS-1$
// designHandle.close( );

Platform.shutdown();

System.out.println(outputRDL);
//this.executeReport(outputRDL);
}catch (Exception e){
e.printStackTrace();
}
return designHandle;
}

public void executeReport(ReportDesignHandle rdh) throws EngineException
{
//HashMap<String, Integer> parameters = new HashMap<String, Integer>();
HashMap parameters = new HashMap();

// String name = "Top Count";
// Integer pvalue = new Integer(4);
//parameters.put(name, pvalue);
// System.out.println(parameters.get("Top Count"));

try{

//Configure the Engine and start the Platform
reportConfig = new EngineConfig( );
reportConfig.setEngineHome( "C:/birt-runtime-2_1_1/ReportEngine" );
//set log config using ( null, Level ) if you do not want a log file
reportConfig.setLogConfig("c:/birt-runtime-2_1_1/logs" , Level.FINE);

Platform.startup( reportConfig );
IReportEngineFactory ReFactory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
reportEngine = ReFactory.createReportEngine( reportConfig );
reportEngine.changeLogLevel( Level.WARNING );

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

//Open the report design
IReportRunnable design = null;
//design = engine.openReportDesign("C:/test/2.1/executereport/test.rptdesign ");
//design = engine.openReportDesign("C:/workspaceBirt/BirtTutorial1/"+rdlName+ ".rptdesign");
design = reportEngine.openReportDesign(rdh);

//Create task to run and render the report,
IRunAndRenderTask task = reportEngine.createRunAndRenderTask(design);
//IRunTask runner = reportEngine.createRunTask(design);



PDFRenderContext pdfRenderContext = new PDFRenderContext();
pdfRenderContext.setBaseURL("http://localhost/");
pdfRenderContext.setSupportedImageFormats("JPG;PNG;BMP;SVG");


//HashMap<String, HTMLRenderContext> contextMap = new HashMap<String, HTMLRenderContext>();
HashMap contextMap = new HashMap();
contextMap.put( EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT, pdfRenderContext );




task.setAppContext( contextMap );
//Set parameters for the report
//task.setParameterValues(parameters);
//Alternatively set each seperately
task.setParameterValue("Top Count", new Integer(122));
System.out.println(task.validateParameters());




IRenderOption rob = new RenderOptionBase();
rob.setOutputFileName("C:/test/2.1/outputBA.pdf");
rob.setOutputFormat("pdf");

task.setRenderOption(rob);

//run the report and destroy the engine
//Note - If the program stays resident do not shutdown the Platform or the Engine

task.run();
task.close();
//engine.shutdown();
//Platform.shutdown();
System.out.println("Finished Executing");
}


/**
* This will allow us to control the formatting manually serverside
* //TODO: Add in support for table name and column name specification...
* @param o
* @return
*/

private String ojbectToString(Object o, String table, String column) {
if (o instanceof GregorianCalendar ) {
GregorianCalendar gc = (GregorianCalendar)o;
//return gc.getTime().getMonth() + "/" + gc.getTime().getDate() + "/" + gc.getTime().getYear();
return gc.get(Calendar.MONTH) + "/" + gc.get(Calendar.DATE) + "/" + gc.get(Calendar.YEAR);
}
else if (o instanceof String)
return (String)o;
else if (o instanceof RBSCodeValue) {
RBSCodeValue rbsVal = (RBSCodeValue)o;
if (rbsVal.getValue() == null )
return rbsVal.getCd().toString();
else
return rbsVal.getValue().toString();
}

return o.toString();
}

}


--------------070308080003000204090201
Content-Type: text/plain;
name="BirtDriver.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="BirtDriver.java"

package com.rbs.core.reporting.server.actions.custom;

import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.model.api.ReportDesignHandle;

import com.rbs.core.logging.common.LogManager;
import com.rbs.core.logging.common.RBSLogger;
import com.rbs.core.reporting.common.vo.PanelReportVO;

/**
* This class may be necessary for stupid reasons
* @author Jeffrey
*
*/
public class BirtDriver {

private static RBSLogger log = LogManager.getLogger(BirtDriver.class.getName());

public static void drive(PanelReportVO prVO) {
log.debug("Driving...");

BirtAction ba = new BirtAction();
ReportDesignHandle rdh = ba.createRdl(prVO);
log.debug("ReportDesignHandle created, trying to execute");
try {
ba.executeReport(rdh);
//BirtExecution.executeReport(rdh);
}catch (EngineException ee) {
log.debug(ee);
}
}
}





/* int columns = 2;
DECreateDynamicTable dcdt = new DECreateDynamicTable();
BirtAction ba = new BirtAction();

try{
dcdt.buildReport(columns, "From Jeff");
} catch (SemanticException se) {
System.out.println(se);
} catch (IOException ios) {
System.out.println(ios);
}
try{
ExecuteReport.executeReport("output");
} catch (EngineException ee) {
System.out.println(ee);
}
}*/


--------------070308080003000204090201--
Previous Topic:web viewer caching reports
Next Topic:birt2.0.0 vs birt 2.1.1
Goto Forum:
  


Current Time: Thu Jul 17 10:03:24 EDT 2025

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

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

Back to the top