karurkarthi / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

XDocReportException: java.lang.OutOfMemoryError: Java heap space #320

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Call attached servlet from front end using any html button

What is the expected output? What do you see instead?

Document without any java heap error

What version of the product are you using? On what operating system?

fr.opensagres.xdocreport.document.docx-1.0.3.jar

Please provide any additional information below.

After downloading more than five documents it is generating java heap space 
error as follows :

fr.opensagres.xdocreport.core.XDocReportException: java.lang.OutOfMemoryError: 
Java heap space
    at fr.opensagres.xdocreport.document.preprocessor.AbstractXDocPreprocessor.preprocess(AbstractXDocPreprocessor.java:118)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.doPreprocessorIfNeeded(AbstractXDocReport.java:363)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.process(AbstractXDocReport.java:509)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.process(AbstractXDocReport.java:484)

Original issue reported on code.google.com by krishnar...@gmail.com on 7 Nov 2013 at 6:53

Attachments:

GoogleCodeExporter commented 9 years ago
I cannot help you more with your info (I have not your docx, and your Java 
context (Code39 is your custom class), so I cannot execute your classes (more 
it's not a Java main). 

As you use 1.0.3, please read 
https://code.google.com/p/xdocreport/wiki/XDocReportDumper to attach in this 
issue an Eclipse Dumper.

Perhaps your Test.docx is very big?

Original comment by angelo.z...@gmail.com on 7 Nov 2013 at 8:23

GoogleCodeExporter commented 9 years ago
Thanks for the reply..
My context is to get template (docx) from db as binary stream  and pass to 
xdocreport.later insert content in that document using velocity frame work and 
generate out put as word docx to end user while he click on some docdownload 
button in my jsp.this is working fine for at most 10 sequence downloads ,then i 
am getting java heap space error in console and getting empty docs or some time 
its getting struck. My template docx size is 1.5 MB and generating docx size 
changing to more than 2 MB . I tried to understand your XDocReportDumpe but 
failed ,i am adding my sample templates ,java main program for this post

Original comment by krishnar...@gmail.com on 7 Nov 2013 at 9:34

GoogleCodeExporter commented 9 years ago
Attachment files

Original comment by krishnar...@gmail.com on 7 Nov 2013 at 9:38

Attachments:

GoogleCodeExporter commented 9 years ago
When I see your Java code and your docx, it seems that you have not taking time 
to read our wiki. So please read our wiki!

1) It seems that you load every time the docx in the report, you must load one 
time the report and after search it in the registry. You can read that at 
https://code.google.com/p/xdocreport/wiki/DocxReportingJavaMain#5._Test_Performa
nce

2) it seems that you don't use the XDocReport servlet although XDocReport 
provides a support for web 
https://code.google.com/p/xdocreport/wiki/DocxReportingWEBApplication  If you 
cannot use our web support, could you explain us, please.

3) your docx doesn't use MERGEFIELD, you will have trouble. please read 
https://code.google.com/p/xdocreport/wiki/DocxReportingQuickStart 

4) I tried to understand your XDocReportDumpe but failed, could you give us 
more info? If you use our web support, you will benefit about dumper.

So please take time to read our wiki.

Original comment by angelo.z...@gmail.com on 7 Nov 2013 at 9:49

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I need dynamic report id like when I select drop down list, it will export 

different reports based upon different report ids. 
 public static final String REPORT_ID = "Anemia"; //I want to  change this 

report id when i select different option from select box of my jsp page
i attach my file 
Thanks,,    

Original comment by krishnar...@gmail.com on 8 Nov 2013 at 12:42

Attachments:

GoogleCodeExporter commented 9 years ago
AbstractProcessXDocReportServlet cannot help you? See at 
https://code.google.com/p/xdocreport/wiki/DocxReportingWEBApplicationServlet

Original comment by angelo.z...@gmail.com on 8 Nov 2013 at 1:12

GoogleCodeExporter commented 9 years ago
The following code is ok for 1 to 2 documents but we have around 50 documents 
then shall i have to write if and else for all docs or is there any alternative 
way to further proceed...
// in getSourceStream method of MyReportServlet class
if (REPORT_ID.equals(reportId)) {
      return MyReportServlet.class.getResourceAsStream("DocxProjectWithVelocity.docx");
    }
    // else manage another report
    throw new XDocReportNotFoundException(reportId);
===============
// in populateContext method of MyReportServlet class
if (REPORT_ID.equals(reportId)) {
      String name = request.getParameter("name");
      Project project = new Project(name);
      context.put("project", project);
    }
    // else manage another report

Original comment by harish.m...@gmail.com on 9 Nov 2013 at 2:34

GoogleCodeExporter commented 9 years ago
I don't know what you wish to do exactly? I suppose you wish to manage several 
docx template report which have the Java same context. 

To do that I will use the reportId as input stream : 

---------------------------------------

 @Override
  protected InputStream getSourceStream(String reportId,
                HttpServletRequest request) throws IOException, XDocReportException {    
      return YourManagerWhichHostDocxTemplates.getStream(reportId);    
  }

  @Override
  protected void populateContext(IContext context, String reportId,
                        HttpServletRequest request) throws IOException, XDocReportException {
      String name = request.getParameter("name");
      Project project = new Project(name);
      context.put("project", project);
  }
---------------------------------------

where YourManagerWhichHostDocxTemplates returns the stream of the docx (from 
DB, from  file system).

I will create a servlet per java context kind.

Regards Angelo

Original comment by angelo.z...@gmail.com on 9 Nov 2013 at 10:33

GoogleCodeExporter commented 9 years ago
I am using WEB Application with Servlet in this process i created 
servlet,web.xml,jsp when i run my application i got below error,  in  
dispatcher we haave tempate enginekined like this but in servlet how to use 
tempate engine
 public DocxProjectWithVelocityController() {
    super(TemplateEngineKind.Velocity, DocumentKind.DOCX);}

my error msg is...
Null template engine. Set template engine with IXDocReport#setTemplateEngine.
fr.opensagres.xdocreport.core.XDocReportException: Null template engine. Set 
template engine with IXDocReport#setTemplateEngine.
    at fr.opensagres.xdocreport.document.AbstractXDocReport.internalGetTemplateEngine(AbstractXDocReport.java:866)

i attached my files... 

Original comment by vinay.mr...@gmail.com on 10 Nov 2013 at 7:50

Attachments:

GoogleCodeExporter commented 9 years ago
You must define AbstractProcessXDocReportServlet#getTemplateEngineKind

See sample at 
https://code.google.com/p/xdocreport/source/browse/demo-webapp/src/main/java/fr/
opensagres/xdocreport/webapp/HelloWorldReportServlet.java?repo=samples

Original comment by angelo.z...@gmail.com on 10 Nov 2013 at 11:02

GoogleCodeExporter commented 9 years ago
Hi, 
Thank you for giving reply..
By following your suggestions i got the output what i need. But i have a 
problem, i have 40 word documents for downloading all 40 downloading fine but 
some times the documents cannot open problem i found.
i attach the both output generated document and problem doc. i didn't 
understand why that was occurs.... anemia and anemia1 contains same data but 
redundant name so i give anemia1....    

Original comment by vinay.mr...@gmail.com on 11 Nov 2013 at 7:47

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
when i select options in the select box simultaneously that problem is occurred.
when that time  Servlet methods didn't called. May be that was the problem. 
please provide solution as soon as posible.... 
--------------------------------------------------------------------------------
---
when i remove image code in servlet it's working fine
but in my project that image is compulsory. i commented these two lines 
// metadata.addFieldAsImage("logo");
// metadata.addFieldAsImage("logo1");  
it's working....
but i need these images....  

Original comment by vinay.mr...@gmail.com on 11 Nov 2013 at 2:16

GoogleCodeExporter commented 9 years ago
As I already said you, I cannot help you with your attached Java code! I have 
not your Java context Code39, etc. So please provide a simple Java Main with 
your case (and attached library) (an Eclipse Project should be cool).

You have not answered to my question "what is your problem with dumper). Dumper 
could perhaps help you.

Original comment by angelo.z...@gmail.com on 11 Nov 2013 at 8:26

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is the jar file for code39...
MyReportServlet is a servlert class. my requirement is when i send a word 
document from input stream, in that word document replace with velocity values 
with my values and and  populate that generated output word document. so in 
that word document i need to generate dynamic barcode so to put that barcode 
image i follows your dynamic image replace 
https://code.google.com/p/xdocreport/wiki/DocxReportingJavaMainDynamicImage.
some times my code work fine.. some times the generated output file was 
corrupted..
when i remove  
 // metadata.addFieldAsImage("logo");
// metadata.addFieldAsImage("logo1");  
this code from my servlet its working fine... but i need these barcode images 
into my  word docunt... 

Original comment by vinay.mr...@gmail.com on 12 Nov 2013 at 4:15

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
i am using Netbeans IDE.. 
i was attached 2 files DocExport contains the project and Sample contains the 
word documents...
when i use this url http://localhost:8084/DocxExport/ jsp page is displaying in 
that fist i select Test1 and export next i select Text2 Export, again i select 
Test1 document is corrupted.... Why that issue is occurred.. and give the 
solution....

Original comment by vinay.mr...@gmail.com on 12 Nov 2013 at 7:32

Attachments:

GoogleCodeExporter commented 9 years ago
Your Anemia1.docx is not a docx. If you open it with notepad you will see stack 
trace :

--------------------------------------------------------------------------------
------
<html><title>Error</title><body bgcolor="#ffffff"><h2>XDocReport Servlet: Error 
report generation</h2><pre>Invocation of method 'registerImage' in  class 
fr.opensagres.xdocreport.document.docx.images.DocxImageRegistry threw exception 
fr.opensagres.xdocreport.core.XDocReportException: Image provider for field 
[logo] cannot be null! at Anemia!word/document.xml[line 1, column 
112673]<br>org.apache.velocity.exception.MethodInvocationException: Invocation 
of method 'registerImage' in  class 
fr.opensagres.xdocreport.document.docx.images.DocxImageRegistry threw exception 
fr.opensagres.xdocreport.core.XDocReportException: Image provider for field 
[logo] cannot be null! at Anemia!word/document.xml[line 1, column 112673]
    at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:243)
210)
...
Caused by: fr.opensagres.xdocreport.core.XDocReportException: Image provider 
for field [logo] cannot be null!
...
--------------------------------------------------------------------------------
-----

So your problem is that you have a logo null with InputStream. By default 
XDocReport throws error when the stream of the image is null. If you wantto 
change that, please read 
https://code.google.com/p/xdocreport/wiki/DocxReportingJavaMainDynamicImage#Opti
onal_Image

But XDocReport should improve this case when report is downloaded, it should 
throws an error and doesn't generate a docx. I don't know if it's possible.

Original comment by angelo.z...@gmail.com on 12 Nov 2013 at 8:40

GoogleCodeExporter commented 9 years ago
I understand what your said. Did you observer the DocxExport project that is 
attached in the previous post.. you said  problem is that i have a logo null 
with InputStream but that logo is also in the first time doc export also see 
the bellow attachment Test1 in that logo is not null, when i export Test3 it is 
also fine again i export Test1 problem is occurs logo will be null with 
inpustream(Test1 with error.docx).when i remove 
metadata.addFieldAsImage("logo"); document export fine but it does not replace 
the velocity syntax's in the source document..
I think in servlet   
"getSourceStream,getTemplateEngineKind,getFieldsMetadata,populateContext" These 
methods are not called Test1 export next Text3 exporting again Test1(Text1 
error.docx)exporting. 
5th attachment of Text1.docx is the original document....

Original comment by vinay.mr...@gmail.com on 12 Nov 2013 at 10:04

Attachments:

GoogleCodeExporter commented 9 years ago
I cannot help you more. I have no time to debug your application. More you 
don't answer to my question "what is your problem with dumper". And next time, 
please take time to read our wiki.

Original comment by angelo.z...@gmail.com on 12 Nov 2013 at 10:10

GoogleCodeExporter commented 9 years ago
Still we are getting java heap space: OutOfMemory exception after 10 docs while 
downloading word documents.I am unable to findout the mistake which i have done 
so please findout mistake and post it as reply asap and i attached my files for 
referring purpose and our credentials are windows server 2003 operating system 
with 64 bit jvm (jdk1.6.0_25).I think i have made mistake inside of 
getFieldsMetadata() method of my app

