Question about serializers
I asked a few days ago about creating a PDF on a background thread (Subject:Create PDF on background) but didn't got an answer I could use. Our users requests the PDF and it cannot be batched. Sometimes it takes a few minutes to be created. What I want to do is something like this: type="fo2pdf"/> value="cocoon:/progress_pipeline" type="html"/> Is something like this possible? Maybe a custom serializer? Is there another way to do this? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Question about serializers
Hello Fawzib, what you are suggesting/trying seems quite impossible to me? But, I am just wondering, why would take it so long for the pdf's to be generated? I suppose you are generating a pdf from several xml docs and serialize it to pdf? Well, do the xml docs change every minute? Why can't you just solve it by smart caching? Do you know which pdfs need to be generated? If you know this, and you really want to do a background creation, use a cron job for this and cache it...or save it as pdf and serve that one A few minutes to be generated, how large are they > -Original Message- > From: Fawzib Rojas [mailto:[EMAIL PROTECTED] > Posted At: dinsdag 13 december 2005 22:01 > Posted To: Cocoon User List > Conversation: Question about serializers > Subject: Question about serializers > Importance: High > > > I asked a few days ago about creating a PDF on a background thread > (Subject:Create PDF on background) but didn't got an answer I > could use. > Our users requests the PDF and it cannot be batched. > Sometimes it takes > a few minutes to be created. What I want to do is something like this: > > > > > > > > value="cocoon:/pdf_pipeline" > type="fo2pdf"/> > > value="cocoon:/progress_pipeline" type="html"/> > > > > Is something like this possible? Maybe a custom serializer? Is there > another way to do this? > > > - > 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: Question about serializers
Fawzib Rojas wrote: I asked a few days ago about creating a PDF on a background thread (Subject:Create PDF on background) but didn't got an answer I could use. Our users requests the PDF and it cannot be batched. Sometimes it takes a few minutes to be created. What I want to do is something like this: type="fo2pdf"/> value="cocoon:/progress_pipeline" type="html"/> Is something like this possible? Maybe a custom serializer? Is there another way to do this? Seems to me you could accomplish this fairly easily with Flowscript. Something like: function pdfDocumentFlow() { // Start the PDF running in the background, it will be // written to the OutputStream: var outputStream = new MySpecialOutputStream(); cocoon.processPipelineTo( "pdf-generation-pipeline", {param1:value1, param2:value2}, outputStream ); // Display the waiting page until complete: while(!outputStream.isClosed()) { sendPageAndWait("waiting-screen"); } // PDF is finished, now display it: cocoon.sendPage( "pdf-display-pipeline", {byteArray : outputStream.toByteArray()} ); } Where "pdf-generation-pipeline" is the normal pipeline producing your PDF document, "waiting-screen" is obviously the screen saying the operation is still in process (and probably refreshes occasionally to call the continuation), and "pdf-display-pipeline" is a pipeline that simply reads from the byte array you pass it from the flow, e.g. The other big missing piece is finding or creating an OutputStream implementation ("MySpecialOutputStream" in the above code) that knows when it's been closed, so you can test for when the PDF has been completely generated. You can create a Java class that extends ByteArrayOutputStream or FileOutputStream, for instance. Or you can probably do this directly in Javascript as well, see http://www.mozilla.org/rhino/scriptjava.html for how to extend java classes in JS. This is all off the top of my head of course. Hope it at least gives you a starting point. --Jason - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question about serializers
Jason Johnston wrote: Seems to me you could accomplish this fairly easily with Flowscript. Something like: I have never used flowscript but I have to say is very cool, but unfortunately is not doing what I expect. The script looks like this: function main() { var count = 0; var path=cocoon.parameters["report"]; var param=getRequestParameters(); var bytes=0; var outputStream = new com.spectron.cocoon.SpectronOutputStream(); // cocoon.processPipelineTo(path+'.pdf_pipe?'+param,'',outputStream); for( bytes=outputStream.size(); !outputStream.isClosed(); count++,bytes=outputStream.size() ) { cocoon.sendPageAndWait("progress.jx", {"stream_size" : bytes,"count":count } ); } // PDF is finished, now display it: cocoon.sendPage( "pdf-display/"+path+'?'+getRequestParameters(), {byteArray : new java.io.ByteArrayInputStream(outputStream.toByteArray())} ); } It seems that when I do the "cocoon.sendPageAndWait" the "cocoon.processPipeline" is aborted because the outputStream.size() remains constant. If I remove the for loop it creates the PDF correctly. Is there a way to create a thread in flowscript and have the "cocoon.processPipeline" run in it? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question about serializers
On Dec 15, 2005, at 7:45 AM, Fawzib Rojas wrote: Is there a way to create a thread in flowscript and have the "cocoon.processPipeline" run in it? Yes, definitely... var t = new java.lang.Thread ( new java.lang.Runnable ( { run: function() { // // Whatever! Note, this function is a closure... // } } ) ); t.start(); Then you can do something like var progressPageBookmark = cocoon.createWebContinuation().id; while (t.isAlive()) { cocoon.sendPageAndWait ( progressPageResource, { bookmark: progressPageBookmark } ); } ...where you have in the JXTemplate for the progress page: Does that do the trick? —ml— - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question about serializers
Mark Lundquist wrote: On Dec 15, 2005, at 7:45 AM, Fawzib Rojas wrote: Is there a way to create a thread in flowscript and have the "cocoon.processPipeline" run in it? Yes, definitely... Well I tried it but it isnt working, If I set use_thread=false it works, if I set use_thread=true. I know the pdf_runnable object is working because pdf_runnable.process() works, but when I call it from the thread it fails. I get some errors in the console and logs, they are after the script. Can anyone give a hand with this, I'm very close... function main() { var use_thread=true; // get path var path=cocoon.parameters["report"]+".pdf_pipe?"+getRequestParameters(); // create runnable var pdf_runnable=new java.lang.Runnable( { "complete": false, "count": 0, "url":path, "error":"no error", "cocoon": cocoon, "out_stream":new java.io.ByteArrayOutputStream(), "run": function(){ this.process(); this.complete=true; }, "process": function(){ this.cocoon.processPipelineTo(this.url,'',this.out_stream); } } ); // if(use_thread){ var pdf_thread=new java.lang.Thread(pdf_runnable); pdf_thread.start(); // wait until thread is done pdf_runnable.count=0; while(pdf_runnable.complete==false) { cocoon.sendPageAndWait("progress.jx", { "stream_size" : pdf_runnable.out_stream.size(),"count":pdf_runnable.count } ); pdf_runnable.count++; } }else{ pdf_runnable.process(); } // cocoon.sendPage( "pdf-display/"+path, {byteArray : new java.io.ByteArrayInputStream(pdf_runnable.out_stream.toByteArray())} ); } Console error: java.lang.NullPointerException at org.apache.cocoon.environment.AbstractEnvironment.release(AbstractEnvironment.java:539) at org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade.release(MutableEnvironmentFacade.java:320) at org.apache.cocoon.transformation.TraxTransformer.recycle(TraxTransformer.java:514) at org.apache.avalon.excalibur.pool.ResourceLimitingPool.put(ResourceLimitingPool.java:438) at org.apache.avalon.excalibur.component.PoolableComponentHandler.doPut(PoolableComponentHandler.java:212) at org.apache.avalon.excalibur.component.ComponentHandler.put(ComponentHandler.java:425) at org.apache.avalon.excalibur.component.ExcaliburComponentSelector.release(ExcaliburComponentSelector.java:305) at org.apache.cocoon.components.ExtendedComponentSelector.release(ExtendedComponentSelector.java:284) at org.apache.cocoon.components.ExtendedComponentSelector.release(ExtendedComponentSelector.java:281) at org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.recycle(AbstractProcessingPipeline.java:650) at org.apache.cocoon.components.pipeline.impl.BaseCachingProcessingPipeline.recycle(BaseCachingProcessingPipeline.java:77) at org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.recycle(AbstractCachingProcessingPipeline.java:948) at org.apache.avalon.excalibur.pool.ResourceLimitingPool.put(ResourceLimitingPool.java:438) at org.apache.avalon.excalibur.component.PoolableComponentHandler.doPut(PoolableComponentHandler.java:212) at org.apache.avalon.excalibur.component.ComponentHandler.put(ComponentHandler.java:425) at org.apache.avalon.excalibur.component.ExcaliburComponentSelector.release(ExcaliburComponentSelector.java:305) at org.apache.cocoon.components.ExtendedComponentSelector.release(ExtendedComponentSelector.java:284) at org.apache.cocoon.components.EnvironmentDescription.release(CocoonComponentManager.java:599) at org.apache.cocoon.components.CocoonComponentManager.endProcessing(CocoonComponentManager.java:204) at org.apache.cocoon.Cocoon.process(Cocoon.java:683) at org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java:1098) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:354) at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567) at org.mortbay.http.HttpContext.handle(HttpContext.java:1808) at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:525) at org.mortbay.http.HttpContext.handle(HttpContext.java:1758) at org.mortbay.http.HttpServer.service(HttpServer.java:879) at org.mortbay.http.HttpConnection.service(HttpConnection.java:790) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:952) at org.mortbay.http.HttpConnection.handle(HttpConnection.java:807) at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:197) at org.mortbay.util.ThreadedServer
Re: Question about serializers
Is there a way to create a thread in flowscript and have the "cocoon.processPipeline" run in it? Yes, definitely... var t = new java.lang.Thread ( Oh, my!! Maybe as long as you don't need to scale... cheers -- Torsten PGP.sig Description: This is a digitally signed message part
Re: Question about serializers
Can anyone help me to make this work? Fawzib Rojas wrote: Mark Lundquist wrote: On Dec 15, 2005, at 7:45 AM, Fawzib Rojas wrote: Is there a way to create a thread in flowscript and have the "cocoon.processPipeline" run in it? Yes, definitely... Well I tried it but it isnt working, If I set use_thread=false it works, if I set use_thread=true. I know the pdf_runnable object is working because pdf_runnable.process() works, but when I call it from the thread it fails. I get some errors in the console and logs, they are after the script. Can anyone give a hand with this, I'm very close... function main() { var use_thread=true; // get path var path=cocoon.parameters["report"]+".pdf_pipe?"+getRequestParameters(); // create runnable var pdf_runnable=new java.lang.Runnable( {"complete": false, "count": 0, "url":path, "error":"no error", "cocoon": cocoon, "out_stream":new java.io.ByteArrayOutputStream(), "run": function(){ this.process(); this.complete=true; }, "process": function(){ this.cocoon.processPipelineTo(this.url,'',this.out_stream); } } ); // if(use_thread){ var pdf_thread=new java.lang.Thread(pdf_runnable); pdf_thread.start(); // wait until thread is done pdf_runnable.count=0; while(pdf_runnable.complete==false) { cocoon.sendPageAndWait("progress.jx", { "stream_size" : pdf_runnable.out_stream.size(),"count":pdf_runnable.count } ); pdf_runnable.count++; } }else{ pdf_runnable.process(); } // cocoon.sendPage( "pdf-display/"+path, {byteArray : new java.io.ByteArrayInputStream(pdf_runnable.out_stream.toByteArray())} ); } Console error: java.lang.NullPointerException at org.apache.cocoon.environment.AbstractEnvironment.release(AbstractEnvironment.java:539) at org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade.release(MutableEnvironmentFacade.java:320) at org.apache.cocoon.transformation.TraxTransformer.recycle(TraxTransformer.java:514) at org.apache.avalon.excalibur.pool.ResourceLimitingPool.put(ResourceLimitingPool.java:438) at org.apache.avalon.excalibur.component.PoolableComponentHandler.doPut(PoolableComponentHandler.java:212) at org.apache.avalon.excalibur.component.ComponentHandler.put(ComponentHandler.java:425) at org.apache.avalon.excalibur.component.ExcaliburComponentSelector.release(ExcaliburComponentSelector.java:305) at org.apache.cocoon.components.ExtendedComponentSelector.release(ExtendedComponentSelector.java:284) at org.apache.cocoon.components.ExtendedComponentSelector.release(ExtendedComponentSelector.java:281) at org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.recycle(AbstractProcessingPipeline.java:650) at org.apache.cocoon.components.pipeline.impl.BaseCachingProcessingPipeline.recycle(BaseCachingProcessingPipeline.java:77) at org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.recycle(AbstractCachingProcessingPipeline.java:948) at org.apache.avalon.excalibur.pool.ResourceLimitingPool.put(ResourceLimitingPool.java:438) at org.apache.avalon.excalibur.component.PoolableComponentHandler.doPut(PoolableComponentHandler.java:212) at org.apache.avalon.excalibur.component.ComponentHandler.put(ComponentHandler.java:425) at org.apache.avalon.excalibur.component.ExcaliburComponentSelector.release(ExcaliburComponentSelector.java:305) at org.apache.cocoon.components.ExtendedComponentSelector.release(ExtendedComponentSelector.java:284) at org.apache.cocoon.components.EnvironmentDescription.release(CocoonComponentManager.java:599) at org.apache.cocoon.components.CocoonComponentManager.endProcessing(CocoonComponentManager.java:204) at org.apache.cocoon.Cocoon.process(Cocoon.java:683) at org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java:1098) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:354) at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567) at org.mortbay.http.HttpContext.handle(HttpContext.java:1808) at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:525) at org.mortbay.http.HttpContext.handle(HttpContext.java:1758) at org.mortbay.http.HttpServer.service(HttpServer.java:879) at org.mortbay.http.HttpConnection.service(HttpConnection.java:790) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:952) at org.mortbay.http.HttpConnection.handle(HttpConnection.java:807) at org.mort