You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Davis, Daniel" <Da...@si.edu> on 2015/04/03 01:57:51 UTC

Deleting a file outside a consumer

I have an odd case and Google is not helpful because its an odd case
(file producer is always matched).  I need to convert PDFs to SWF on
linux in a route.  The most common tool is called pdf2swf but it has a
problem characteristic, it can only read from a file and not a pipe
because it reads the file twice.  The operations in in the middle of a
bunch of routes kicked off from a JMS message.  It works fine in the
route shown below.  The issue is that I am left with at least one file. 
The camel file consumer does a great job of cleaning up after itself if
one wants.  Who would expect the file consumer to delete the file it had
just written?  I have not found a component that just does OS level file
manipulation without reading or writing (that doesn't mean there isn't
one just that I have not found it).  I could write a component (but the
point of Camel is to not reinvent the wheel unnecessarily) or just call
Java file operations.  I can do command line operations though they
would be platform specific.  I really don't like going around Camel if
there is a way to do something with Camel.  And in the route I already
know the name of the file(s) and I am done with them by the end of the
route.

Does anyone have a suggestion for doing this from XML DSL or Java DSL
without going around Camel?

<route id="DerivativesProcessPDF2SWF">
     <from uri="direct:processDerivativesPDF2SWF"/>
     <log message="${id} Derivatives: Started PDF2SWF processing ..."
loggingLevel="DEBUG" logName="edu.si.derivatives"/>
     <!-- Create a Flash derivative using pdf2swf for the Flexpaper
viewer. -->
     <!-- Unfortunately pdf2swf cannot accept a pipe as an input stream
source, hence we use a temporary file. -->
     <to uri="file://staging/"/> <!-- This will create a temporary file
that must be cleaned out. -->
     <recipientList>
         <simple>
             exec:pdf2swf?args=${header.CamelFileNameProduced} -o
${header.CamelFileNameProduced}.swf
         </simple>
     </recipientList>
     <choice>
         <when>
             <simple>
                 ${headers.CamelExecExitValue} == 0
             </simple>
             <to
uri="fedora:addDatastream?name=OBJ.swf&amp;type=application/x-shockwave-flash&amp;group=M&amp;dsLabel=Flexpaper&amp;versionable=false"/>
         </when>
         <otherwise>
             <log message="${id} Derivatives: Unable to convert PDF to
SWF. PID: ${headers.CamelFedoraPid} ${headers.CamelExecExitValue}"
loggingLevel="ERROR"/>
         </otherwise>
     </choice>
     <log message="${id} Derivatives: Finished PDF2SWF processing."
loggingLevel="DEBUG" logName="edu.si.derivatives"/>
</route>

--
Daniel Davis
Technical Manager - Office of Research Information Systems
Smithsonian Institution


Re: Deleting a file outside a consumer

Posted by "Davis, Daniel" <Da...@si.edu>.
Thanks.  Its just as important to know what is not there to keep from
spinning one's wheels.  It seems reasonable to add functionality to the
file producer to perform platform independent delete operations on file
systems separately from writes though I don't know if this is exactly
what you were writing about.  Perhaps more kinds of "write metadata"
operations including permissions on existing files and directories.  But
you "literally" wrote the book :-) and have thought through the
nuances.  As you say there are several workable approaches for now.

When one has a "swiss army knife" like Camel its nice to look at it
first but it cannot do everything --- yet.

--
Dan Davis

