You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by xsltuser <ch...@yahoo.com> on 2008/08/07 08:05:40 UTC

Abrubt server shutdown during XSLT transformation using FOP 0.94

Hi All,

One of our applications is using FOP processing mechanism to transform xml
files to pdf format by applying XSLT templates. The issue here is (which has
become a show stopper now) is that at times the transformation process kills
the server on which it is running. This happens randomly for different
servers. There is no specific scenario in which it can be replicated. As
evident from server logs, it fails at the following line 
transformer.transform(src, res);

Please find below the code snippet. Any suggestions to fix the issue are
greatly appreciated. 

/// import statements


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStream;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

// Code snippet follows:


                        XmlDocument receiptDataXML = new XmlDocument();
			JavaXMLBinding.java2XML(receiptDataPOJO, receiptDataXML);

			File xsltfile=new File(xsltPath + "testxsl.xsl");
			 
                        File pdffile = new File(xmlPath + "testpdf.pdf");

			// Setup output

			OutputStream out = new java.io.FileOutputStream(pdffile);
			out = new java.io.BufferedOutputStream(out);

			FopFactory fopFactory = FopFactory.newInstance();
			fopFactory.setUserConfig(configfile);
                        FOUserAgent foUserAgent =
fopFactory.newFOUserAgent();

			// Construct fop with output format as PDF
			Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,foUserAgent, out);

			TransformerFactory factory = TransformerFactory.newInstance();
			Transformer transformer = factory.newTransformer(new
StreamSource(xsltfile));
			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
				
			java.io.StringWriter wr=new java.io.StringWriter();
			receiptDataXML.write(wr);
			ByteArrayInputStream xmlInputStream = new      
ByteArrayInputStream(wr.toString().getBytes ());
			Source src = new StreamSource(xmlInputStream);
								
			// Resulting SAX events (the generated FO) must be piped through to FOP
			Result res = new SAXResult(fop.getDefaultHandler());

			// Start XSLT transformation and FOP processing
			transformer.transform(src, res);







-- 
View this message in context: http://www.nabble.com/Abrubt-server-shutdown-during-XSLT-transformation-using-FOP-0.94-tp18864628p18864628.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Abrubt server shutdown during XSLT transformation using FOP 0.94

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 07.08.2008 10:32:06 xsltuser wrote:
> 
> 
> The code snippet I have posted is demonstrating the flow for one processing
> run. I have deliberately kept all the business logic out of way to ease
> understanding. We are also maintaining single instances of  FOPFactory and
> TransformerFactory in the actual class. 
> 
> Regarding XML, I can replace the existing code as follows where java2XML is
> using Castor APIs for marshelling. Please advise.
> 
>                         FileOutputStream fileOut = new
> FileOutputStream(xmlFile);
> 			XmlDocument receiptDataXML = new XmlDocument();
> 			JavaXMLBinding.java2XML(receiptData, receiptDataXML);
> 			receiptDataXML.write(fileOut);
>                         Source src = new StreamSource(xmlFile);

That's even worse. That way you write it to a file. A hard drive is much
slower than memory.

I haven't found any reference to "XmlDocument" and "JavaXMLBinding" on
the net. So I don't have a chance to suggest better approaches.

For ideas how to do this efficiently, please look
into our tutorial at:
http://xmlgraphics.apache.org/fop/0.95/embedding.html#examples

But to tell you how to connect Castor in this connect I need access to
its Javadocs. But the Javadocs I found on Castor didn't contain the
classes "JavaXMLBinding" or "XmlDocument". Maybe these are your own
helper classes. At any rate, Castor's Mashaller class supports
generating SAX event to a SAX ContentHandler.
See: http://www.castor.org/api/org/exolab/castor/xml/Marshaller.html
This would avoid the serialization and subsequent parsing of the XML.

> We are also doing Exception Handling but no exceptions are thrown in this
> scenario. Server shuts down at transformer.transform(src, res);. Last line
> displayed in log is 'WARN  (FONode) - Warning(Unknown location): fo:table,
> table-layout="auto" is currently not supported by FOP'
> 
> >                       Source src = new StreamSource(xmlInputStream);
> >                       logger.info("After setting source");
> > 								
> > 			// Resulting SAX events (the generated FO) must be piped through to FOP
> > 			Result res = new SAXResult(fop.getDefaultHandler());
> >                       logger.info("After setting result");
> > 
> > 			// Start XSLT transformation and FOP processing
> > 			transformer.transform(src, res);
> 
> INFO  (ReceiptTransformer) - After setting source
> INFO  (ReceiptTransformer) - After setting result
> WARN  (FONode) - Warning(Unknown location): fo:table, table-layout="auto" is
> currently not supported by FOP

