Results 1 to 3 of 3

Thread: to simple: delete a file using just one Spring Integration element [Help]

  1. #1
    Join Date
    Dec 2011
    Posts
    26

    Default to simple: delete a file using just one Spring Integration element [Help]

    Hi everybody;

    Actually i'm using an int:service-activator which calls a java method in order to delete a txt file. This solution is not elegant and I would like do the deletion without use any java class, something like:
    Code:
    <file:something id="delFile" channel="toDel" directory="path"  delete-source-files: "true"/>
    is it possible to do something like that?

    Thanks!

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,017

    Default

    If the payload is a java.io.File...

    Code:
    <int:service-activator input-channel="toDel" expression="payload.delete()" output-channel="nullChannel" />
    If you want to test success/failure to delete, route the output to a channel - the payload will be a Boolean (result of java.io.File.delete()).
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Dec 2011
    Posts
    26

    Default

    Thanks for the answer, but in the payload is not the file, the only thing related with the file is stored in the header and is a peace of the name of the file. To create the file i did the following:

    Code:
    <file:outbound-channel-adapter id="fileout" channel="toStart" directory="${temporal.path}"  filename-generator-expression="headers[messageId].substring(3)+'.txt'"/>
    The idea would be something like that:
    Code:
    <int:service-activator id="deleteFile" input-channel="todeleteFile" output-channel="outscreen"
    		expression="getResource(${temporal.path}+headers[messageId].substring(3)+'.txt').delete()"/>
    Thank!
    Last edited by uzor; Feb 16th, 2012 at 10:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •