Announcement Announcement Module
No announcement yet.
File copy not working as expected Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • File copy not working as expected

    I'm trying to build a file processing integration using the fileCopy-file example as my inspiration.

    Ive tried the example with Spring Integration 1.0-RELEASE and 1.0.1 in SVN (can't wait!), but the behavior doesn't seem correct and given its simialarity to the example fileCopy application, I don't know where I'm going wrong.

    Here's the code for the application context:
     <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns:beans=""
        <beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
        <poller max-messages-per-poll="1" id="defaultPoller" default="true">
            <interval-trigger interval="1000"/>
           <beans:bean id="newBlogPublishingServiceActivator" class="com.joshlong.lazyblogger.integrations.NewBlogPublishingServiceActivator">
            <beans:property name="blogService" ref="blogService"/>
            <beans:property name="utilities" ref="utils"/>
    	<file:inbound-channel-adapter id="filesIn"    
    	                              directory="file:${user.home}/blogs/inbound" />
    	<service-activator input-channel="filesIn"
                                       ref="newBlogPublishingServiceActivator" method="publishIncomingBlogEntry"/>
    	<file:outbound-channel-adapter id="filesOut"       directory="file:/home/jlong/blogs/published" />
    Here's the code for the Java code (which is blessedly simple (thanks for that!))

    // package ...
    // bunch of imports none of which have anytyhing to do with a spring API (huzzah!)
    public class NewBlogPublishingServiceActivator {
        public File  publishIncomingBlogEntry( File content ) {
            try {
                InputStream inStream = null;
                inStream =new FileInputStream(content) ;
                String inStreamString = IOUtils.toString(inStream) ;
                blogService.publish( null, new Date(), null, inStreamString ) ;  
            } catch (Throwable e) {
            return null;
        private Utilities utilities;
        private IBlogService blogService; 
        public Utilities getUtilities() {
            return utilities;
        public void setUtilities(Utilities utilities) {
            this.utilities = utilities;
        public IBlogService getBlogService() {
            return blogService;
        public void setBlogService(IBlogService blogService) {
            this.blogService = blogService;
    Any ideas would be very appreciated

  • #2
    I should clarify: I can see that Spring Integration is picking up the file in the inbound directory and I can scrutinize the payload (a File object) in the method in the service activator. It doesnt, however, see to do anything beyond that. the service activator class returns the File (the payload) and my understanding was that would be sent on the reply (the outbound-channel in the service activator.).

    Thanks again!


    • #3
      I put it under the debugger. The value for the directory is being set in the Spring confguration on the inbound-file-adapter as follows:
      The directory in the Spring configuration for the outbound-file-adapter is being set as follows:

      The value o the directory attribute on the FileWritingMessagingHandler class is equal to "file:/home/jlong/blogs/published" for the outbound file directory, which is not a valid url! I change the attribute on the outbound to be just ${user.home}/blogs/published, and sure enough, it worked! This I think is because the inbound adapter is using a Spring framework Resource under the hood, which knows how to deal wiht file: prefixes, and the FileWritingMessagingHandler instead uses a plain jane object. So much for symmetry! I just went back and noticed that the sample is doing the right thing, as well, by using file: on the inbound but not on the outbound.

      It might prove useful to change that or at least note in big bold letters that they're not the same, because it's hard to tell from the birds eye view that the XML schema affords us.

      Thanks again


      • #4

        Please file a JIRA issue for this. We should be consistent or at least well-documented as you pointed out. In this case, if possible, perhaps the system should fail-fast with a meaningful error message.

        On a somewhat related note, I think it might be nice to have the "file:" prefix automatically prepended if no other prefix has been provided. The Resource usage here is convenient, but I'm sure most of the time it will be "file:" anyways.

        Thank you for providing so much detail in your posts.



        • #5

          Thanks as usual for the quick response. I added a JIRA item at

          What do you think the resolution for this would be? I can kind of see why the attribute was a afterall, I doubt the FileCopyUtil class supports writing to all the possible URIs addressable by the Spring Resource URL format, so it makes more sense to limit it to a File. On the other hand, it does make sense to support the flexibility in the inbound connector because a file on the classpath is just as good as a file on the filesystem wrt to reads (but definitely wrt to writes).

          Your point about the default being file: is also very valid. Changing either attribute would alter a now public interface (though, i rather suspect most people are using the xml schema, so they needn't see the underlying change.)

          Assuming you're willing to break the class public interface, perhaps you could expose both as Resource and just test for the value being one of a few types supportable (ie, classpath:, file:, or regular old file without prefix for inbound, file:, regular file for outbound)? Semantically, a inbound file adapter shouldn't be reading http: urls anyway :-)

          Anyway, thanks again


          • #6
            File FTP Upload on Remote Machine


            I have a requirment like reding the message xml file message from MQ Q and construct the text file xml message and upload the text file on remote machine. preferabally by FTP connection. Can I use the file outbound adapter and are there any sampls for this in spring