Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » BIRT & gzip problem?
BIRT & gzip problem? [message #646337] Thu, 23 December 2010 07:03 Go to next message
Missing name Missing name is currently offline Missing name Missing name
Messages: 55
Registered: July 2010
Member
Hello,

I continue my old discussion

http://www.eclipse.org/forums/index.php?t=msg&th=200471& amp;start=0&S=ae0a82523ba358e5ca8bd169eb4ad907

As Jason wrote the BIRT uses allways the iText setFullCompression method. I found out that for my big test material the winzip compress the BIRT pdf to the 5% size.

So I tried to use the GZIPOutputStream for my servlet. My servlet processed the gzip file, but I couldn't open the unzipped file with the Adobe reader.

So I wrote the simple java program, which runs simple BIRT report with the simple data. I run the program and used gunzip. I got the error message "There was an error opening this document. Access denied" when I tried to open the file with the Adobe reader. This error message sound like I don't have rights to open the file, but file is only read-only.

It is possible that this problem is not related on the BIRT, but is there some problem with my Java program?

Thanks,

Mika

GzipRunReport.java:

import java.io.File;
import java.io.FileOutputStream;
import java.util.zip.GZIPOutputStream;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.ReportEngine;

public class GzipRunReport {
	public static void main(String[] args) throws Exception {
		GZIPOutputStream gzipOutputStream = null;
		ReportEngine engine = null;
		try {
			String templateFilename = "C:\\birtWorkspace\\BirtEsittely\\reports\\simple.rptdesign";
			//String templateFilename = "C:\\testiRapo.rptdesign";
			EngineConfig config = new EngineConfig();
			config
					.setEngineHome("C:\\birt-runtime-2_6_1\\ReportEngine");
			// Create the report engine.
			engine = new ReportEngine(config);
			IReportRunnable report = null;
			// Create the report
			report = engine.openReportDesign(templateFilename);
			// Create the task
			IRunAndRenderTask task = engine.createRunAndRenderTask(report);
			// Set the options
			HTMLRenderOption options = new HTMLRenderOption();
			options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);
			File file = new File("c:\\birtWork\\birt.pdf.gz");
			FileOutputStream fileOutputStream = new FileOutputStream(file);
			gzipOutputStream = new GZIPOutputStream(fileOutputStream);
			options.setOutputStream(gzipOutputStream);
			task.setRenderOption(options);
			task.run();
		} finally {
			// Destroy the report engine.
			gzipOutputStream.close();
			engine.destroy();
			Platform.shutdown();
		}
	}
}



parameters.xml:

<?xml version="1.0" encoding="UTF-8"?>
<parameters>
	<data>This is an important report.</data>
</parameters>


simple.rptdesign:

