Re: FopServlet
Here's a modified version of the servlet: http://cvs.apache.org/~jeremias/FopServlet.java BTW, while updating the file I found an opportunity for a little optimization. In the servlet's case the ByteArrayOutputStream should not be instantiated with the default constructor. This only allocates 64 bytes initially. Every time the buffer runs out of space the old buffer is discarded and a new one with twice the previous space is allocated. If you do new ByteArrayOutputStream(16384) (or an even higher number depending on the documents you serve), you will get a slight performance improvement almost for free. :-) On 10.03.2005 13:02:22 Ben Gill wrote: Maybe the example can be updated with my version? I have not compiled this, but I know it works... Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: FopServlet
Are you not creating an XML file on disk with this version with: else if ((xmlParam != null) (xslParam != null)) { Source src = new StreamSource(new File(xmlParam)); I think it would be good to include an example of how to generate the PDF from a ProjectTeam without touching the disk? Ben -Original Message- From: Jeremias Maerki [mailto:[EMAIL PROTECTED] Sent: 11 March 2005 08:26 To: [EMAIL PROTECTED] Subject: Re: FopServlet Here's a modified version of the servlet: http://cvs.apache.org/~jeremias/FopServlet.java BTW, while updating the file I found an opportunity for a little optimization. In the servlet's case the ByteArrayOutputStream should not be instantiated with the default constructor. This only allocates 64 bytes initially. Every time the buffer runs out of space the old buffer is discarded and a new one with twice the previous space is allocated. If you do new ByteArrayOutputStream(16384) (or an even higher number depending on the documents you serve), you will get a slight performance improvement almost for free. :-) On 10.03.2005 13:02:22 Ben Gill wrote: Maybe the example can be updated with my version? I have not compiled this, but I know it works... Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] _ This message has been checked for all known viruses by the MessageLabs Virus Control Centre. This message has been checked for all known viruses by the MessageLabs Virus Control Centre. * Notice: This email is confidential and may contain copyright material of Ocado Limited (the Company). Opinions and views expressed in this message may not necessarily reflect the opinions and views of the Company. If you are not the intended recipient, please notify us immediately and delete all copies of this message. Please note that it is your responsibility to scan this message for viruses. Company reg. no. 3875000. Ocado Limited Titan Court 3 Bishops Square Hatfield Business Park Hatfield Herts AL10 9NE * - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FopServlet
The modified servlet has the same functionality as the example servlet in the distribution. You're welcome to do the example involving the ProjectTeam yourself. I don't have the time. On 11.03.2005 11:06:59 Ben Gill wrote: Are you not creating an XML file on disk with this version with: else if ((xmlParam != null) (xslParam != null)) { Source src = new StreamSource(new File(xmlParam)); I think it would be good to include an example of how to generate the PDF from a ProjectTeam without touching the disk? Ben -Original Message- From: Jeremias Maerki [mailto:[EMAIL PROTECTED] Sent: 11 March 2005 08:26 To: [EMAIL PROTECTED] Subject: Re: FopServlet Here's a modified version of the servlet: http://cvs.apache.org/~jeremias/FopServlet.java BTW, while updating the file I found an opportunity for a little optimization. In the servlet's case the ByteArrayOutputStream should not be instantiated with the default constructor. This only allocates 64 bytes initially. Every time the buffer runs out of space the old buffer is discarded and a new one with twice the previous space is allocated. If you do new ByteArrayOutputStream(16384) (or an even higher number depending on the documents you serve), you will get a slight performance improvement almost for free. :-) On 10.03.2005 13:02:22 Ben Gill wrote: Maybe the example can be updated with my version? I have not compiled this, but I know it works... Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] _ This message has been checked for all known viruses by the MessageLabs Virus Control Centre. This message has been checked for all known viruses by the MessageLabs Virus Control Centre. * Notice: This email is confidential and may contain copyright material of Ocado Limited (the Company). Opinions and views expressed in this message may not necessarily reflect the opinions and views of the Company. If you are not the intended recipient, please notify us immediately and delete all copies of this message. Please note that it is your responsibility to scan this message for viruses. Company reg. no. 3875000. Ocado Limited Titan Court 3 Bishops Square Hatfield Business Park Hatfield Herts AL10 9NE * - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: FopServlet
); Driver driver = new Driver(); driver.setLogger(log); driver.setRenderer(Driver.RENDER_PDF); driver.setOutputStream(out); //Setup XSLT if (factory == null) { factory = TransformerFactory.newInstance(); } Transformer transformer; if (xslt != null) { transformer = factory.newTransformer(xslt); } else { transformer = factory.newTransformer(); } //Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(driver.getContentHandler()); //Start XSLT transformation and FOP processing transformer.transform(src, res); byte[] content = out.toByteArray(); //log.debug(Created PDF: + content.length); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); } catch (Exception ex) { throw new ServletException(ex); } } } and the simplest way to sort the build.xml file is to add this to servlet/build.xml: property name=embedding.src.dir value=./../embedding/java/ !-- === -- !-- Compiles the source directory -- !-- === -- target name=compile depends=prepare echo message=Compiling the sources / javac srcdir=${embedding.src.dir} destdir=${build.dest} debug=${debug} deprecation=${deprecation} optimize=${optimize} classpath refid=project.class.path/ /javac javac srcdir=${src.dir} destdir=${build.dest} debug=${debug} deprecation=${deprecation} optimize=${optimize} classpath refid=project.class.path/ /javac /target Ben -Original Message- From: Jeremias Maerki [mailto:[EMAIL PROTECTED] Sent: 11 March 2005 10:10 To: [EMAIL PROTECTED] Subject: Re: FopServlet The modified servlet has the same functionality as the example servlet in the distribution. You're welcome to do the example involving the ProjectTeam yourself. I don't have the time. On 11.03.2005 11:06:59 Ben Gill wrote: Are you not creating an XML file on disk with this version with: else if ((xmlParam != null) (xslParam != null)) { Source src = new StreamSource(new File(xmlParam)); I think it would be good to include an example of how to generate the PDF from a ProjectTeam without touching the disk? Ben -Original Message- From: Jeremias Maerki [mailto:[EMAIL PROTECTED] Sent: 11 March 2005 08:26 To: [EMAIL PROTECTED] Subject: Re: FopServlet Here's a modified version of the servlet: http://cvs.apache.org/~jeremias/FopServlet.java BTW, while updating the file I found an opportunity for a little optimization. In the servlet's case the ByteArrayOutputStream should not be instantiated with the default constructor. This only allocates 64 bytes initially. Every time the buffer runs out of space the old buffer is discarded and a new one with twice the previous space is allocated. If you do new ByteArrayOutputStream(16384) (or an even higher number depending on the documents you serve), you will get a slight performance improvement almost for free. :-) On 10.03.2005 13:02:22 Ben Gill wrote: Maybe the example can be updated with my version? I have not compiled this, but I know it works... Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] _ This message has been checked for all known viruses by the MessageLabs Virus Control Centre. This message has been checked for all known viruses by the MessageLabs Virus Control Centre. * Notice: This email is confidential and may contain copyright material of Ocado Limited (the Company). Opinions and views expressed in this message may not necessarily reflect the opinions and views of the Company. If you are not the intended recipient, please notify us immediately and delete all copies of this message. Please note that it is your responsibility to scan this message for viruses. Company reg. no. 3875000. Ocado Limited Titan Court 3 Bishops Square Hatfield Business Park Hatfield Herts AL10 9NE * - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED
RE: FopServlet
Hi, ok I tried it again and get the same exception!! Here is my code (well I have given you the equiv with project team!): public void execute(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try { ProjectTeam projectTeam = new ProjectTeam(); // set up the logger for the driver if (logger==null) { logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); MessageHandler.setScreenLogger(logger); } MessageHandler.setScreenLogger(logger); File xslFile = new File(./../myxsl, projectTeam2FO.xsl); SAXSource xmlSource = new SAXSource(new IncidentsXMLReader(), new IncidentsInputSource(projectTeam)); SAXSource xslSource = new SAXSource( new InputSource(new FileInputStream(xslFile))); TraxInputHandler input = new TraxInputHandler(xmlSource.getInputSource(), xslSource.getInputSource()); renderXML(input, response); } catch (ServletException ex) { throw ex; } catch (Exception e) { throw new ServletException(e); } } public void renderXML(TraxInputHandler input, HttpServletResponse response) throws ServletException { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); response.setContentType(application/pdf); Driver driver = new Driver(); driver.setLogger(logger); driver.setRenderer(Driver.RENDER_PDF); driver.setOutputStream(out); input.run(driver); byte[] content = out.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); } catch (Exception ex) { throw new ServletException(ex); } } and here is the stack trace: 2005-03-10 07:40:21 StandardContext[/tracker]: Mapped to servlet 'fop' with servlet path '/fop' and path info 'null' and update=true 2005-03-10 07:40:23 StandardWrapperValve[fop]: Servlet.service() for servlet fop threw exception javax.servlet.ServletException: java.net.MalformedURLException at com.ocado.tracker.common.FopServlet.renderXML(FopServlet.java:150) at com.ocado.tracker.common.FopServlet.execute(FopServlet.java:116) at com.ocado.tracker.common.FopServlet.doGet(FopServlet.java:56) at javax.servlet.http.HttpServlet.service(HttpServlet.java:696) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application FilterChain.java:200) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh ain.java:146) at org.springframework.orm.hibernate.support.OpenSessionInViewFilter.doFilterIn ternal(OpenSessionInViewFilter.java:171) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestF ilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application FilterChain.java:166) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh ain.java:146) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja va:209) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja va:144) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(StandardPipeline.java:596) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase .java:445) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(StandardPipeline.java:594) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133 ) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(StandardPipeline.java:596) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve. java:118) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(StandardPipeline.java:594) at
Re: FopServlet
On 10.03.2005 08:49:26 Ben Gill wrote: Hi, ok I tried it again and get the same exception!! Here is my code (well I have given you the equiv with project team!): snip/ Hmm, you are still using the InputHandler approach which I personally don't consider ideal. I'd integrate the renderXML() method into the main execute method and use the pattern from ExampleObj2PDF 1:1. But I can't tell if your problem has something to do with that. Probably not. and here is the stack trace: 2005-03-10 07:40:21 StandardContext[/tracker]: Mapped to servlet 'fop' with servlet path '/fop' and path info 'null' and update=true 2005-03-10 07:40:23 StandardWrapperValve[fop]: Servlet.service() for servlet fop threw exception javax.servlet.ServletException: java.net.MalformedURLException at com.ocado.tracker.common.FopServlet.renderXML(FopServlet.java:150) at com.ocado.tracker.common.FopServlet.execute(FopServlet.java:116) Ok, this doesn't say much other than there's an URL somewhere that's making problems. snip/ at java.lang.Thread.run(Thread.java:534) Caused by: java.net.MalformedURLException at java.net.URL.init(URL.java:571) at java.net.URL.init(URL.java:434) at java.net.URL.init(URL.java:383) at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source) at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source) at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source) at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source) at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) This here is more interesting. DTDConfiguration. Is there a DTD involved somewhere in your processing chain? If yes, I'd try to track that down. Obviously, the problem happens during XSLT stage, not within FOP itself. What I would suggest is even more than the above suggestion. Extract the whole transformation (XSLT+FOP) functionality of the servlet into a separate class that you can easily test outside the web container. Then just call this functionality from within the servlet. at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:495) at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java: 658) I'm sorry that I can't just tell what went wrong. My suggestions should help you track down the problem further and maybe someone else has an additional idea. Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FopServlet
Does the problem persist if you serialize the SAX events generated by the Incident with an identity transformer to a file and run the XSL transformation stand-alone from the command-line? I don't think it's a problem but did you realize that you have two FOP processing runs in your testGeneratePDF() method, the first started by Transformer.transform() and the other by input.run()? Since I can't do anything with the line numbers in the stack trace, this is something you have to do. On 10.03.2005 11:12:07 Ben Gill wrote: -Original Message- From: Jeremias Maerki [mailto:[EMAIL PROTECTED] Sent: 10 March 2005 09:37 To: [EMAIL PROTECTED] Subject: Re: FopServlet On 10.03.2005 08:49:26 Ben Gill wrote: Hi, ok I tried it again and get the same exception!! Here is my code (well I have given you the equiv with project team!): snip/ Hmm, you are still using the InputHandler approach which I personally don't consider ideal. I'd integrate the renderXML() method into the main execute method and use the pattern from ExampleObj2PDF 1:1. But I can't tell if your problem has something to do with that. Probably not. Ok, I tried this and still get the same error... I have created a Junit test for this and here is my code, based upon the ExampleObj2PDF example: public void testGeneratePDF() throws Exception { try { Incident incident = incidentsDAO.loadIncident(new Long(121)); File baseDir = new File(.); File outDir = new File(baseDir, out); outDir.mkdirs(); File xslFile = new File(baseDir, ../source/src/com/ocado/tracker/incidents/fop/incident2FO.xsl); Driver driver = new Driver(); Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); driver.setLogger(logger); MessageHandler.setScreenLogger(logger); driver.setRenderer(Driver.RENDER_PDF); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { driver.setOutputStream(out); //Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(new StreamSource(xslFile)); //Setup input for XSLT transformation Source src = incident.getSource(); //Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(driver.getContentHandler()); //Start XSLT transformation and FOP processing transformer.transform(src, res); } finally { if (out!=null) { out.close(); } } SAXSource xmlSource = new SAXSource(new IncidentsXMLReader(), new IncidentsInputSource(incident)); SAXSource xslSource = new SAXSource( new InputSource(new FileInputStream(xslFile))); TraxInputHandler input = new TraxInputHandler(xmlSource.getInputSource(), xslSource.getInputSource()); input.run(driver); byte[] content = out.toByteArray(); log.debug(Got content [ + content + ]); } catch (Exception e) { log.error(Error [ + e.getMessage() + ], e); } } obviously,my Incident is your ProjectTeam!!! and here is the stack trace: 2005-03-10 07:40:21 StandardContext[/tracker]: Mapped to servlet 'fop' with servlet path '/fop' and path info 'null' and update=true 2005-03-10 07:40:23 StandardWrapperValve[fop]: Servlet.service() for servlet fop threw exception javax.servlet.ServletException: java.net.MalformedURLException at com.ocado.tracker.common.FopServlet.renderXML(FopServlet.java:150) at com.ocado.tracker.common.FopServlet.execute(FopServlet.java:116) Ok, this doesn't say much other than there's an URL somewhere that's making problems. Yes, and it could be the way this: ../source/src/com/ocado/tracker/incidents/fop/incident2FO.xsl); (but the it finds the xsl file and says it exists and this is the string I use for my working version...) or in the XSL: xsl:stylesheet version=1.1 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:fo=http://www.w3.org/1999/XSL/Format; exclude-result-prefixes=fo and/or fo:root xmlns:fo=http://www.w3.org/1999/XSL/Format; As you noted, the error is coming from the DTD: Caused by: java.net.MalformedURLException at java.net.URL.init(URL.java:571) at java.net.URL.init(URL.java
RE: FopServlet
Right, I have got it working! Thanks for your help Jeremias - you were right about input.run() running in my test (which was the old way - which was causing the error!).. the key was to use the ExampleObj2PDF logic in the servlet... Maybe the example can be updated with my version? I have not compiled this, but I know it works... Here is : public void execute(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ByteArrayOutputStream out = null; try { ProjectTeam projectTeam = new ProjectTeam(); projectTeam.setProjectName(test); Driver driver = new Driver(); Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); driver.setLogger(logger); MessageHandler.setScreenLogger(logger); driver.setRenderer(Driver.RENDER_PDF); out = new ByteArrayOutputStream(); driver.setOutputStream(out); File xslFile = new File(./../webapps/myappname/WEB-INF/classes/mypkgname/fop, projectteam2fo.xsl); //Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(new StreamSource(xslFile)); //Setup input for XSLT transformation Source src = incident.getSource(); //Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(driver.getContentHandler()); //Start XSLT transformation and FOP processing transformer.transform(src, res); byte[] content = out.toByteArray(); response.setContentType(application/pdf); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); } catch (Exception e) { throw new ServletException(e); } finally { if (out!=null) { out.close(); } } } Regards -Original Message- From: Jeremias Maerki [mailto:[EMAIL PROTECTED] Sent: 10 March 2005 11:03 To: [EMAIL PROTECTED] Subject: Re: FopServlet Does the problem persist if you serialize the SAX events generated by the Incident with an identity transformer to a file and run the XSL transformation stand-alone from the command-line? I don't think it's a problem but did you realize that you have two FOP processing runs in your testGeneratePDF() method, the first started by Transformer.transform() and the other by input.run()? Since I can't do anything with the line numbers in the stack trace, this is something you have to do. On 10.03.2005 11:12:07 Ben Gill wrote: -Original Message- From: Jeremias Maerki [mailto:[EMAIL PROTECTED] Sent: 10 March 2005 09:37 To: [EMAIL PROTECTED] Subject: Re: FopServlet On 10.03.2005 08:49:26 Ben Gill wrote: Hi, ok I tried it again and get the same exception!! Here is my code (well I have given you the equiv with project team!): snip/ Hmm, you are still using the InputHandler approach which I personally don't consider ideal. I'd integrate the renderXML() method into the main execute method and use the pattern from ExampleObj2PDF 1:1. But I can't tell if your problem has something to do with that. Probably not. Ok, I tried this and still get the same error... I have created a Junit test for this and here is my code, based upon the ExampleObj2PDF example: public void testGeneratePDF() throws Exception { try { Incident incident = incidentsDAO.loadIncident(new Long(121)); File baseDir = new File(.); File outDir = new File(baseDir, out); outDir.mkdirs(); File xslFile = new File(baseDir, ../source/src/com/ocado/tracker/incidents/fop/incident2FO.xsl); Driver driver = new Driver(); Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); driver.setLogger(logger); MessageHandler.setScreenLogger(logger); driver.setRenderer(Driver.RENDER_PDF); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { driver.setOutputStream(out); //Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(new StreamSource(xslFile)); //Setup input for XSLT transformation Source src = incident.getSource(); //Resulting SAX events (the generated FO) must
Re: FopServlet
Ben Gill wrote: Hi, I am trying to use the FopServlet, but ideally, dont want to have to produce the XML file on disk, and then load it up again, just to pass in File, File into XSLTHandler (or TraxInputHandler)... So, I was trying to just pass in InputSources..(ie): ProjectTeam projectTeam = new ProjectTeam(); InputSource projectTeamInputSource = new ProjectTeamInputSource(projectTeam); Is this possible? or do I *have* to save the XML to disk? Yes this is easy to achieve. (I was getting a malformed URL exception when trying to do this) You must have made a mistake somewhere, difficult to guess where. See the website for more examples: http://xml.apache.org/fop/embedding.html Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FopServlet
BenI tried without creating a file on disk but was not successful but then I might have missed something. If disk space is an issue ( like in my case) , I created them in the /tmp directory on Unix where my server was running. The /tmp directory gets cleaned up et end of day and so that solved my problem..ThanksManoj-Ben Gill [EMAIL PROTECTED] wrote: -To: "'[EMAIL PROTECTED]'" [EMAIL PROTECTED]From: Ben Gill [EMAIL PROTECTED]Date: 03/09/2005 02:02AMSubject: FopServletHi,I am trying to use the FopServlet, but ideally, dont want to have to producethe XML file on disk, and then load it up again, just to pass in File, Fileinto XSLTHandler (or TraxInputHandler)...So, I was trying to just pass in InputSources..(ie):ProjectTeam projectTeam = new ProjectTeam();InputSource projectTeamInputSource = newProjectTeamInputSource(projectTeam);Is this possible? or do I *have* to save the XML to disk?(I was getting a malformed URL exception when trying to do this)BenThis message has been checked for all known viruses by the MessageLabs Virus Control Centre. *Notice: This email is confidential and may contain copyright material of Ocado Limited (the "Company"). Opinions and views expressed in this message may not necessarily reflect the opinions and views of the Company.If you are not the intended recipient, please notify us immediately and delete all copies of this message. Please note that it is your responsibility to scan this message for viruses.Company reg. no. 3875000.Ocado LimitedTitan Court3 Bishops SquareHatfield Business ParkHatfieldHertsAL10 9NE*-To unsubscribe, e-mail: [EMAIL PROTECTED]For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: FopServlet
Thanks That is what I have done as well (except saved them locally to the webapp - as had bad experiences before with Swap space running out when using /tmp!!)... I read a few other posts around, where people got this MalformedURLException when trying to do this... But as you say - it works this way so I am not going to lose too much sleep over it! :) -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]Sent: 09 March 2005 15:31To: [EMAIL PROTECTED]Subject: Re: FopServlet Ben I tried without creating a file on disk but was not successful but then I might have missed something. If disk space is an issue ( like in my case) , I created them in the /tmp directory on Unix where my server was running. The /tmp directory gets cleaned up et end of day and so that solved my problem.. Thanks Manoj -Ben Gill [EMAIL PROTECTED] wrote: -To: "'[EMAIL PROTECTED]'" [EMAIL PROTECTED]From: Ben Gill [EMAIL PROTECTED]Date: 03/09/2005 02:02AMSubject: FopServletHi,I am trying to use the FopServlet, but ideally, dont want to have to producethe XML file on disk, and then load it up again, just to pass in File, Fileinto XSLTHandler (or TraxInputHandler)...So, I was trying to just pass in InputSources..(ie):ProjectTeam projectTeam = new ProjectTeam();InputSource projectTeamInputSource = newProjectTeamInputSource(projectTeam);Is this possible? or do I *have* to save the XML to disk?(I was getting a malformed URL exception when trying to do this)BenThis message has been checked for all known viruses by the MessageLabs Virus Control Centre. *Notice: This email is confidential and may contain copyright material of Ocado Limited (the "Company"). Opinions and views expressed in this message may not necessarily reflect the opinions and views of the Company.If you are not the intended recipient, please notify us immediately and delete all copies of this message. Please note that it is your responsibility to scan this message for viruses.Company reg. no. 3875000.Ocado LimitedTitan Court3 Bishops SquareHatfield Business ParkHatfieldHertsAL10 9NE*-To unsubscribe, e-mail: [EMAIL PROTECTED]For additional commands, e-mail: [EMAIL PROTECTED]- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] _This message has been checked for all known viruses by the MessageLabs Virus Control Centre. This message has been checked for all known viruses by the MessageLabs Virus Control Centre. * Notice: This email is confidential and may contain copyright material of Ocado Limited (the "Company"). Opinions and views expressed in this message may not necessarily reflect the opinions and views of the Company. If you are not the intended recipient, please notify us immediately and delete all copies of this message. Please note that it is your responsibility to scan this message for viruses. Company reg. no. 3875000. Ocado Limited Titan Court 3 Bishops Square Hatfield Business Park Hatfield Herts AL10 9NE *
Re: FopServlet
Manoj, you must definitely have missed something. Using the disk for this kills a lot of performance. Chris' suggestion is right. The embedded examples page (where Ben obviously got the example from) should point him in the right direction. Unfortunately, the example servlet in the FOP 0.20.5 distribution was written with the older XSLTInputHandler approach. It is very simple to rewrite that part to use the approach that is shown, step by step, in the embedded examples. ExampleObj2PDF is the key. Ben, if you use a JAXP source instead of an InputSource the thing should become clear (when you also look at ExampleObj2PDF). ProjectTeam.java contains the following method: public Source getSourceForProjectTeam() { return new SAXSource(new ProjectTeamXMLReader(), new ProjectTeamInputSource(this)); } So the source for the JAXP transformation is the above SAXSource instance, and the Result is the SAXResult that you initialize with the ContentHandler you get via Driver.getContentHandler(). All clear? [1] http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/servlet/src/FopServlet.java?hideattic=0rev=1.1.2.2view=markup On 09.03.2005 16:30:38 Manoj_Nair wrote: Ben I tried without creating a file on disk but was not successful but then I might have missed something. If disk space is an issue ( like in my case) , I created them in the /tmp directory on Unix where my server was running. The /tmp directory gets cleaned up et end of day and so that solved my problem.. Thanks Manoj -Ben Gill [EMAIL PROTECTED] wrote: - To: '[EMAIL PROTECTED]' [EMAIL PROTECTED] From: Ben Gill [EMAIL PROTECTED] Date: 03/09/2005 02:02AM Subject: FopServlet Hi, I am trying to use the FopServlet, but ideally, dont want to have to produce the XML file on disk, and then load it up again, just to pass in File, File into XSLTHandler (or TraxInputHandler)... So, I was trying to just pass in InputSources..(ie): ProjectTeam projectTeam = new ProjectTeam(); InputSource projectTeamInputSource = new ProjectTeamInputSource(projectTeam); Is this possible? or do I *have* to save the XML to disk? (I was getting a malformed URL exception when trying to do this) Ben This message has been checked for all known viruses by the MessageLabs Virus Control Centre. * Notice: This email is confidential and may contain copyright material of Ocado Limited (the Company). Opinions and views expressed in this message may not necessarily reflect the opinions and views of the Company. If you are not the intended recipient, please notify us immediately and delete all copies of this message. Please note that it is your responsibility to scan this message for viruses. Company reg. no. 3875000. Ocado Limited Titan Court 3 Bishops Square Hatfield Business Park Hatfield Herts AL10 9NE * - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -To unsubscribe, e-mail: [EMAIL PROTECTED] additional commands, e-mail: [EMAIL PROTECTED] Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FopServlet
If you don't manage, post your sources and I'll give you another shove. :-) On 09.03.2005 16:58:21 Ben Gill wrote: Yeah the sources you quote are the ones I was using... I will give it another try and let you know if I get any problems... Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FopServlet
On Wed, 2005-03-09 at 10:02 +, Ben Gill wrote: Hi, I am trying to use the FopServlet, but ideally, dont want to have to produce the XML file on disk, and then load it up again, just to pass in File, File into XSLTHandler (or TraxInputHandler)... I'm not sure about FopServlet, but our approach is to have a servlet mapping. All files named *.vfo will point to our Servlet. The Servlet will then extract the name requested and load the .vfo file. It will then use velocity first to insert information from the request and session before using the FOP engine to render as PDF and pass the resulting document directly out via streaming. No saving to disk is required anywhere in this process. Even better - I forgot to mention this is a two step process. Before being passed to FOP we actually have a XSLT transform occur. We have a standard transform for content which takes away the complexity of FO. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: fopservlet classpath problem... or is it?
Sorry to reply to my own message, but it was the RPM installation not passing the endorsed.directories. Read on only if this is relevant to you. I hope this helps anybody else, who might be encountering similar problems using Fop with a Tomcat RPM installation. This was my good start-up, which was Tomcat 4.1.18 hand-installed: /usr/java/j2sdk1.4.1_01/bin/java -Xms32m -Xmx256m -Djava.endorsed.dirs=/usr/java/jakarta-tomcat-4.1.18/bin:/usr/java/jakarta-t omcat-4.1.18/common/endorsed -classpath /usr/java/j2sdk1.4.1_01/lib/tools.jar:/usr/java/jakarta-tomcat-4.1.18/bin/bo otstrap.jar -Dcatalina.base=/usr/java/jakarta-tomcat-4.1.18 -Dcatalina.home=/usr/java/jakarta-tomcat-4.1.18 -Djava.io.tmpdir=/usr/java/jakarta-tomcat-4.1.18/temp org.apache.catalina.startup.Bootstrap start And this was my bad start-up with Tomcat 4.1.24 installed using the RPM: /usr/java/j2sdk1.4.1_02/bin/java -Djava.endorsed.dirs= -classpath /usr/java/j2sdk1.4.1_02/lib/tools.jar:/var/tomcat4/bin/bootstrap.jar -Dcatalina.base=/var/tomcat4 -Dcatalina.home=/var/tomcat4 -Djava.io.tmpdir=/var/tomcat4/temp org.apache.catalina.startup.Bootstrap start The RPM installation sets java.endorsed.dirs to nothing, which means that the XML parser remained unendorsed. Now that I've spotted this, I have also set -Xms32m -Xmx256m to increase the memory for large files, and edit. I've added into /usr/bin/dtomcat4: 8 # Endorsed directories JAVA_ENDORSED_DIRS=${CATALINA_HOME}/common/endorsed echo Using JAVA_ENDORSED_DIRS:${JAVA_HOME} # Java options - we want lots of memory for Fop JAVA_OPTS=-Xms32m -Xmx256m ${JAVA_OPTS} 8 Everything is running OK now, except for the fact that I get the error in catalina.out similar to that reported at http://www.mail-archive.com/tomcat-dev@jakarta.apache.org/msg37249.html . Evidently, Fop's choice of XML parser doesn't agree with Tomcat. Having said that, I have got a working configuration now. -Original Message- From: Rob Staveley (Tom) [mailto:[EMAIL PROTECTED] Sent: 20 August 2003 11:34 To: [EMAIL PROTECTED] Subject: fopservlet classpath problem... or is it? Most, but not all, XSL files rendered by FopServlet get me the exception below from my Tomcat 4.1.24 installation installed via RPMs. Running it at the command line works fine. I have a Tomcat 4.1.18 installation not installed via RPMs which works OK with the same XML and XSL files. On both platforms, I'm using JDK 1.4.1. I've put xalan-2.4.1.jar, xercesImpl-2.2.1.jar and xml-apis.jar into /var/tomcat4/common/endorsed. Should I be doing something else to sort out the classpath, or am I barking up the wrong tree? javax.servlet.ServletException: org.apache.fop.apps.FOPException: No flow in page-sequence at FopServlet2.renderXML(FopServlet2.java:184) at FopServlet2.doGet(FopServlet2.java:121) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source) at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source) at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContext.invoke(Unknown Source) at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(Unknown Source) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(Unknown Source) at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at
RE: FopServlet, passing parameters as URL
Sorry, I find some bugs in the other code. I found this code in the net... import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; import org.xml.sax.*; import org.apache.fop.apps.Driver; import org.apache.fop.apps.FOPException; public class XPDF extends HttpServlet { public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String xmlParam = request.getParameter(XML_REQUEST_PARAM); String xslParam = request.getParameter(XSL_REQUEST_PARAM); buildPdf(request, response, xmlParam, xslParam); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } private void buildPdf(HttpServletRequest request, HttpServletResponse response, String xmlParam, xslParam) throws IOException, FileNotFoundException { // Data stream out of the xslt transformer ByteArrayOutputStream xslt_out = new ByteArrayOutputStream(); // Data stream out of the pdf renderer ByteArrayOutputStream render_out = new ByteArrayOutputStream(); // Data stream back to the browser ServletOutputStream out = response.getOutputStream(); response.setContentType(application/pdf); try { // Get a transformer factory TransformerFactory tFactory = TransformerFactory.newInstance(); // Provide the .xml and .xslt-fo input files Source xmlSource = new StreamSource (xmlParam); Source xslSource = new StreamSource(xslParam); Result xmlResult = new StreamResult(xslt_out); // Configure out transformer Transformer transformer = tFactory.newTransformer(xslSource); // Transform the .xml document into a FO document stream transformer.transform(xmlSource, xmlResult); // Set the output from the first transformation // as the input to the second transformation ByteArrayInputStream foInput = new ByteArrayInputStream(xslt_out.toByteArray()); // Get a transformation driver configure it Driver driver = new Driver(new InputSource(foInput), render_out); driver.setRenderer(Driver.RENDER_PDF); // Perform the transformation driver.run(); byte[] content = render_out.toByteArray(); response.setContentLength(content.length); out.write(content); out.flush(); driver= null; foInput = null; xmlResult = null; xslSource = null; xmlSource = null; } catch (FOPException fe) { out.print(fe.getMessage()); fe.printStackTrace(new PrintStream((OutputStream)out)); } catch (Exception e) { out.print(e.getMessage()); e.printStackTrace(new PrintStream((OutputStream)out)); } } } - Nueva Tiscali ADSL libre www.tiscali.es/libre ¡¡¡ POR SÓLO 16,95 euros al mes !!! + tiempo de conexión (0,024 ./min.) Y cuota máxima garantizada de 39,95 ./mes AHORA ALTA GRATIS ¡¡¡ Por fin pagas por lo que consumes !!! - - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FopServlet, passing parameters as URL
This is bad practice! Writing the XSL-FO intermediate result into a byte array is wasting resources and speed. See ExampleXML2PDF.java for a better way, namely piping SAX events from the Transformer through to FOP. On 17.04.2003 15:03:42 david.bg wrote: Sorry, I find some bugs in the other code. I found this code in the net... snip/ private void buildPdf(HttpServletRequest request, HttpServletResponse response, String xmlParam, xslParam) throws IOException, FileNotFoundException { // Data stream out of the xslt transformer ByteArrayOutputStream xslt_out = new ByteArrayOutputStream(); // Data stream out of the pdf renderer ByteArrayOutputStream render_out = new ByteArrayOutputStream(); // Data stream back to the browser ServletOutputStream out = response.getOutputStream(); response.setContentType(application/pdf); try { // Get a transformer factory TransformerFactory tFactory = TransformerFactory.newInstance(); // Provide the .xml and .xslt-fo input files Source xmlSource = new StreamSource (xmlParam); Source xslSource = new StreamSource(xslParam); Result xmlResult = new StreamResult(xslt_out); // Configure out transformer Transformer transformer = tFactory.newTransformer(xslSource); // Transform the .xml document into a FO document stream transformer.transform(xmlSource, xmlResult); // Set the output from the first transformation // as the input to the second transformation ByteArrayInputStream foInput = new ByteArrayInputStream(xslt_out.toByteArray()); // Get a transformation driver configure it Driver driver = new Driver(new InputSource(foInput), render_out); driver.setRenderer(Driver.RENDER_PDF); // Perform the transformation driver.run(); byte[] content = render_out.toByteArray(); response.setContentLength(content.length); out.write(content); out.flush(); driver= null; foInput = null; xmlResult = null; xslSource = null; xmlSource = null; } catch (FOPException fe) { out.print(fe.getMessage()); fe.printStackTrace(new PrintStream((OutputStream)out)); } catch (Exception e) { out.print(e.getMessage()); e.printStackTrace(new PrintStream((OutputStream)out)); } } } Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: FopServlet, passing parameters as URL
What bugs did u find? I have been using it with no problems. -Adam -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: April 17, 2003 6:04 AM To: [EMAIL PROTECTED] Subject: RE: FopServlet, passing parameters as URL Sorry, I find some bugs in the other code. I found this code in the net... import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; import org.xml.sax.*; import org.apache.fop.apps.Driver; import org.apache.fop.apps.FOPException; public class XPDF extends HttpServlet { public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String xmlParam = request.getParameter(XML_REQUEST_PARAM); String xslParam = request.getParameter(XSL_REQUEST_PARAM); buildPdf(request, response, xmlParam, xslParam); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } private void buildPdf(HttpServletRequest request, HttpServletResponse response, String xmlParam, xslParam) throws IOException, FileNotFoundException { // Data stream out of the xslt transformer ByteArrayOutputStream xslt_out = new ByteArrayOutputStream(); // Data stream out of the pdf renderer ByteArrayOutputStream render_out = new ByteArrayOutputStream(); // Data stream back to the browser ServletOutputStream out = response.getOutputStream(); response.setContentType(application/pdf); try { // Get a transformer factory TransformerFactory tFactory = TransformerFactory.newInstance(); // Provide the .xml and .xslt-fo input files Source xmlSource = new StreamSource (xmlParam); Source xslSource = new StreamSource(xslParam); Result xmlResult = new StreamResult(xslt_out); // Configure out transformer Transformer transformer = tFactory.newTransformer(xslSource); // Transform the .xml document into a FO document stream transformer.transform(xmlSource, xmlResult); // Set the output from the first transformation // as the input to the second transformation ByteArrayInputStream foInput = new ByteArrayInputStream(xslt_out.toByteArray()); // Get a transformation driver configure it Driver driver = new Driver(new InputSource(foInput), render_out); driver.setRenderer(Driver.RENDER_PDF); // Perform the transformation driver.run(); byte[] content = render_out.toByteArray(); response.setContentLength(content.length); out.write(content); out.flush(); driver= null; foInput = null; xmlResult = null; xslSource = null; xmlSource = null; } catch (FOPException fe) { out.print(fe.getMessage()); fe.printStackTrace(new PrintStream((OutputStream)out)); } catch (Exception e) { out.print(e.getMessage()); e.printStackTrace(new PrintStream((OutputStream)out)); } } } - Nueva Tiscali ADSL libre www.tiscali.es/libre ¡¡¡ POR SÓLO 16,95 euros al mes !!! + tiempo de conexión (0,024 ./min.) Y cuota máxima garantizada de 39,95 ./mes AHORA ALTA GRATIS ¡¡¡ Por fin pagas por lo que consumes !!! - - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: FopServlet, passing parameters as URL
Hi all, Adam: If you use adobe acrobat 4.0, sometimes the pdf opens in the browser as a blank page. I try upgrade acrobat to 5.0 and all works, but I found the code posted in another mail, and it seems correct. (Jeremias says it's inefficient). Jeremias: If you use the code from exampleXML2PDF in a servlet... well, read the first line: IEx fails sometimes... :) I think there will be another way to do it, but I don't know how: XPDF code works, and lag isn't important... David - Nueva Tiscali ADSL libre www.tiscali.es/libre ¡¡¡ POR SÓLO 16,95 euros al mes !!! + tiempo de conexión (0,024 ./min.) Y cuota máxima garantizada de 39,95 ./mes AHORA ALTA GRATIS ¡¡¡ Por fin pagas por lo que consumes !!! - - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: FopServlet, passing parameters as URL
Thanks for the update. Since acrobat 5 is a free download i wouldn't worry about this problem. Get users to upgrade to the current version :). This way you will be able to include the current 128 encryption security features as well. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: April 17, 2003 9:26 AM To: [EMAIL PROTECTED] Subject: RE: FopServlet, passing parameters as URL Hi all, Adam: If you use adobe acrobat 4.0, sometimes the pdf opens in the browser as a blank page. I try upgrade acrobat to 5.0 and all works, but I found the code posted in another mail, and it seems correct. (Jeremias says it's inefficient). Jeremias: If you use the code from exampleXML2PDF in a servlet... well, read the first line: IEx fails sometimes... :) I think there will be another way to do it, but I don't know how: XPDF code works, and lag isn't important... David - Nueva Tiscali ADSL libre www.tiscali.es/libre ¡¡¡ POR SÓLO 16,95 euros al mes !!! + tiempo de conexión (0,024 ./min.) Y cuota máxima garantizada de 39,95 ./mes AHORA ALTA GRATIS ¡¡¡ Por fin pagas por lo que consumes !!! - - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FopServlet, passing parameters as URL
I went back to the other mails. So now, it's clear what's wrong. As Jörg said, it's bad to write the output from FOP directly to the servlet's OutputStream. That's where you have to use a ByteArrayOutputStream. There's no easy way around it, I think. But the intermediate buffer between XSLT and FOP is still bad and unnecessary. So below you find a modified version of the code your posted on 2003-04-14. Warning: just a hack-up, untested, but should work IMO. public class XURLPDF extends HttpServlet { public static final String XML_REQUEST_PARAM = xml; public static final String XSL_REQUEST_PARAM = xsl; Logger log = null; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { if(log == null) { log = new ConsoleLogger(ConsoleLogger.LEVEL_WARN); MessageHandler.setScreenLogger(log); } try { String xmlParam = request.getParameter(XML_REQUEST_PARAM); String xslParam = request.getParameter(XSL_REQUEST_PARAM); if((xmlParam != null) (xslParam != null)) { response.setContentType(application/pdf); Driver driver = new Driver(); Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); driver.setLogger(logger); MessageHandler.setScreenLogger(logger); driver.setRenderer(Driver.RENDER_PDF); //driver.setOutputStream(response.getOutputStream()); ByteArrayOutputStream baout = new ByteArrayOutputStream(16384); //The parameter 16384 initializes the initial buffer to //16KB to reduce memory reallocations by //ByteArrayOutputStream driver.setOutputStream(baout); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(new StreamSource(xslParam)); Source src=new StreamSource(xmlParam); Result res = new SAXResult(driver.getContentHandler()); transformer.transform(src, res); final byte[] content = out.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); } else { PrintWriter out = response.getWriter(); out.println(htmlheadtitleError/title/headbodyh1FopServlet Error/h1h3request param not given./body/html); } } catch (Exception ex) { throw new ServletException(ex); } } } If you care about performance you should consider caching stylesheets or using XSLTC. On 17.04.2003 18:25:40 david.bg wrote: Hi all, Adam: If you use adobe acrobat 4.0, sometimes the pdf opens in the browser as a blank page. I try upgrade acrobat to 5.0 and all works, but I found the code posted in another mail, and it seems correct. (Jeremias says it's inefficient). Jeremias: If you use the code from exampleXML2PDF in a servlet... well, read the first line: IEx fails sometimes... :) I think there will be another way to do it, but I don't know how: XPDF code works, and lag isn't important... Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: FopServlet, passing parameters as URL
When I ran the attached code below, I got blank screen instead of the pdf file. Where is the pdf file? Thanks SteveAdam Shelley [EMAIL PROTECTED] wrote: Thank you david for the code post. This is the exact code I was looking forin a thread i started back a couple weeks ago. Very much appreciated.-Adam-Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]Sent: April 14, 2003 9:01 AMTo: [EMAIL PROTECTED]Subject: FopServlet, passing parameters as URLI "mix" FopServlet.java and ExampleXML2PDF.java to develop a servlet thatuses xml and xml parameters as url.This is the code:/*XURLPDF.java, v 1.0 2003/03/14 17:30:00 davidAbstract :Mixing code from FopServlet.java and ExampleXML2PDF.java,this servlet obtains a pdf, passing xml and xsl parameters as url.Author: David Bermudez Garcia*/import java.io.*;//SERVLETimport javax.servlet.*;import javax.servlet.http.*;//SAXimport javax.xml.transform.Transformer;import javax.xml.transform.TransformerFactory;import javax.xml.transform.TransformerException;import javax.xml.transform.Source;import javax.xml.transform.Result;import javax.xml.transform.stream.*;import javax.xml.transform.sax.SAXResult;import org.xml.sax.InputSource;import org.xml.sax.XMLReader;//FOPimport org.apache.fop.apps.Driver;import org.apache.fop.apps.FOPException;import org.apache.fop.messaging.MessageHandler;//AVALONimport org.apache.avalon.framework.logger.ConsoleLogger;import org.apache.avalon.framework.logger.Logger;public class XURLPDF extends HttpServlet {public static final String XML_REQUEST_PARAM = "xml";public static final String XSL_REQUEST_PARAM = "xsl";Logger log = null;public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException{if(log == null) {log = new ConsoleLogger(ConsoleLogger.LEVEL_WARN);MessageHandler.setScreenLogger(log);}try {String xmlParam = request.getParameter(XML_REQUEST_PARAM);String xslParam = request.getParameter(XSL_REQUEST_PARAM);if((xmlParam != null) (xslParam != null)) {response.setContentType("application/pdf");Driver driver = new Driver();Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);driver.setLogger(logger);MessageHandler.setScreenLogger(logger);driver.setRenderer(Driver.RENDER_PDF);driver.setOutputStream(response.getOutputStream());TransformerFactory factory = TransformerFactory.newInstance();Transformer transformer = factory.newTransformer(newStreamSource(xslParam));Source src="" StreamSource(xmlParam);Result res = new SAXResult(driver.getContentHandler());transformer.transform(src, res);} else {PrintWriter out = response.getWriter();out.println(" FopServletError request param not given.");}} catch (Exception ex) {throw new ServletException(ex);}}}-Nueva Tiscali ADSL libre www.tiscali.es/libre?POR SO 16,95 euros al mes !!!+ tiempo de conexi (0,024 ./min.)Y cuota mima garantizada de 39,95 ./mesAHORA ALTA GRATIS?Por fin pagas por lo que consumes !!!--To unsubscribe, e-mail: [EMAIL PROTECTED]For additional commands, e-mail: [EMAIL PROTECTED]-To unsubscribe, e-mail: [EMAIL PROTECTED]For additional commands, e-mail: [EMAIL PROTECTED]Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo.
RE: FopServlet, passing parameters as URL
Hello, Steve, you know that some browsers need to end the url with pdf to assimilate that the content that are getting is a pdf file? Because that, you need to write your URL this form: http://host:port/directory/servlet?xml=somethingxsl=somethingdummi=pdf an example: http://pingu:8080/prueba/XURLPDF?xml=http://pingu:8080/1.xmlxsl=http://pingu:8080/1.xsldummi=pdf - Nueva Tiscali ADSL libre www.tiscali.es/libre ¡¡¡ POR SÓLO 16,95 euros al mes !!! + tiempo de conexión (0,024 ./min.) Y cuota máxima garantizada de 39,95 ./mes AHORA ALTA GRATIS ¡¡¡ Por fin pagas por lo que consumes !!! - - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FopServlet, passing parameters as URL
Steve Guo wrote: When I ran the attached code below, I got blank screen instead of the pdf file. Where is the pdf file? Eaten by IEx, I guess: driver.setOutputStream(response.getOutputStream()); ^^ IEx has difficulties if the content length of the response is not set. Get the relevant code from FOPServlet.java from the FOP source distribution. J.Pietschmann - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FopServlet error in Oracle OC4J
I wonder what the Oracle guys did to that server that it generates so many problems. :-) Anyway, can you please check if you have any JAXP libraries from FOP in the classpath (xml-api.jar, xalan.jar, xercesImpl.jar)? If yes try removing them. Maybe something like that interferes with Oracle's JAXP implementation. FOP uses plain JAXP by the book in its latest version. So if anything goes wrong with Oracle's implementation and you don't have any foreign JAXP implementations in your classpath, I suggest you contact Oracle support to help you, because the exception does not happen in FOP directly but in the JAXP API (see top of stacktrace: SAXParserFactory.newInstance). On 27.02.2003 12:25:21 Roberto Venanzi wrote: HI, I have problems with the following code in the FopServlet that run in Oracle OC4J: in the FopServlet I have modified the metod renderFO to add a barcode font: snip/ the error is: java.lang.ClassCastException: oracle.xml.jaxp.JXSAXParserFactory at javax.xml.parsers.SAXParserFactory.newInstance(Unknown Source) at org.apache.fop.configuration.ConfigurationReader.createParser(Unknown Source) at org.apache.fop.configuration.ConfigurationReader.start (Unknown Source) snip/ Anyone can help me? Jeremias Maerki - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FopServlet error in Oracle OC4J
Jeremias Maerki wrote: I wonder what the Oracle guys did to that server that it generates so many problems. :-) Bought it from Ironflare? __ This message and its attachments have been found clean from known viruses with three different antivirus programs. __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: FOPServlet and XML string
I'm having the same issues, so if you find a solution, please post. But, it seems like you could use the XALAN function XSLTransform to convert a DOM document or a string using an XSL file to either a FO file or another DOM document. XSLTInputHandler will only take java.io.File parameters, but I've seen examples of using the JAXP Transformer to do the job as well. See: http://www.devx.com/xml/articles/vp101201/vp101201-1.asp. It seems as if this could be modified to use a StringReader and/or StringWriter. Let me know if you have any luck. Mike -Original Message- From: Mo, Jennifer [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 25, 2002 2:17 PM To: [EMAIL PROTECTED] Subject: FOPServlet and XML string Does anyone know how to modify the FOPServlet so that it takes in a XML string instead of a XML file? The XSLTInputHandler class (which inherits from InputHandler) seems to only take in a file but not a String. i'm stuck. Any ideas or suggestion?
RE: FopServlet
Look in the log. Maybe your classpath is incorrect, maybe something is missing. You never know. -Original Message- From: Samimi, Ashkan (Contractor) [mailto:[EMAIL PROTECTED] Sent: March 19, 2002 6:22 AM To: '[EMAIL PROTECTED]' Subject: FopServlet Hi, Running this command on command prompt creates the PDF file perfectly: FOP.bat -xml glossay.xml -xsl glossay.xsl -pdf glossay.pdf Running the same with FopServlet http://localhost:7001/FopServlet?xml=glossay.xmlxsl=glossay.xsl Does not do anything. No error messages, no initiation of acrobat reader. Just a Blank browser screen. I'm using FOP 0.20.3 and FopServlet provided in the Examples\embedding directory. What do I do wrong!!?? Can somebody help. Many thanks in advance, Ashkan
Re: FopServlet
What you're doing wrong is most likely using IE as your browser. IE depends on filename extensions to determine the sort of file it is to display - in this case, it looks for '.pdf' You need to add the magic string a=b.pdf to the end of the URL that invokes the FopServlet, viz: http://blah.blah.blah/servlet/FopServlet?xsl=blah.xslxml=blah.xmla=b.pdf Also - and this may be the most important, you should change your Acrobat reader congifuration so that IE does not attempt to execute it within its window. Acrobat is an Active X component and there is a load of security nonsense yadda yadda that causes the IE screen to present a blank screen rather randomly. See adobe publication http://www.adobe.com/support/techdocs/98fe.htm for details. TJ P.S. All of this works fine in Netscape fyi. - Original Message - From: Samimi, Ashkan (Contractor) [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, March 19, 2002 6:22 AM Subject: FopServlet Hi, Running this command on command prompt creates the PDF file perfectly: FOP.bat -xml glossay.xml -xsl glossay.xsl -pdf glossay.pdf Running the same with FopServlet http://localhost:7001/FopServlet?xml=glossay.xmlxsl=glossay.xsl Does not do anything. No error messages, no initiation of acrobat reader. Just a Blank browser screen. I'm using FOP 0.20.3 and FopServlet provided in the Examples\embedding directory. What do I do wrong!!?? Can somebody help. Many thanks in advance, Ashkan
Re: FopServlet question
Thanx Keiron I solved the problem - the FopServlet with xsl and xml arguments does not work in IE5.X - its the old problem with IE paying attention only to file extensions. The solution is to add the suffix a=b.pdf to the URL that invokes FopServlet. TJ - Original Message - From: Keiron Liddle [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, March 04, 2002 3:35 AM Subject: Re: FopServlet question Hi, Lets consider what this problem could be: - you are getting a transform error when using xml and xslt (stylesheet error) - the files from the distribution also have the problem - the files in the distribution work in the distribution - your file probably also work on the command line - the FopServlet works (I have tested it) This immediately tells us the it is a problem with the environment. What is different? You are running in a servlet. What libraries does the servlet use to run? I'm sure it is using an xml parser and possibly an xslt processor. So fix your classpath, ie. remove old/incompatible versions of xml libararies. (Note: jdk1.4 includes an xml parser) On 2002.03.02 04:08 TJ Smith wrote: Hello The xsl and xml files are rather huge and most likely would not be welcomed with open arms by the group :-) I have attached relevant bits of both files and the error walkback from executing FopServlet below. I have also tried the FopPrintServlet with identical results viz. works fine with 'fo' parameter, squawks about stylesheet requires attribute: version' if invoked with 'xml' and 'xsl' parameters. I tried using xsl and xml files from the fop 20.3 distribution - and they produced the same disappointing results. I have recompiled both servlets without error - and have the jar files that came with fop 20.3 in the path. This is making me crazy - crazier, actually :-) - so any and all advice is appreciated! Note that I did have the XSLT and FO namespaces in he stylesheet - but thanks for the suggestion :-)
Re: FopServlet question
Thanks Matt. I discovered my problem - it's an old problem with the (*%R# IE5 (it works fine with Netscape). IE looks for file extensions to decide what to do with the file - FopServlet with xml and xsl parameters evidently generates a file without the extension and dumb IE craps out. The solution is to append a=b.pdf to the end of the URL invoking the FopServlet. Anyway, I appreciated your response! TJ - Original Message - From: Matt Savino [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, March 02, 2002 9:39 AM Subject: Re: FopServlet question I seem to remember having some trouble getting XSLT input handler to work as well. I ended up doing the transoformation separately, then feeding the resulting FO DOM as an arg to driver.render(). I've included the servet I use , one of the simpler stylesheets, and some dummy XML (there's a lot of extra code in the servlet, but you should be able to find the relevant parts). This system runs on .20.2. I'm waiting to see if .20.3 is solidified. Hope this helps. -Matt TJ Smith wrote: Hello The xsl and xml files are rather huge and most likely would not be welcomed with open arms by the group :-) I have attached relevant bits of both files and the error walkback from executing FopServlet below. I have also tried the FopPrintServlet with identical results viz. works fine with 'fo' parameter, squawks about stylesheet requires attribute: version' if invoked with 'xml' and 'xsl' parameters. I tried using xsl and xml files from the fop 20.3 distribution - and they produced the same disappointing results. I have recompiled both servlets without error - and have the jar files that came with fop 20.3 in the path. This is making me crazy - crazier, actually :-) - so any and all advice is appreciated! Note that I did have the XSLT and FO namespaces in he stylesheet - but thanks for the suggestion :-) XSL snippet (original file is about 2500 lines) --- ?xml version=1.0? xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:fo=http://www.w3.org/1999/XSL/Format; xsl:template name=sectionTableInit ... /xsl:stylesheet XML snippet (original file is 363 lines) -- ?xml version=1.0 standalone=no? !-- !DOCTYPE fda-form SYSTEM DTD/Canonical.dtd -- !-- The ID attribute for fda-form uniquely identifies THIS form -- form ID=f7 column-width=9.8cm,9.8cm ... Here is the error walkback stuff (same for FopServlet and FopPrintServlet) -- -- Error: 500 Location: /fop/servlet/FopServlet Internal Servlet Error: javax.servlet.ServletException at FopServlet.renderXML(FopServlet.java:131) at FopServlet.doGet(FopServlet.java:73) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at org.apache.tomcat.facade.ServletHandler.doService(Unknown Source) at org.apache.tomcat.core.Handler.invoke(Unknown Source) at org.apache.tomcat.core.Handler.service(Unknown Source) at org.apache.tomcat.facade.ServletHandler.service(Unknown Source) at org.apache.tomcat.core.ContextManager.internalService(Unknown Source) at org.apache.tomcat.core.ContextManager.service(Unknown Source) at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Unknown Source) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(Unknown Source) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Unknown Source) at java.lang.Thread.run(Thread.java:484) Root cause: org.apache.fop.apps.FOPException at org.apache.fop.apps.XSLTInputHandler.getParser(XSLTInputHandler.java:109) at FopServlet.renderXML(FopServlet.java:124) at FopServlet.doGet(FopServlet.java:73) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at org.apache.tomcat.facade.ServletHandler.doService(Unknown Source) at org.apache.tomcat.core.Handler.invoke(Unknown Source) at org.apache.tomcat.core.Handler.service(Unknown Source) at org.apache.tomcat.facade.ServletHandler.service(Unknown Source) at org.apache.tomcat.core.ContextManager.internalService(Unknown Source) at org.apache.tomcat.core.ContextManager.service(Unknown Source) at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Unknown Source) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(Unknown Source) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Unknown Source) at java.lang.Thread.run(Thread.java:484
Re: FopServlet question
) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(Unknown Source) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Unknown Source) at java.lang.Thread.run(Thread.java:484) - ; SystemID: file:///C:/java/jakarta-tomcat-3.3/bin; Line#: 1; Column#: 8 ; SystemID: file:///C:/java/jakarta-tomcat-3.3/bin; Line#: 1; Column#: 8 javax.xml.transform.TransformerException: stylesheet requires attribute: version at org.apache.xalan.processor.StylesheetHandler.error(StylesheetHandler.java:85 2) at org.apache.xalan.processor.XSLTElementProcessor.setPropertiesFromAttributes( XSLTElementProcessor.java:389) at org.apache.xalan.processor.XSLTElementProcessor.setPropertiesFromAttributes( XSLTElementProcessor.java:300) at org.apache.xalan.processor.ProcessorLRE.startElement(ProcessorLRE.java:184) at org.apache.xalan.processor.StylesheetHandler.startElement(StylesheetHandler. java:632) at org.apache.xerces.parsers.SAXParser.startElement(SAXParser.java:1371) at org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidat or.java:840) at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XM LDocumentScanner.java:990) at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner. java:381) at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:948) at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFa ctoryImpl.java:795) at org.apache.xalan.processor.TransformerFactoryImpl.newXMLFilter(TransformerFa ctoryImpl.java:486) at org.apache.fop.apps.TraxInputHandler.getXMLFilter(TraxInputHandler.java:84) at java.lang.reflect.Method.invoke(Native Method) at org.apache.fop.apps.XSLTInputHandler.getParser(XSLTInputHandler.java:102) at FopServlet.renderXML(FopServlet.java:124) at FopServlet.doGet(FopServlet.java:73) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at org.apache.tomcat.facade.ServletHandler.doService(Unknown Source) at org.apache.tomcat.core.Handler.invoke(Unknown Source) at org.apache.tomcat.core.Handler.service(Unknown Source) at org.apache.tomcat.facade.ServletHandler.service(Unknown Source) at org.apache.tomcat.core.ContextManager.internalService(Unknown Source) at org.apache.tomcat.core.ContextManager.service(Unknown Source) at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Unknown Source) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(Unknown Source) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Unknown Source) at java.lang.Thread.run(Thread.java:484) ... - Original Message - From: Matt Savino [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, March 01, 2002 2:47 PM Subject: Re: FopServlet question Make sure you're stylesheet has both XSLT and FO namespaces. I know I fought with this one for a day or two: ?xml version=1.0? xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:fo=http://www.w3.org/1999/XSL/Format; ... If that doesn't work, you might try attaching the xsl and xml files to this list. -Matt TJ Smith wrote: Hello My application requires servlet generated pdf from input xsl and xml files. In fact, the application seems to be exactly what is described in the document http://xml.apache.org/fop/embedding.html as http://blah.blah.blah/fop/servlet/FopServlet?xml=/home/path/to/xmlfile.xmlx sl=/home/path/to/xslfile.xsl I am using fop 20.3 and cannot get the FopServlet included with that release to create the pdf via the url as above. I constanly get a massive error trace listing containing the error: java.lang.reflect.InvocationTargetException: org.apache.fop.apps.FOPException: stylesheet requires attribute: version my style sheet DOES have a version - so I'm a bit lost as to what is going on here! I should add that FopServlet works fine when invoked with the url: http://blah.blah.blah/fop/servlet/FopServlet?fo=blah.fo Any suggestions would be appreciated! TJ
Re: FopServlet question
Make sure you're stylesheet has both XSLT and FO namespaces. I know I fought with this one for a day or two: ?xml version=1.0? xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:fo=http://www.w3.org/1999/XSL/Format; ... If that doesn't work, you might try attaching the xsl and xml files to this list. -Matt TJ Smith wrote: Hello My application requires servlet generated pdf from input xsl and xml files. In fact, the application seems to be exactly what is described in the document http://xml.apache.org/fop/embedding.html as http://blah.blah.blah/fop/servlet/FopServlet?xml=/home/path/to/xmlfile.xmlxsl=/home/path/to/xslfile.xsl I am using fop 20.3 and cannot get the FopServlet included with that release to create the pdf via the url as above. I constanly get a massive error trace listing containing the error: java.lang.reflect.InvocationTargetException: org.apache.fop.apps.FOPException: stylesheet requires attribute: version my style sheet DOES have a version - so I'm a bit lost as to what is going on here! I should add that FopServlet works fine when invoked with the url: http://blah.blah.blah/fop/servlet/FopServlet?fo=blah.fo Any suggestions would be appreciated! TJ