Doesn't help, I'm afraid. A server or a JVM doesn't just shutdown
silently in mid-process. There must be an error message somewhere in a
log file (maybe a different one from what you're looking at. Or the
operating system logs the crash of an application somewhere. You might
also have caught Exception or Throwable somewhere in your code and
swallowed the error message.


<snip/> 


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Abrubt server shutdown during XSLT transformation using FOP 0.94

Posted by xsltuser <ch...@yahoo.com>.

The code snippet I have posted is demonstrating the flow for one processing
run. I have deliberately kept all the business logic out of way to ease
understanding. We are also maintaining single instances of  FOPFactory and
TransformerFactory in the actual class. 

Regarding XML, I can replace the existing code as follows where java2XML is
using Castor APIs for marshelling. Please advise.

                        FileOutputStream fileOut = new
FileOutputStream(xmlFile);
			XmlDocument receiptDataXML = new XmlDocument();
			JavaXMLBinding.java2XML(receiptData, receiptDataXML);
			receiptDataXML.write(fileOut);
                        Source src = new StreamSource(xmlFile);

We are also doing Exception Handling but no exceptions are thrown in this
scenario. Server shuts down at transformer.transform(src, res);. Last line
displayed in log is 'WARN  (FONode) - Warning(Unknown location): fo:table,
table-layout="auto" is currently not supported by FOP'

>                       Source src = new StreamSource(xmlInputStream);
>                       logger.info("After setting source");
> 								
> 			// Resulting SAX events (the generated FO) must be piped through to FOP
> 			Result res = new SAXResult(fop.getDefaultHandler());
>                       logger.info("After setting result");
> 
> 			// Start XSLT transformation and FOP processing
> 			transformer.transform(src, res);

INFO  (ReceiptTransformer) - After setting source
INFO  (ReceiptTransformer) - After setting result
WARN  (FONode) - Warning(Unknown location): fo:table, table-layout="auto" is
currently not supported by FOP






Jeremias Maerki-2 wrote:
> 
> Very little to work with here. If you have a code line I'm sure you also
> have an exception and a stack trace. Can we see that please? If it's a
> JVM crash there's not much we can help you with but you don't say if
> it's that, either.
> 
> The code snippet is out of context which doesn't help either. Anyway,
> looking at the code I see two things that I don't like (but that doesn't
> mean it has something to do with your problem:
> 1. That the XML generated from the POJO has to be written to a temporary
> String is very inefficient. I don't know what you're using there but
> there has to be a better way (i.e. to connect via SAX).
> 2. The FopFactory and the TransformerFactory are instantiated for every
> processing run. That way you can't profit from caching images and other
> stuff and the stylesheet has to be reparsed every time. That slows your
> application down if nothing else. If this code is running concurrently
> you might easily get into an OutOfMemoryError if larger images are used
> because they can't be shared and take up space for each processing run
> rather than once. Sharing the FopFactory doesn't get that out of the
> world but can improve the situation.
> 
> On 07.08.2008 08:05:40 xsltuser wrote:
>> 
>> Hi All,
>> 
>> One of our applications is using FOP processing mechanism to transform
>> xml
>> files to pdf format by applying XSLT templates. The issue here is (which
>> has
>> become a show stopper now) is that at times the transformation process
>> kills
>> the server on which it is running. This happens randomly for different
>> servers. There is no specific scenario in which it can be replicated. As
>> evident from server logs, it fails at the following line 
>> transformer.transform(src, res);
>> 
>> Please find below the code snippet. Any suggestions to fix the issue are
>> greatly appreciated. 
>> 
>> /// import statements
>> 
>> 
>> import java.io.File;
>> import java.io.FileInputStream;
>> import java.io.FileOutputStream;
>> import java.io.FileWriter;
>> import java.io.OutputStream;
>> 
>> import javax.xml.transform.OutputKeys;
>> import javax.xml.transform.Result;
>> import javax.xml.transform.Source;
>> import javax.xml.transform.Transformer;
>> import javax.xml.transform.TransformerFactory;
>> import javax.xml.transform.sax.SAXResult;
>> import javax.xml.transform.stream.StreamResult;
>> import javax.xml.transform.stream.StreamSource;
>> 
>> // Code snippet follows:
>> 
>> 
>>                         XmlDocument receiptDataXML = new XmlDocument();
>> 			JavaXMLBinding.java2XML(receiptDataPOJO, receiptDataXML);
>> 
>> 			File xsltfile=new File(xsltPath + "testxsl.xsl");
>> 			 
>>                         File pdffile = new File(xmlPath + "testpdf.pdf");
>> 
>> 			// Setup output
>> 
>> 			OutputStream out = new java.io.FileOutputStream(pdffile);
>> 			out = new java.io.BufferedOutputStream(out);
>> 
>> 			FopFactory fopFactory = FopFactory.newInstance();
>> 			fopFactory.setUserConfig(configfile);
>>                         FOUserAgent foUserAgent =
>> fopFactory.newFOUserAgent();
>> 
>> 			// Construct fop with output format as PDF
>> 			Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,foUserAgent, out);
>> 
>> 			TransformerFactory factory = TransformerFactory.newInstance();
>> 			Transformer transformer = factory.newTransformer(new
>> StreamSource(xsltfile));
>> 			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
>> 				
>> 			java.io.StringWriter wr=new java.io.StringWriter();
>> 			receiptDataXML.write(wr);
>> 			ByteArrayInputStream xmlInputStream = new      
>> ByteArrayInputStream(wr.toString().getBytes ());
>> 			Source src = new StreamSource(xmlInputStream);
>> 								
>> 			// Resulting SAX events (the generated FO) must be piped through to
>> FOP
>> 			Result res = new SAXResult(fop.getDefaultHandler());
>> 
>> 			// Start XSLT transformation and FOP processing
>> 			transformer.transform(src, res);
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/Abrubt-server-shutdown-during-XSLT-transformation-using-FOP-0.94-tp18864628p18864628.html
>> Sent from the FOP - Users mailing list archive at Nabble.com.
>> 
>> 
> 
> 
> 
> Jeremias Maerki
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Abrubt-server-shutdown-during-XSLT-transformation-using-FOP-0.94-tp18864628p18866170.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Abrubt server shutdown during XSLT transformation using FOP 0.94

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Very little to work with here. If you have a code line I'm sure you also
have an exception and a stack trace. Can we see that please? If it's a
JVM crash there's not much we can help you with but you don't say if
it's that, either.

The code snippet is out of context which doesn't help either. Anyway,
looking at the code I see two things that I don't like (but that doesn't
mean it has something to do with your problem:
1. That the XML generated from the POJO has to be written to a temporary
String is very inefficient. I don't know what you're using there but
there has to be a better way (i.e. to connect via SAX).
2. The FopFactory and the TransformerFactory are instantiated for every
processing run. That way you can't profit from caching images and other
stuff and the stylesheet has to be reparsed every time. That slows your
application down if nothing else. If this code is running concurrently
you might easily get into an OutOfMemoryError if larger images are used
because they can't be shared and take up space for each processing run
rather than once. Sharing the FopFactory doesn't get that out of the
world but can improve the situation.

On 07.08.2008 08:05:40 xsltuser wrote:
> 
> Hi All,
> 
> One of our applications is using FOP processing mechanism to transform xml
> files to pdf format by applying XSLT templates. The issue here is (which has
> become a show stopper now) is that at times the transformation process kills
> the server on which it is running. This happens randomly for different
> servers. There is no specific scenario in which it can be replicated. As
> evident from server logs, it fails at the following line 
> transformer.transform(src, res);
> 
> Please find below the code snippet. Any suggestions to fix the issue are
> greatly appreciated. 
> 
> /// import statements
> 
> 
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.FileOutputStream;
> import java.io.FileWriter;
> import java.io.OutputStream;
> 
> import javax.xml.transform.OutputKeys;
> import javax.xml.transform.Result;
> import javax.xml.transform.Source;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.sax.SAXResult;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
> 
> // Code snippet follows:
> 
> 
>                         XmlDocument receiptDataXML = new XmlDocument();
> 			JavaXMLBinding.java2XML(receiptDataPOJO, receiptDataXML);
> 
> 			File xsltfile=new File(xsltPath + "testxsl.xsl");
> 			 
>                         File pdffile = new File(xmlPath + "testpdf.pdf");
> 
> 			// Setup output
> 
> 			OutputStream out = new java.io.FileOutputStream(pdffile);
> 			out = new java.io.BufferedOutputStream(out);
> 
> 			FopFactory fopFactory = FopFactory.newInstance();
> 			fopFactory.setUserConfig(configfile);
>                         FOUserAgent foUserAgent =
> fopFactory.newFOUserAgent();
> 
> 			// Construct fop with output format as PDF
> 			Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,foUserAgent, out);
> 
> 			TransformerFactory factory = TransformerFactory.newInstance();
> 			Transformer transformer = factory.newTransformer(new
> StreamSource(xsltfile));
> 			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
> 				
> 			java.io.StringWriter wr=new java.io.StringWriter();
> 			receiptDataXML.write(wr);
> 			ByteArrayInputStream xmlInputStream = new      
> ByteArrayInputStream(wr.toString().getBytes ());
> 			Source src = new StreamSource(xmlInputStream);
> 								
> 			// Resulting SAX events (the generated FO) must be piped through to FOP
> 			Result res = new SAXResult(fop.getDefaultHandler());
> 
> 			// Start XSLT transformation and FOP processing
> 			transformer.transform(src, res);
> 
> 
> 
> 
> 
> 
> 
> -- 
> View this message in context: http://www.nabble.com/Abrubt-server-shutdown-during-XSLT-transformation-using-FOP-0.94-tp18864628p18864628.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
> 
> 



Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org