<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.22" id="1">
    <property name="createdBy">Eclipse BIRT Designer Version 2.6.1.v20100902 Build &lt;2.6.1.v20100915-1750></property>
    <property name="units">in</property>
    <property name="iconFile">/templates/blank_report.gif</property>
    <property name="bidiLayoutOrientation">ltr</property>
    <property name="imageDPI">96</property>
    <data-sources>
        <oda-data-source extensionID="org.eclipse.datatools.enablement.oda.xml" name="Data Source" id="7">
            <property name="FILELIST">C:\birtWorkspace\BirtEsittely\reports\parameters.xml</property>
        </oda-data-source>
    </data-sources>
    <data-sets>
        <oda-data-set extensionID="org.eclipse.datatools.enablement.oda.xml.dataSet" name="Data Set" id="8">
            <list-property name="columnHints">
                <structure>
                    <property name="columnName">data</property>
                    <text-property name="heading">data</text-property>
                </structure>
            </list-property>
            <structure name="cachedMetaData">
                <list-property name="resultSet">
                    <structure>
                        <property name="position">1</property>
                        <property name="name">data</property>
                        <property name="dataType">string</property>
                    </structure>
                </list-property>
            </structure>
            <property name="dataSource">Data Source</property>
            <list-property name="resultSet">
                <structure>
                    <property name="position">1</property>
                    <property name="name">data</property>
                    <property name="nativeName">data</property>
                    <property name="dataType">string</property>
                    <property name="nativeDataType">12</property>
                </structure>
            </list-property>
            <xml-property name="queryText"><![CDATA[table0#-TNAME-#table0#:#[/parameters]#:#{data;STRING;/data}]]></xml-property>
            <xml-property name="designerValues"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<model:DesignValues xmlns:design="http://www.eclipse.org/datatools/connectivity/oda/design" xmlns:model="http://www.eclipse.org/birt/report/model/adapter/odaModel">
  <Version>1.0</Version>
  <design:ResultSets derivedMetaData="true">
    <design:resultSetDefinitions>
      <design:resultSetColumns>
        <design:resultColumnDefinitions>
          <design:attributes>
            <design:name>data</design:name>
            <design:position>1</design:position>
            <design:nativeDataTypeCode>12</design:nativeDataTypeCode>
            <design:precision>-1</design:precision>
            <design:scale>-1</design:scale>
            <design:nullability>Unknown</design:nullability>
          </design:attributes>
          <design:usageHints>
            <design:label>data</design:label>
            <design:formattingHints/>
          </design:usageHints>
        </design:resultColumnDefinitions>
      </design:resultSetColumns>
      <design:criteria/>
    </design:resultSetDefinitions>
  </design:ResultSets>
</model:DesignValues>
]]></xml-property>
            <list-property name="privateDriverProperties">
                <ex-property>
                    <name>MAX_ROW</name>
                    <value>-1</value>
                </ex-property>
                <ex-property>
                    <name>XML_FILE</name>
                </ex-property>
            </list-property>
        </oda-data-set>
    </data-sets>
    <styles>
        <style name="report" id="4">
            <property name="fontFamily">sans-serif</property>
            <property name="fontSize">10pt</property>
        </style>
        <style name="crosstab" id="5">
            <property name="borderBottomColor">#CCCCCC</property>
            <property name="borderBottomStyle">solid</property>
            <property name="borderBottomWidth">1pt</property>
            <property name="borderLeftColor">#CCCCCC</property>
            <property name="borderLeftStyle">solid</property>
            <property name="borderLeftWidth">1pt</property>
            <property name="borderRightColor">#CCCCCC</property>
            <property name="borderRightStyle">solid</property>
            <property name="borderRightWidth">1pt</property>
            <property name="borderTopColor">#CCCCCC</property>
            <property name="borderTopStyle">solid</property>
            <property name="borderTopWidth">1pt</property>
        </style>
        <style name="crosstab-cell" id="6">
            <property name="borderBottomColor">#CCCCCC</property>
            <property name="borderBottomStyle">solid</property>
            <property name="borderBottomWidth">1pt</property>
            <property name="borderLeftColor">#CCCCCC</property>
            <property name="borderLeftStyle">solid</property>
            <property name="borderLeftWidth">1pt</property>
            <property name="borderRightColor">#CCCCCC</property>
            <property name="borderRightStyle">solid</property>
            <property name="borderRightWidth">1pt</property>
            <property name="borderTopColor">#CCCCCC</property>
            <property name="borderTopStyle">solid</property>
            <property name="borderTopWidth">1pt</property>
        </style>
    </styles>
    <page-setup>
        <simple-master-page name="Simple MasterPage" id="2">
        	<!--
            <property name="backgroundImage">reports/draft.jpg</property>
            -->
            <page-footer>
                <text id="3">
                    <property name="contentType">html</property>
                    <text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
                </text>
            </page-footer>
        </simple-master-page>
    </page-setup>
    <body>
        <data id="9">
            <property name="whiteSpace">nowrap</property>
            <property name="dataSet">Data Set</property>
            <list-property name="boundDataColumns">
                <structure>
                    <property name="name">data</property>
                    <text-property name="displayName">data</text-property>
                    <expression name="expression" type="javascript">dataSetRow["data"]</expression>
                    <property name="dataType">string</property>
                </structure>
            </list-property>
            <property name="resultSetColumn">data</property>
        </data>
    </body>