Original comment by harish.m...@gmail.com on 19 Nov 2013 at 6:07

Attachments:

GoogleCodeExporter commented 9 years ago
1) you don't answer to my question about dumper.
2) Your problem is perhaps about your image which is big? Have you tried with 
little image?

Original comment by angelo.z...@gmail.com on 19 Nov 2013 at 7:56

GoogleCodeExporter commented 9 years ago
Issue 329 has been merged into this issue.

Original comment by angelo.z...@gmail.com on 19 Nov 2013 at 8:01

GoogleCodeExporter commented 9 years ago
When I see your code, you write the Code39 code bare in a file and you read it 
with FileImageProvider. You will have problem when several users will generate 
report.

I suggest you to implement your own IImageProvider with streaming (and not with 
temp File) like this : 

-------------------------------------------------------------------
import java.io.IOException;
import java.io.OutputStream;

import com.onbarcode.barcode.AbstractBarcode;

import fr.opensagres.xdocreport.core.document.ImageFormat;
import fr.opensagres.xdocreport.document.images.AbstractImageProvider;
import fr.opensagres.xdocreport.document.images.SimpleImageInfo;

public class BarCodeImageProvider
    extends AbstractImageProvider
{

    private final AbstractBarcode barCode;

    public BarCodeImageProvider( AbstractBarcode barCode, boolean useImageSize )
    {
        super( useImageSize );
        this.barCode = barCode;
    }

    public void write( OutputStream outputStream )
        throws IOException
    {
        try
        {            
            barCode.drawBarcode( outputStream );
        }
        catch ( Exception e )
        {
            throw new IOException( e );
        }
    }

    public ImageFormat getImageFormat()
    {
        // perhaps it's better to use barCode.getImageFormat();?
        return ImageFormat.png;
    }

    @Override
    protected SimpleImageInfo loadImageInfo()
        throws IOException
    {
        // should be improved if resize is used.
        return null;
    }

    @Override
    protected boolean doIsValid()
    {
        return barCode != null;
    }

}
-------------------------------------------------------------------

And after you use it like this : 

-------------------------------------------------------------------
Code39 code = new Code39();
IImageProvider logo = new BarCodeImageProvider( code, true );
-------------------------------------------------------------------

I have not tested the code, but please tell me if it works. I think it's a good 
sample to show how to implement her own IImageProvider.

Original comment by angelo.z...@gmail.com on 19 Nov 2013 at 8:30

GoogleCodeExporter commented 9 years ago
Yes, it is working with out implementing our own IImageProvider
This is the code 
Code39 barcode = new Code39();
                    barcode.setData(accno);
                    barcode.setX(2);
                    barcode.setY(60);
                    barcode.setBarcodeWidth(150);
                    barcode.setBarcodeHeight(80);
                    barcode.setLeftMargin(0);
                    barcode.setRightMargin(0);
                   barcode.drawBarcode("C://Barcode.png");
                   IImageProvider logo = new FileImageProvider(new File("C://Barcode.png"));
                context.put("logo",logo);
               context.put("logo1",logo);

use barcode.jar file

Original comment by vinay.mr...@gmail.com on 28 Jan 2014 at 12:51

GoogleCodeExporter commented 9 years ago
By using Docx Reporting in WEB Application with Servle can we chang the output 
file name for eg:DocxProjectWithVelocity.docx  to abc.docx

Original comment by vinay.mr...@gmail.com on 28 Jan 2014 at 12:54

GoogleCodeExporter commented 9 years ago
I suggest you really to use BarCodeImageProvider as I have explained to avoid 
temp file like you have if you use FileImageProvider

>By using Docx Reporting in WEB Application with Servle can we chang the output 
file >name for eg:DocxProjectWithVelocity.docx  to abc.docx

Please don't post the same question. I have answered you at 
https://code.google.com/p/xdocreport/issues/detail?id=356#c13

Original comment by angelo.z...@gmail.com on 28 Jan 2014 at 1:43

GoogleCodeExporter commented 9 years ago

Original comment by angelo.z...@gmail.com on 18 Feb 2014 at 11:03