On 04/03/2015 12:23 PM, Claus Ibsen wrote:
> Hi
>
> Ah we dont have that.
>
> But we could add support for the file producer to support delete=true
> so it will delete the file it wrote at the end of the UoW. But then
> again it would only be for special use-cases where you need to write
> temp files.
>
> You can always write a bit of java code that deletes the file, and/or
> attach the code to the UoW so Camel does it at the end. Or use
> onCompletion etc.
>
>
>
>
>
> On Fri, Apr 3, 2015 at 1:57 AM, Davis, Daniel <Da...@si.edu> wrote:
>> I have an odd case and Google is not helpful because its an odd case
>> (file producer is always matched).  I need to convert PDFs to SWF on
>> linux in a route.  The most common tool is called pdf2swf but it has a
>> problem characteristic, it can only read from a file and not a pipe
>> because it reads the file twice.  The operations in in the middle of a
>> bunch of routes kicked off from a JMS message.  It works fine in the
>> route shown below.  The issue is that I am left with at least one file.
>> The camel file consumer does a great job of cleaning up after itself if
>> one wants.  Who would expect the file consumer to delete the file it had
>> just written?  I have not found a component that just does OS level file
>> manipulation without reading or writing (that doesn't mean there isn't
>> one just that I have not found it).  I could write a component (but the
>> point of Camel is to not reinvent the wheel unnecessarily) or just call
>> Java file operations.  I can do command line operations though they
>> would be platform specific.  I really don't like going around Camel if
>> there is a way to do something with Camel.  And in the route I already
>> know the name of the file(s) and I am done with them by the end of the
>> route.
>>
>> Does anyone have a suggestion for doing this from XML DSL or Java DSL
>> without going around Camel?
>>
>> <route id="DerivativesProcessPDF2SWF">
>>      <from uri="direct:processDerivativesPDF2SWF"/>
>>      <log message="${id} Derivatives: Started PDF2SWF processing ..."
>> loggingLevel="DEBUG" logName="edu.si.derivatives"/>
>>      <!-- Create a Flash derivative using pdf2swf for the Flexpaper
>> viewer. -->
>>      <!-- Unfortunately pdf2swf cannot accept a pipe as an input stream
>> source, hence we use a temporary file. -->
>>      <to uri="file://staging/"/> <!-- This will create a temporary file
>> that must be cleaned out. -->
>>      <recipientList>
>>          <simple>
>>              exec:pdf2swf?args=${header.CamelFileNameProduced} -o
>> ${header.CamelFileNameProduced}.swf
>>          </simple>
>>      </recipientList>
>>      <choice>
>>          <when>
>>              <simple>
>>                  ${headers.CamelExecExitValue} == 0
>>              </simple>
>>              <to
>> uri="fedora:addDatastream?name=OBJ.swf&amp;type=application/x-shockwave-flash&amp;group=M&amp;dsLabel=Flexpaper&amp;versionable=false"/>
>>          </when>
>>          <otherwise>
>>              <log message="${id} Derivatives: Unable to convert PDF to
>> SWF. PID: ${headers.CamelFedoraPid} ${headers.CamelExecExitValue}"
>> loggingLevel="ERROR"/>
>>          </otherwise>
>>      </choice>
>>      <log message="${id} Derivatives: Finished PDF2SWF processing."
>> loggingLevel="DEBUG" logName="edu.si.derivatives"/>
>> </route>
>>
>> --
>> Daniel Davis
>> Technical Manager - Office of Research Information Systems
>> Smithsonian Institution
>>
>
>


Re: Deleting a file outside a consumer

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Ah we dont have that.

But we could add support for the file producer to support delete=true
so it will delete the file it wrote at the end of the UoW. But then
again it would only be for special use-cases where you need to write
temp files.

You can always write a bit of java code that deletes the file, and/or
attach the code to the UoW so Camel does it at the end. Or use
onCompletion etc.





On Fri, Apr 3, 2015 at 1:57 AM, Davis, Daniel <Da...@si.edu> wrote:
> I have an odd case and Google is not helpful because its an odd case
> (file producer is always matched).  I need to convert PDFs to SWF on
> linux in a route.  The most common tool is called pdf2swf but it has a
> problem characteristic, it can only read from a file and not a pipe
> because it reads the file twice.  The operations in in the middle of a
> bunch of routes kicked off from a JMS message.  It works fine in the
> route shown below.  The issue is that I am left with at least one file.
> The camel file consumer does a great job of cleaning up after itself if
> one wants.  Who would expect the file consumer to delete the file it had
> just written?  I have not found a component that just does OS level file
> manipulation without reading or writing (that doesn't mean there isn't
> one just that I have not found it).  I could write a component (but the
> point of Camel is to not reinvent the wheel unnecessarily) or just call
> Java file operations.  I can do command line operations though they
> would be platform specific.  I really don't like going around Camel if
> there is a way to do something with Camel.  And in the route I already
> know the name of the file(s) and I am done with them by the end of the
> route.
>
> Does anyone have a suggestion for doing this from XML DSL or Java DSL
> without going around Camel?
>
> <route id="DerivativesProcessPDF2SWF">
>      <from uri="direct:processDerivativesPDF2SWF"/>
>      <log message="${id} Derivatives: Started PDF2SWF processing ..."
> loggingLevel="DEBUG" logName="edu.si.derivatives"/>
>      <!-- Create a Flash derivative using pdf2swf for the Flexpaper
> viewer. -->
>      <!-- Unfortunately pdf2swf cannot accept a pipe as an input stream
> source, hence we use a temporary file. -->
>      <to uri="file://staging/"/> <!-- This will create a temporary file
> that must be cleaned out. -->
>      <recipientList>
>          <simple>
>              exec:pdf2swf?args=${header.CamelFileNameProduced} -o
> ${header.CamelFileNameProduced}.swf
>          </simple>
>      </recipientList>
>      <choice>
>          <when>
>              <simple>
>                  ${headers.CamelExecExitValue} == 0
>              </simple>
>              <to
> uri="fedora:addDatastream?name=OBJ.swf&amp;type=application/x-shockwave-flash&amp;group=M&amp;dsLabel=Flexpaper&amp;versionable=false"/>
>          </when>
>          <otherwise>
>              <log message="${id} Derivatives: Unable to convert PDF to
> SWF. PID: ${headers.CamelFedoraPid} ${headers.CamelExecExitValue}"
> loggingLevel="ERROR"/>
>          </otherwise>
>      </choice>
>      <log message="${id} Derivatives: Finished PDF2SWF processing."
> loggingLevel="DEBUG" logName="edu.si.derivatives"/>
> </route>
>
> --
> Daniel Davis
> Technical Manager - Office of Research Information Systems
> Smithsonian Institution
>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/