</report>

Re: BIRT & gzip problem? [message #646554 is a reply to message #646337] Mon, 27 December 2010 11:06 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Mika,

As a test can you use birt to write out the pdf and then open it with
your java program and try to gzip it and save to another file and then
try to open it with adobe?

Jason

On 12/23/2010 7:03 AM, Mika wrote:
> Hello,
>
> I continue my old discussion
>
> http://www.eclipse.org/forums/index.php?t=msg&th=200471& amp;start=0&S=ae0a82523ba358e5ca8bd169eb4ad907
>
>
> As Jason wrote the BIRT uses allways the iText setFullCompression
> method. I found out that for my big test material the winzip compress
> the BIRT pdf to the 5% size.
>
> So I tried to use the GZIPOutputStream for my servlet. My servlet
> processed the gzip file, but I couldn't open the unzipped file with the
> Adobe reader.
> So I wrote the simple java program, which runs simple BIRT report with
> the simple data. I run the program and used gunzip. I got the error
> message "There was an error opening this document. Access denied" when I
> tried to open the file with the Adobe reader. This error message sound
> like I don't have rights to open the file, but file is only read-only.
>
> It is possible that this problem is not related on the BIRT, but is
> there some problem with my Java program?
>
> Thanks,
>
> Mika
>
> GzipRunReport.java:
>
>
> import java.io.File;
> import java.io.FileOutputStream;
> import java.util.zip.GZIPOutputStream;
>
> import org.eclipse.birt.core.framework.Platform;
> import org.eclipse.birt.report.engine.api.EngineConfig;
> import org.eclipse.birt.report.engine.api.HTMLRenderOption;
> import org.eclipse.birt.report.engine.api.IReportRunnable;
> import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
> import org.eclipse.birt.report.engine.api.ReportEngine;
>
> public class GzipRunReport {
> public static void main(String[] args) throws Exception {
> GZIPOutputStream gzipOutputStream = null;
> ReportEngine engine = null;
> try {
> String templateFilename =
> "C:\\birtWorkspace\\BirtEsittely\\reports\\simple.rptdesign";
> //String templateFilename = "C:\\testiRapo.rptdesign";
> EngineConfig config = new EngineConfig();
> config
> .setEngineHome("C:\\birt-runtime-2_6_1\\ReportEngine");
> // Create the report engine.
> engine = new ReportEngine(config);
> IReportRunnable report = null;
> // Create the report
> report = engine.openReportDesign(templateFilename);
> // Create the task
> IRunAndRenderTask task = engine.createRunAndRenderTask(report);
> // Set the options
> HTMLRenderOption options = new HTMLRenderOption();
> options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);
> File file = new File("c:\\birtWork\\birt.pdf.gz");
> FileOutputStream fileOutputStream = new FileOutputStream(file);
> gzipOutputStream = new GZIPOutputStream(fileOutputStream);
> options.setOutputStream(gzipOutputStream);
> task.setRenderOption(options);
> task.run();
> } finally {
> // Destroy the report engine.
> gzipOutputStream.close();
> engine.destroy();
> Platform.shutdown();
> }
> }
> }
>
>
>
> parameters.xml:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <parameters>
> <data>This is an important report.</data>
> </parameters>
>
>
> simple.rptdesign:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.22"
> id="1">
> <property name="createdBy">Eclipse BIRT Designer Version 2.6.1.v20100902
> Build <2.6.1.v20100915-1750></property>
> <property name="units">in</property>
> <property name="iconFile">/templates/blank_report.gif</property>
> <property name="bidiLayoutOrientation">ltr</property>
> <property name="imageDPI">96</property>
> <data-sources>
> <oda-data-source extensionID="org.eclipse.datatools.enablement.oda.xml"
> name="Data Source" id="7">
> <property
> name="FILELIST">C:\birtWorkspace\BirtEsittely\reports\parameters.xml </property>
>
> </oda-data-source>
> </data-sources>
> <data-sets>
> <oda-data-set
> extensionID="org.eclipse.datatools.enablement.oda.xml.dataSet "
> name="Data Set" id="8">
> <list-property name="columnHints">
> <structure>
> <property name="columnName">data</property>
> <text-property name="heading">data</text-property>
> </structure>
> </list-property>
> <structure name="cachedMetaData">
> <list-property name="resultSet">
> <structure>
> <property name="position">1</property>
> <property name="name">data</property>
> <property name="dataType">string</property>
> </structure>
> </list-property>
> </structure>
> <property name="dataSource">Data Source</property>
> <list-property name="resultSet">
> <structure>
> <property name="position">1</property>
> <property name="name">data</property>
> <property name="nativeName">data</property>
> <property name="dataType">string</property>
> <property name="nativeDataType">12</property>
> </structure>
> </list-property>
> <xml-property
> name="queryText">< ![CDATA[table0#-TNAME-#table0#:#[/parameters]#:#{data;STRING ;/data}]] ></xml-property>
>
> <xml-property name="designerValues"><![CDATA[<?xml version="1.0"
> encoding="UTF-8"?>
> <model:DesignValues
> xmlns:design="http://www.eclipse.org/datatools/connectivity/oda/design"
> xmlns:model="http://www.eclipse.org/birt/report/model/adapter/odaModel">
> <Version>1.0</Version>
> <design:ResultSets derivedMetaData="true">
> <design:resultSetDefinitions>
> <design:resultSetColumns>
> <design:resultColumnDefinitions>
> <design:attributes>
> <design:name>data</design:name>
> <design:position>1</design:position>
> <design:nativeDataTypeCode>12</design:nativeDataTypeCode>
> <design:precision>-1</design:precision>
> <design:scale>-1</design:scale>
> <design:nullability>Unknown</design:nullability>
> </design:attributes>
> <design:usageHints>
> <design:label>data</design:label>
> <design:formattingHints/>
> </design:usageHints>
> </design:resultColumnDefinitions>
> </design:resultSetColumns>
> <design:criteria/>
> </design:resultSetDefinitions>
> </design:ResultSets>
> </model:DesignValues>
> ]]></xml-property>
> <list-property name="privateDriverProperties">
> <ex-property>
> <name>MAX_ROW</name>
> <value>-1</value>
> </ex-property>
> <ex-property>
> <name>XML_FILE</name>
> </ex-property>
> </list-property>
> </oda-data-set>
> </data-sets>
> <styles>
> <style name="report" id="4">
> <property name="fontFamily">sans-serif</property>
> <property name="fontSize">10pt</property>
> </style>
> <style name="crosstab" id="5">
> <property name="borderBottomColor">#CCCCCC</property>
> <property name="borderBottomStyle">solid</property>
> <property name="borderBottomWidth">1pt</property>
> <property name="borderLeftColor">#CCCCCC</property>
> <property name="borderLeftStyle">solid</property>
> <property name="borderLeftWidth">1pt</property>
> <property name="borderRightColor">#CCCCCC</property>
> <property name="borderRightStyle">solid</property>
> <property name="borderRightWidth">1pt</property>
> <property name="borderTopColor">#CCCCCC</property>
> <property name="borderTopStyle">solid</property>
> <property name="borderTopWidth">1pt</property>
> </style>
> <style name="crosstab-cell" id="6">
> <property name="borderBottomColor">#CCCCCC</property>
> <property name="borderBottomStyle">solid</property>
> <property name="borderBottomWidth">1pt</property>
> <property name="borderLeftColor">#CCCCCC</property>
> <property name="borderLeftStyle">solid</property>
> <property name="borderLeftWidth">1pt</property>
> <property name="borderRightColor">#CCCCCC</property>
> <property name="borderRightStyle">solid</property>
> <property name="borderRightWidth">1pt</property>
> <property name="borderTopColor">#CCCCCC</property>
> <property name="borderTopStyle">solid</property>
> <property name="borderTopWidth">1pt</property>
> </style>
> </styles>
> <page-setup>
> <simple-master-page name="Simple MasterPage" id="2">
> <!--
> <property name="backgroundImage">reports/draft.jpg</property>
> -->
> <page-footer>
> <text id="3">
> <property name="contentType">html</property>
> <text-property name="content"><![CDATA[<value-of>new
> Date()</value-of>]]></text-property>
> </text>
> </page-footer>
> </simple-master-page>
> </page-setup>
> <body>
> <data id="9">
> <property name="whiteSpace">nowrap</property>
> <property name="dataSet">Data Set</property>
> <list-property name="boundDataColumns">
> <structure>
> <property name="name">data</property>
> <text-property name="displayName">data</text-property>
> <expression name="expression"
> type="javascript">dataSetRow["data"]</expression>
> <property name="dataType">string</property>
> </structure>
> </list-property>
> <property name="resultSetColumn">data</property>
> </data>
> </body>
> </report>
>
>
Re: BIRT & gzip problem? [message #646628 is a reply to message #646554] Wed, 29 December 2010 07:29 Go to previous messageGo to next message
Missing name Missing name is currently offline Missing name Missing name
Messages: 55
Registered: July 2010
Member
Hello,

Above GzipRunReport.java is working fine. I used the winzip and result is ok. There was some problem with the gunzip.

But my custom BIRT servlet is not working with the gzip. I can't post the actual customer code to the forum.

The servlet passes the gzip stream like this to the BIRT:

options.setOutputStream(new GZIPOutputStream(httpServletResponse.getOutputStream()));


When I run the servlet there are not exceptions and special log messages. Only the white page opens to the browser. When I save with JUnit test the server response to the disk and try to extract the pdf from the gzip file I got the "Invalid Compressed Data -- unable to inflate." error message.

Do you see any reason why the servlet is not working?

I have another test servlet, which reads the pdf file from the disk and then returns the gzipped response. That is working fine.

BR,

Mika

[Updated on: Wed, 29 December 2010 07:49]

Report message to a moderator

Re: BIRT & gzip problem? [message #646636 is a reply to message #646628] Wed, 29 December 2010 08:41 Go to previous messageGo to next message
Missing name Missing name is currently offline Missing name Missing name
Messages: 55
Registered: July 2010
Member
Hello,

The problem solved!! I have to close the GZIPOutputStream. Normally I don't have to close the httpServletResponse.getOutputStream(), because the servlet container etc. creates and closes it.

BR,

Mika
Re: BIRT & gzip problem? [message #646649 is a reply to message #646636] Wed, 29 December 2010 10:53 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Mika,

Very cool. I wish you would write this up and put it on birt exchange
dev share.

Jason

On 12/29/2010 8:41 AM, Mika wrote:
> Hello,
>
> The problem solved!! I have to close the GZIPOutputStream. Normally I
> don't have to close the httpServletResponse.getOutputStream(), because
> the servlet container etc. creates and closes it.
>
> BR,
>
> Mika
Re: BIRT & gzip problem? [message #647027 is a reply to message #646649] Tue, 04 January 2011 01:57 Go to previous messageGo to next message
Missing name Missing name is currently offline Missing name Missing name
Messages: 55
Registered: July 2010
Member
Jason,

It is possible that I write later this to the birt exchange
dev share. Currently I'm too busy with project...

BR,

Mika
Re: BIRT & gzip problem? [message #647100 is a reply to message #647027] Tue, 04 January 2011 10:33 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Mika,

Sure. If you get time in the future this would be cool.

Jason

On 1/4/2011 1:57 AM, Mika wrote:
> Jason,
>
> It is possible that I write later this to the birt exchange dev share.
> Currently I'm too busy with project...
>
> BR,
>
> Mika
Previous Topic:Report parameter mapping to jdbc data set IN query paramete
Next Topic:Dynamic data sources for report generation
Goto Forum:
  


Current Time: Tue Jul 22 05:31:22 EDT 2014

Powered by FUDForum. Page generated in 0.02850 seconds