13/03/2007, 16h19
|
#3
|
|
Futur Membre du Club
Développeur informatique Inscription : juillet 2006 Messages : 33 Détails du profil  Informations personnelles : Âge : 39 Informations professionnelles :
Activité : Développeur informatique Informations forums :
Inscription : juillet 2006 Messages : 33 Points : 18 Points : 18
|
Je me suis fait ma propre servlet sans aucune méthode synchronisée.
Cependant quand je lance en même temps des états différents j'ai des erreurs.
Alors que si je les lances séparément ils fonctionnent.
Voici la méthode doGet de ma servlet
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
|
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
try {
// traitement des paramêtres
Enumeration paramsR = req.getParameterNames();
HashMap params = new HashMap();
while (paramsR.hasMoreElements()) {
String nom = (String)paramsR.nextElement();
if (!nom.equals("__report") && !nom.equals("__format")) {
if (nom.startsWith("ref") )
params.put(nom, new Integer(req.getParameter(nom)));
else
params.put(nom, req.getParameter(nom));
}
}
// lancement de l'état
XPREngine moteur = new XPREngine();
if (req.getParameter("__format").equals("html")) {
moteur.generateHTML(req.getParameter("__report"), params, res.getOutputStream());
} else {
res.setContentType("application/pdf");
moteur.generatePDF(req.getParameter("__report"), params, res.getOutputStream());
}
}
catch(Exception e) {
erreur(e, req, res, XErrorFactory.TYPE_ALERTE, 0, "Erreur lors de la génération de l'état.", e.getMessage(), "");
}
} |
et celui de ma classe XPREngine que j'ai créé à partir de bout de code trouvé sur le site de BIRT.
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
|
/*
* Créé le 30 juin 2006
*
*/
package xxxxx.reports;
import java.io.OutputStream;
import java.util.HashMap;
import org.eclipse.birt.report.engine.api.*;
import xxxxx.outils.xweb.XParamsAppliBean;
ublic class XPREngine {
private static EngineConfig config;
private static ReportEngine ENGINE;
static
{
config = new EngineConfig( );
config.setEngineHome( XParamsAppliBean.getBIRT_home() );
config.setLogConfig("", java.util.logging.Level.OFF);
ENGINE = new ReportEngine( config );
HTMLEmitterConfig hc = new HTMLEmitterConfig( );
HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler( );
hc.setImageHandler( imageHandler );
config.setEmitterConfiguration( HTMLRenderOption.OUTPUT_FORMAT_HTML, hc );
}
/**
* @param etat : chemin et nom du fichier .rptdesign
* @param params contient des paires nomParam, valeur
* @param fichierPDF : chemin et nom du fichier de généré
* @throws EngineException
*/
public void generatePDF(String etat, HashMap params, String fichierPDF) throws EngineException
{
IReportRunnable report = ENGINE.openReportDesign(etat);
IRunAndRenderTask task = ENGINE.createRunAndRenderTask( report );
HTMLRenderOption options = new HTMLRenderOption( );
options.setOutputFormat( HTMLRenderOption.OUTPUT_FORMAT_PDF );
options.setOutputFileName(fichierPDF);
task.setRenderOption( options );
task.setParameterValues( params );
if (!task.validateParameters())
throw new EngineException("Paramètre ou valeur invalide");
task.run( );
}
/**
* @param etat : chemin et nom du fichier .rptdesign
* @param params contient des paires nomParam, valeur
* @param sortie : flux de sortie
* @throws EngineException
*/
public void generatePDF(String etat, HashMap params, OutputStream sortie) throws Exception
{
generate(etat, params, sortie, HTMLRenderOption.OUTPUT_FORMAT_PDF);
}
/**
* @param etat : chemin et nom du fichier .rptdesign
* @param params contient des paires nomParam, valeur
* @param sortie : flux de sortie
* @throws EngineException
*/
public void generateHTML(String etat, HashMap params, OutputStream sortie) throws Exception
{
generate(etat, params, sortie, HTMLRenderOption.OUTPUT_FORMAT_HTML);
}
private void generate(String etat, HashMap params, OutputStream sortie, String type) throws Exception
{
IReportRunnable report = ENGINE.openReportDesign(XParamsAppliBean.getBIRT_home() + etat);
IRunAndRenderTask task = ENGINE.createRunAndRenderTask( report );
HTMLRenderOption options = new HTMLRenderOption( );
options.setOutputFormat( type);
options.setOutputStream(sortie);
task.setRenderOption( options );
if (type.equals(HTMLRenderOption.OUTPUT_FORMAT_HTML)) {
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setImageDirectory(XParamsAppliBean.getBIRT_home() + "/report/images/");
renderContext.setBaseImageURL("/Reports/report/images/");
HashMap contextMap = new HashMap();
contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );
task.setAppContext( contextMap );
}
task.setParameterValues( params );
task.run( );
task.close();
}
} |
Faut il qie je synchronise une partie de ce code ?
|
|
00
|