Home » Archived » BIRT » java.lang.IllegalStateException: zip file closed(while generating report using birt apis getting illegalestateException:zip file closed is coming)
|
Re: java.lang.IllegalStateException: zip file closed [message #649577 is a reply to message #649516] |
Wed, 19 January 2011 18:32 |
|
Can you post your code?
Jason
On 1/19/2011 9:40 AM, laxmipathi raju wrote:
> Hi,
> I am using birt apis to generate rpt files in my code. Some times i am
> getting the below error
>
> java.lang.IllegalStateException: zip file closed
> at java.util.zip.ZipFile.ensureOpen(ZipFile.java:516)
> at java.util.zip.ZipFile.getEntry(ZipFile.java:252)
> at java.util.jar.JarFile.getEntry(JarFile.java:197)
> at Jan 19, 2011 7:54:34 PM
> and the below error is following the above,
>
> org.eclipse.birt.report.engine.api.impl.RenderTask render
> SEVERE: An error happened while running the report. Cause:
> org.eclipse.birt.report.engine.api.EngineException: /pages doesnt exist
> at org.eclipse.birt.report.engine.internal.document.ReportPageE xecutor.
> <init>(ReportPageExecutor.java:50)
> at org.eclipse.birt.report.engine.api.impl.RenderTask$PageRange
> Render.render(RenderTask.java:479)
> at org.eclipse.birt.report.engine.api.impl.RenderTask.render(Re
> nderTask.java:220)
> at com.jataayu.reportapp.business.birt.BIRTConfiguration$TaskTh read.
> <init>(BIRTConfiguration.java:654)
>
>
>
> This is effecting the next reports generation also.
> can you please help me in solving this problem.
>
>
>
> Thanks & Regards,
> Laxmipathi Raju
|
|
|
Re: java.lang.IllegalStateException: zip file closed [message #649653 is a reply to message #649577] |
Thu, 20 January 2011 06:13 |
laxmipathi raju Messages: 17 Registered: April 2010 |
Junior Member |
|
|
Dear Jason,
Thanks for your reply. And here i am sending you the code snippets i am using.
Method 1:
public boolean generateHTMLFile(String designFilePath,
String rptDocFile, Object[] paramObjArr,
HttpServletRequest request, String htmlFile) throws OmegaException {
if (StringHandler.getTrimmedString(designFilePath).length() < 1
|| StringHandler.getTrimmedString(rptDocFile).length() < 1
|| StringHandler.getTrimmedString(htmlFile).length() < 1) {
return false;
}
IReportDocument rptDoc = BIRTConfiguration.runTask(designFilePath, paramObjArr, rptDocFile);
if(logger.isInfoEnabled()) {
logger.info("ReportDocument created successfully at path : "+rptDocFile);
}
if(rptDoc == null) {
return false;
}
if(request != null) {
cleanRedundantSession(request.getSession());
}
String context = request.getContextPath();
String requestURL = request.getRequestURL().toString();
String baseURL = requestURL.split(context)[0] + context;
String imgURL = baseURL + "/BIRT_Temp_Images";
String imgDir = request.getSession().getServletContext().getRealPath(
"/BIRT_Temp_Images");
if (logger.isInfoEnabled()) {
logger.info("[ Base URL : " + baseURL + " , Img Url : " + imgURL
+ " , Image Directory : " + imgDir);
}
HTMLRenderOption htmlOptions = new HTMLRenderOption();
htmlOptions.setOutputFileName(htmlFile);
htmlOptions.setOutputFormat(OmegaConstants.HTML_EXT_STR);
htmlOptions.setImageDirectory(imgDir);
htmlOptions.setBaseImageURL(imgURL);
htmlOptions.setEmbeddable(true);
htmlOptions.setHtmlPagination(true);
htmlOptions.setImageHandler(new HTMLServerImageHandler());
htmlOptions.setActionHandler(new MISAHTMLActionHandler());
if(BIRTConfiguration.renderTask(rptDoc, htmlOptions, request)) {
if(logger.isInfoEnabled()) {
logger.info("HTML file generated successfully at : "+htmlFile);
}
return true;
}else {
if(logger.isInfoEnabled()) {
logger.info("Failed to generate HTML file.");
}
return false;
}
}
Method 2:
public static IReportDocument runTask(String designFilePath,
Object[] paramObjectArr, String rptDocFile) throws OmegaException {
if(!FileUtils.isFileOrDirExists(designFilePath, FileUtils.FILE_ID)) {
throw new OmegaException(OmegaConstants.OMEGA_TEMPLATE_FILE_UNAVAILABL E);
}
IReportRunnable runnable = getReportRunnable(designFilePath);
IRunTask runTask = reportEngine.createRunTask(runnable);
if (paramObjectArr != null && paramObjectArr.length > 0) {
for (Object obj : paramObjectArr) {
Map<String, ?> map = null;
if (obj instanceof Map) {
map = (Map<String, ?>) obj;
}
if (map == null || map.isEmpty()) {
continue;
}
if (log.isInfoEnabled()) {
log.info("Parameter mapping : " + map);
}
runTask.setParameterValues(map);
}
}
if (!runTask.validateParameters()) {
log.error("Invalid parameter values passed.");
throw new OmegaException(OmegaConstants.OMEGA_DESIGN_FILE_INVALID_PARA METERS_FAILURE);
}
Thread t = null;
TaskThread taskThread;
try{
taskThread = new TaskThread(null, runTask, rptDocFile);
} catch (Exception e1) {
log.info("Error while Run task execution. Datasource may be invalid");
throw new OmegaException(OmegaConstants.OMEGA_DESIGN_FILE_DS_CONN_FAIL URE);
}
t = new Thread(taskThread);
t.start();
try {
t.join();
} catch (InterruptedException e) {
log.fatal("Interruted while rendering the task : ", e
.fillInStackTrace());
//must throw
}
runTask.close();
if(log.isInfoEnabled()) {
log.info("Run task is closed.");
}
if(!taskThread.isTaskSuccess()) {
throw new OmegaException(OmegaConstants.OMEGA_DESIGN_FILE_DS_CONN_FAIL URE);
}
try {
return reportEngine.openReportDocument(rptDocFile);
} catch (EngineException e) {
throw new OmegaException(OmegaConstants.OMEGA_REPORT_DOCUMENT_ACCESS_E RROR);
}
}
Method 3:
private static class TaskThread implements Runnable {
private volatile boolean done = false;
IRunTask runTask;
IRenderTask renderTask;
TaskThread(IRenderTask renderTask, IRunTask runTask, String fileName) {
try {
if (renderTask != null) {
this.renderTask = renderTask;
renderTask.render();
}
if (runTask != null) {
this.runTask = runTask;
runTask.run(fileName);
}
} catch (EngineException e) {
log.fatal("Exception completing the task.", e
.fillInStackTrace());
return;
}
}
The above methods i am using to generate a html file and it is failing in TaskThread().
Can Please help me out to solve this problem.
Thanks & Regards,
Laxmipathi Raju
|
|
|
Re: java.lang.IllegalStateException: zip file closed [message #649822 is a reply to message #649653] |
Thu, 20 January 2011 16:22 |
|
Every thread has to create a new task (ie run, render, or runandrender)
and then close the task with the thread. So only create one copy of the
BIRT engine and in every thread use the engine createTask method in it
and then close the task in the thread. Can you try this and let me know?
Jason
On 1/20/2011 1:13 AM, laxmipathi raju wrote:
> Dear Jason,
> Thanks for your reply. And here i am sending you the code snippets i am
> using.
> Method 1:
> public boolean generateHTMLFile(String designFilePath,
> String rptDocFile, Object[] paramObjArr,
> HttpServletRequest request, String htmlFile) throws OmegaException {
>
> if (StringHandler.getTrimmedString(designFilePath).length() < 1
> || StringHandler.getTrimmedString(rptDocFile).length() < 1
> || StringHandler.getTrimmedString(htmlFile).length() < 1) {
> return false;
> }
>
> IReportDocument rptDoc = BIRTConfiguration.runTask(designFilePath,
> paramObjArr, rptDocFile);
> if(logger.isInfoEnabled()) {
> logger.info("ReportDocument created successfully at path : "+rptDocFile);
> }
>
> if(rptDoc == null) {
> return false;
> }
>
> if(request != null) {
> cleanRedundantSession(request.getSession());
> }
>
> String context = request.getContextPath();
> String requestURL = request.getRequestURL().toString();
> String baseURL = requestURL.split(context)[0] + context;
> String imgURL = baseURL + "/BIRT_Temp_Images";
> String imgDir = request.getSession().getServletContext().getRealPath(
> "/BIRT_Temp_Images");
>
> if (logger.isInfoEnabled()) {
> logger.info("[ Base URL : " + baseURL + " , Img Url : " + imgURL
> + " , Image Directory : " + imgDir);
> }
>
> HTMLRenderOption htmlOptions = new HTMLRenderOption();
> htmlOptions.setOutputFileName(htmlFile);
> htmlOptions.setOutputFormat(OmegaConstants.HTML_EXT_STR);
> htmlOptions.setImageDirectory(imgDir);
> htmlOptions.setBaseImageURL(imgURL);
> htmlOptions.setEmbeddable(true);
> htmlOptions.setHtmlPagination(true);
> htmlOptions.setImageHandler(new HTMLServerImageHandler());
> htmlOptions.setActionHandler(new MISAHTMLActionHandler());
>
> if(BIRTConfiguration.renderTask(rptDoc, htmlOptions, request)) {
> if(logger.isInfoEnabled()) {
> logger.info("HTML file generated successfully at : "+htmlFile);
> }
> return true;
> }else {
> if(logger.isInfoEnabled()) {
> logger.info("Failed to generate HTML file.");
> }
> return false;
> }
> }
>
> Method 2:
> public static IReportDocument runTask(String designFilePath,
> Object[] paramObjectArr, String rptDocFile) throws OmegaException {
> if(!FileUtils.isFileOrDirExists(designFilePath, FileUtils.FILE_ID)) {
> throw new OmegaException(OmegaConstants.OMEGA_TEMPLATE_FILE_UNAVAILABL E);
> }
>
> IReportRunnable runnable = getReportRunnable(designFilePath);
> IRunTask runTask = reportEngine.createRunTask(runnable);
>
> if (paramObjectArr != null && paramObjectArr.length > 0) {
> for (Object obj : paramObjectArr) {
> Map<String, ?> map = null;
> if (obj instanceof Map) {
> map = (Map<String, ?>) obj;
> }
>
> if (map == null || map.isEmpty()) {
> continue;
> }
> if (log.isInfoEnabled()) {
> log.info("Parameter mapping : " + map);
> }
> runTask.setParameterValues(map);
> }
> }
>
> if (!runTask.validateParameters()) {
> log.error("Invalid parameter values passed.");
> throw new OmegaException(OmegaConstants.OMEGA_DESIGN_FILE_INVALID_PARA
> METERS_FAILURE);
> }
> Thread t = null;
> TaskThread taskThread;
> try{
> taskThread = new TaskThread(null, runTask, rptDocFile);
> } catch (Exception e1) {
> log.info("Error while Run task execution. Datasource may be invalid");
> throw new OmegaException(OmegaConstants.OMEGA_DESIGN_FILE_DS_CONN_FAIL
> URE);
> }
> t = new Thread(taskThread);
> t.start();
>
> try {
> t.join();
> } catch (InterruptedException e) {
> log.fatal("Interruted while rendering the task : ", e
> .fillInStackTrace());
> //must throw
> }
>
> runTask.close();
> if(log.isInfoEnabled()) {
> log.info("Run task is closed.");
> }
>
> if(!taskThread.isTaskSuccess()) {
> throw new OmegaException(OmegaConstants.OMEGA_DESIGN_FILE_DS_CONN_FAIL
> URE);
> }
>
> try {
> return reportEngine.openReportDocument(rptDocFile);
> } catch (EngineException e) {
> throw new OmegaException(OmegaConstants.OMEGA_REPORT_DOCUMENT_ACCESS_E
> RROR);
> }
> }
>
> Method 3:
> private static class TaskThread implements Runnable {
> private volatile boolean done = false;
> IRunTask runTask;
> IRenderTask renderTask;
>
> TaskThread(IRenderTask renderTask, IRunTask runTask, String fileName) {
> try {
> if (renderTask != null) {
> this.renderTask = renderTask;
> renderTask.render();
> }
>
> if (runTask != null) {
> this.runTask = runTask;
> runTask.run(fileName);
> }
> } catch (EngineException e) {
> log.fatal("Exception completing the task.", e
> .fillInStackTrace());
> return;
> }
> }
>
> The above methods i am using to generate a html file and it is failing
> in TaskThread().
> Can Please help me out to solve this problem.
>
>
>
> Thanks & Regards,
> Laxmipathi Raju
|
|
|
Goto Forum:
Current Time: Tue Sep 24 23:53:27 GMT 2024
Powered by FUDForum. Page generated in 0.03665 seconds
|