bonjour
j ai récupéré le rapport birt sous .rtpdocument a partir du server birt iserver sous forme d'un inputstream mais quand je l affiche j ai une erreur qui se produise, voila le code que j utiliser pour recupere mon rapport du server
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringWriter;
import java.net.URL;
import java.rmi.RemoteException;
import org.eclipse.birt.core.archive.compound.IArchiveFile;
import org.eclipse.birt.core.exception.BirtException;
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.IDocumentWriter;
import org.eclipse.birt.report.engine.api.IRenderOption;
import org.eclipse.birt.report.engine.api.IRenderTask;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.RenderOption;
import org.eclipse.birt.report.engine.api.RenderOptionBase;
import com.actuate.idapi.client.ActuateSession;
import com.actuate.idapi.client.ActuateSessionException;
import com.actuate.idapi.client.ActuateSessionFactory;
import com.actuate.idapi.client.FileDownload;
import com.actuate.idapi.client.ReportSessionBuilder;
import com.actuate.idapi.client.ServerFile;
import com.actuate.idapi.client.Utilities;
import com.actuate.idapi.examples.BaseExample;
import com.actuate.schemas.Attachment;
import com.actuate.schemas.DownloadFileResponse;
import com.actuate.schemas.ExecuteReportResponse;
public class RunReport extends BaseExample {
private static RunReport m_instance = null;
public String IDAPI_HOST = "localhost";
public int IDAPI_PORT = 8000;
private IReportEngine engine;
private IRenderOption option;
public RunReport() throws BirtException {
EngineConfig config = new EngineConfig();
config.setBIRTHome( "C:/birt-runtime-2_5_0/birt-runtime-2_5_0/ReportEngine");
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
option = new RenderOption();
}
public static void main(String[] args) throws RemoteException, Throwable {
(new RunReport()).runReport();
}
@SuppressWarnings("deprecation")
private void runReport( ) throws ActuateSessionException, IOException, EngineException {
String userName = "administrator";
String password = "birtadmin";
URL endpoint = Utilities.makeUrl( IDAPI_HOST, IDAPI_PORT );
ActuateSessionFactory factory = new ActuateSessionFactory( );
ActuateSession session = null;
factory.setDefaultVolume("Birtiserver");
session = factory.login(endpoint,userName, password);
String inputFileName = "/Home/administrator/Mardi2.rptdesign";
String outputFileName ="/Home/administrator/";
ServerFile reportFile = new ServerFile( session, inputFileName );
try {
System.out.println(reportFile.getFileId());
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ReportSessionBuilder jobBuilder = reportFile.runSyncReport( );
ServerFile outputFile = null;
outputFile = new ServerFile( session, outputFileName );
jobBuilder.setOutputFolder(outputFile);
ExecuteReportResponse executeReportResponse = jobBuilder.start( );
String idreport = executeReportResponse.getObjectId();
FileDownload download = new FileDownload(session, idreport);
download.send( );
InputStream in = download.getDataStream( );
StringWriter writer=new StringWriter();
InputStreamReader streamReader=new InputStreamReader(in);
//le buffer permet le readline
BufferedReader buffer=new BufferedReader(streamReader);
String line="";
while ( null!=(line=buffer.readLine())){
writer.write(line);
}
// Sortie finale dans le String
String str = writer.toString();
IReportDocument bon = engine.openReportDocument(str);
IRenderTask renderTask = engine.createRenderTask(bon);
option.setOutputFormat(RenderOptionBase.OUTPUT_FORMAT_PDF);
renderTask.setRenderOption(option);
renderTask.render(); |
j ai une erreur qui se produit lors de lexecution de ce code
Code :
1 2 3 4 5 6 7 8
|
Exception in thread "main" java.lang.NullPointerException
at java.io.File.<init>(Unknown Source)
at org.eclipse.birt.report.engine.api.impl.ReportEngineHelper.openReportDocument(ReportEngineHelper.java:422)
at org.eclipse.birt.report.engine.api.impl.ReportEngineHelper.openReportDocument(ReportEngineHelper.java:396)
at org.eclipse.birt.report.engine.api.impl.ReportEngine.openReportDocument(ReportEngine.java:579)
at com.actuate.idapi.client.test.RunReport.runReport(RunReport.java:97)
at com.actuate.idapi.client.test.RunReport.main(RunReport.java:53) |